Git - How do I deploy code from my central Git repository to my production server?

I am new to Git. I need to configure Git to deploy a Django site on a production server. My question here is to know how best to do this.

Currently, I only have a master branch. My problem is that the development environment is not equal to the production environment. How can I use two environments (development and production) in Git? Should I use two new branches (Development and production). Please let me know this.

Another question ... when I finish uploading / popping the code to the Production server, I need to restart Gunicorn (it serves the Django website). How can i do this?

And the most important question ... Should I use Git for this or do I have better options?

Best wishes,

+4
source share
2 answers

The first issue that you must resolve is your project structure. Usually the difference between development and production environment is setting.py and url.py. So why do you separate them first? :) For example, you can have one main settings.py parameter, where you set all the standard settings that are common. Then at the end of the file, you simply import settings_dev.py and installting_prod.py for an example:

try: from settings_prod import * except ImportError: pass try: from settings_dev import * except ImportError: pass 

Then simply you can overload all the necessary settings and user settings of the project (for example, installed applications). The same logic you can use for urls.py file.

Then you can simply ignore adding * _dev files to the repo and on the server side you can just check the code from the repo and restart the HTTP server. To automate this now, I cannot name the application name I need. Sometimes a simple python script may be a solution, for example: viewing if the datetime file has changed, and if so, just run the reload command for http.

Hope this helps.

Ignas

+2
source

You can follow this model - http://nvie.com/posts/a-successful-git-branching-model/

And, git is fine, but use Fabric to deploy.

0
source

Source: https://habr.com/ru/post/1384280/


All Articles