Best Practice for updating application in production environment
I have successfully launched an angular-fullstack application and especially at the beginning there are quite frequent small updates I want to make to the system. What is the best practice to do it?
Right now, this is what I do:
- SSH into ubuntu server
- Go to application's root directory
-
git pull - stop the server
-
grunt build - start the server in production mode
So during between step 4 and step 6, the server is down. This might not be the best way to do it.
Also, how do you handle 503 here? For SEO it is beneficial if you tell Google that the server is not available only temporarily.
Thanks for your help!
Edit: I know you can automate the steps with a continuous deployment server. But again - the downtime is there.
If you're looking for a zero-downtime solution, you're probably going to have some work ahead. I run most of my web apps in Docker containers with at least two replicas, so that I can do a rolling update. I have a load balancer in front of both, and when one goes down, traffic goes to the other. Then the first comes back up with the new version, and can receive traffic again. Then the same goes for the other replica. I personally do all this with Kubernetes, but I'm sure that's out of the scope for what you're looking for. IIRC Heroku might offer a service to do something like this for you.
Thank you, I think that is a very good solution, but seems a bit overkill for my case at this stage. I plan to do this in the long run though.
Any other ideas? Maybe some quick-wins?
How far do you want to go? My first suggestion would be to start using a continuous integration system. My favorite is CircleCI. You just need it to run your tests, run a build, and then package it and send it somewhere.
You can create a production repo @molerat619 so you can gulp/grunt build on your local and push it to your production repo.
Then on your server only git pull && npm install and restart the server. This could avoid the downtime on your server while doing gulp/grunt build
@Awk34 Continouus Integration is also pretty cool. Definitely going to do that too. I used shippable and Jenkins so far - in my case both were free.
@DanMMX that's actually a good idea. For the small down time - do you know how that 503 could work with angular-fullstack? I also have Apache running on the ubuntu server.
@DanMMX The solution you are referring to would involve version controlling dist folder in the same git repository. Would it be possible to have two different repos one for source and one for dist.
@samsfisher It shouldn't necessarily be the same repository, what I do is
git clone original dev && cd dev
git clone production dist
So the dist folder is another repo and add it to the .gitignore from the parent repo