简体   繁体   English

Git-如何将代码从中央Git存储库部署到生产服务器?

[英]Git - How to deploy code from my central Git repo to my production server?

I'm new to Git. 我是Git的新手。 I need to setup Git to deploy a Django website to the production server. 我需要设置Git来将Django网站部署到生产服务器。 My question here is to know what is the best way of doing this. 我在这里的问题是知道什么是最好的方法。

By now I only have a Master branch. 到目前为止,我只有一个Master分支。 My problem here is that Development environment is not equal to the Production environment. 我的问题是开发环境不等于生产环境。 How can I have the two environments(Development and Production) in Git? 如何在Git中拥有两个环境(开发和生产)? Should I use two new Branches(Development and Production). 我应该使用两个新的分支(开发和生产)。 Please give me a clue on this. 请给我一个线索。

Other question... when I finish to upload/push the code to the Production server I need to restart the Gunicorn(serves Django website). 其他问题...当我完成将代码上载/推送到生产服务器时,我需要重新启动Gunicorn(服务于Django网站)。 How can I do this? 我怎样才能做到这一点?

And the most important question... Should I use Git to do this or I have better options? 还有最重要的问题...我应该使用Git还是要有更好的选择?

Best Regards, 最好的祝福,

The first question you must solve is your project structure. 您必须解决的第一个问题是您的项目结构。 Usually the difference between development and the production environment is setting.py and url.py. 通常,开发环境和生产环境之间的区别是setting.py和url.py。 So why you firstly separate those? 那么,为什么首先要分离它们呢? :) For example you can have one main settings.py where you define all the default settings which are in common. :)例如,您可以有一个主要的settings.py,您可以在其中定义所有通用的默认设置。 Then at the end of the file you just import the settings_dev.py and settting_prod.py for exemple: 然后在文件末尾,只需导入settings_dev.py和settting_prod.py例如:

try:
    from settings_prod import *
except ImportError:
    pass

try:
    from settings_dev import *
except ImportError:
    pass

Then simply you can overload all the setting you want and have custom settings of the project (for example installed apps). 然后,您可以简单地使所需的所有设置超载,并具有项目的自定义设置(例如,已安装的应用程序)。 The same logic you can use for urls.py file. 您可以对urls.py文件使用相同的逻辑。

Then you can simply ignore adding the *_dev files to repo and on the server side you can just checkout the code from repo and restart http server. 然后,您可以简单地忽略将* _dev文件添加到回购中,而在服务器端,您只需从回购中签出代码并重新启动http服务器即可。 To automatize this for now I can't give the right name of app to use. 现在暂时无法自动执行此操作,我无法提供要使用的正确名称。 Sometimes simple python script could be solution like: watching if the file datetime changed and if yes, just run restart command for http. 有时,简单的python脚本可能是解决方案,例如:监视文件datetime是否更改,如果是,则对http运行重新启动命令。

Hope that helped. 希望能有所帮助。

Ignas 伊格纳斯

You can follow this brunching model - http://nvie.com/posts/a-successful-git-branching-model/ 您可以按照brunching模型- http://nvie.com/posts/a-successful-git-branching-model/

And, git is ok but use Fabric for deployment. 而且,git还可以,但可以使用Fabric进行部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM