Deploy your project with a git push on your server
Feb 11, 2015 • 2 minutes to read • Last Updated: Apr 9, 2017As much as you like using github for your public repositories you need a way to host your codebase where you deploy your project sometimes.
You can bookmark this for future reference to get it running quickly. I usually work with ubuntu on AWS EC2 for setting up my projects. To be able to perform these you can use an Linux operating system servers and do it quite easily. So for the purpost of this example I am going to assume you are using EC2 systems too.
Step 1: Login to your EC2 machine through ssh. For ubuntu users login using ssh
Step 2: Once you are in. then you create a git bare repository. You create a directory first and then make it a bare repository. For the purpose of this blog I will call my project unicorn and the bare git repository as unicorn.git.
Step 3 : Create a place you want to export your project files to. Since the default path when I login in EC2 is /home/ubuntu/
, I will create a project directory right there and call it unicorn.
Step 4 : Once I am done I need to setup the git hook for whenever my project is updated. Which is called post-update.sample
which should be in your unicorn.git folder. We need to first rename the file to post-update
.
Step 5 : Clear everything in there and add this to the file. What it does, is export the git files to the directory /home/ubuntu/unicorn/
. But if you have setup a different path for where you want to export your files then, do so.
Step 6 : Next logout from the server and goto your local git repository for project unicorn and add a remote.
Step 7 : That’s it ! Now push master branch to the remote production and checkout the /home/ubuntu/unicorn
directory for the files.
Also if you would like to checkout how to write pre-commit
files for __pylint__ing your code then checkout this blog post.
I am writing a book!
While I do appreciate you reading my blog posts, I would like to draw your attention to another project of mine. I have slowly begun to write a book on how to build web scrapers with python. I go over topics on how to start with scrapy and end with building large scale automated scraping systems.
If you are looking to build web scrapers at scale or just receiving more anecdotes on python then please signup to the email list below.