[英]How to deploy Django app on Ubuntu when using Gitlab
I have create a simple Django application, then I have commit and push to Gitlab. 我创建了一个简单的Django应用程序,然后我提交并推送到Gitlab。 Finally I would like to install that application on my "production server" which is running ubuntu so from that server terminal I run the command:
最后我想在运行ubuntu的“生产服务器”上安装该应用程序,以便从该服务器终端运行命令:
git clone https://domain.com/path/to/git
I cannot find my python code among the file cloned. 我无法在克隆的文件中找到我的python代码。
What is the correct way to get the python code from the gitlab repository? 从gitlab存储库获取python代码的正确方法是什么?
First of all, 首先,
does your git has all source code including the pip installed apps? 您的git是否包含所有源代码,包括pip安装的应用程序?
Well i don't know about gitlab, and there's basically everything missing about your configuration on the server, but you can set up a git hook on a git repo. 好吧,我不知道gitlab,在服务器上基本上没有关于你的配置的一切,但是你可以在git repo上设置一个git hook。
here is and example of a post-receive hook to deploy an example django project. 这是一个用于部署示例django项目的post-receive钩子的示例。
#!/bin/bash
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "master branch received, deploying..."
GIT_WORK_TREE="/PATH/TO/DJANGO/PROJECT" git checkout -f master > /dev/null
source /PATH/TO/DJANGO/VIRTUAL/ENVIRONMENT/bin/activate > /dev/null
echo "installing new pip dependencies..."
pip install -r /PATH/TO/DJANGO/PROJECT/dependencies.txt > /dev/null
echo "applaying new db migrations..."
python /PATH/TO/DJANGO/PROJECT/manage.py migrate_schemas > /dev/null
deactivate > /dev/null
touch /PATH/TO/DJANGO/PROJECT/PROJECT_NAME/wsgi.py > /dev/null
echo "Sever code reloaded."
else
echo "Received branch $ref, not deploying."
fi
done
so a few thing to consider: 所以要考虑一些事情:
chmod +x FILE_NAME
chmod +x FILE_NAME
pip freeze > dependencies.txt
(note, everything on the file will be insatled on the server) pip freeze > dependencies.txt
生成它(请注意,文件上的所有内容都将嵌入到服务器上) touch wsgi.py
would reload the code if your running apache with mod_wsgi on daemon mode ( more info ) touch wsgi.py
将重新加载代码,如果您在守护进程模式下运行带有mod_wsgi的apache( 更多信息 ) 问题是分支,我解决了选择一个特定的分支,应用选项“-b”后跟正确的分支名称“develop”:
git clone -b develop https://example.com/username/projectname.git
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.