We are working on a django project which is hosted on an amazon ec2 instance. It is on very early stage, so changes are made constantly and the webapp should be updated more than once a day. Right now, the development cycle looks like:
- The code is modified/added/deleted.
- It is pushed to a bitbucket repository.
- I login to ec2 server with
ssh
. - Pull the new code from the repo and merge.
- Restart the server.
Although, it does the job, I don’t feel like it is the best way to working with remote servers.
What are the well known techniques of development on remote servers?
I think what you need is a Continuous Integration (CI) server. You can host your own, for example Jenkins which has BitBucket integration or use a hosted service like CodeShip which has a free plan.
You could try and set up your own set of scripts to do a similar job but the industry has already provided a solution in this area.
You didn’t mention tests in your question but You can also get these CI tools to run your tests for you as well, so bad builds don’t go into production.
There is quite a lot of possible solutions to your problem. You can easily write scripts to automate the steps of the process or use an existing ready-to-use continuous integration solution. I will shortly describe the first solution, where you write scripts to do this yourself.
On the server where your webapp mywebapp is deployed, write a small script shell mywebapp_deployment_tool
which deploys the latest version of the application. I suggest that you keep a dedicated branch live
or release
corresponding to the latest deployed version, and which is distinct from the development branch. The job of the script would then be:
- Checkout the latest
live
branch. - Restart the server (maybe
kill -HUP
would do).
Now create a git owned by your deployment infrastructure¹ repository on your server and configure a git hook that will trigger your mywebapp_deployment_tool
each time a commit is pushed to the live
branch.
On your development repository, set up a git hook that will automatically push merges to the live
branch to the repository on the server. This will, in turn, trigger the deployment script.
Also note that VirtualBox or FreeBSD jails can be used to set up an environment where you can test your webapp before merging changes to live
.
¹ This just means that this repository should not be used for development.