Django项目构建发布

EdShao 2020-04-29

前言:

之前的Django项目直接部署到Docker容器中,简单高效;

不过生产中还是要部署到K8S中,在此总结一下工作经历

一、Harbor仓库

创建harbor仓库项目

传送门:Harbor单点仓库部署

二、编写Dockefile

Dockerfile文件

FROM python:3.6
WORKDIR /root
COPY . /root/
RUN pip install --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple -r /root/requirements.txt
CMD uwsgi --ini /root/cops_uwsgi.ini

requirements.txt文件

requests
django
djangorestframework
uwsgi
mysqlclient
ldap3
redis
boto

uwsgi配置

为什么要用uwsgi请自行百度

[uwsgi]
http=0.0.0.0:9001
chdir=/root
module = Project.wsgi
vacuum=True
master=True
workers=8
enable-threads=True
threads=32
memory-report=True

构建脚本build.sh

#!/bin/sh
REV=`git rev-parse --short HEAD`
docker build -t cloudops_test:$REV .

docker tag cloudops_test:${REV} 10.60.128.219:888/cloudops/cloudops_test:${REV}
docker push 10.60.128.219:888/cloudops/cloudops_test:${REV}

三、发布代码到仓库

3.1 拉取git仓库代码

[ harbor]# cd /data/web/xxx/
[ xxx]# git pull   #### 各位看官,请跟实际环境操作

3.2 Harbor项目推送示例

Django项目构建发布

3.2 构建Django代码

[ opsservice]# cat build.sh 
#!/bin/sh
REV=`git rev-parse --short HEAD`
docker build -t cloudops_test:$REV .


docker tag cloudops_test:${REV} 10.60.128.219:888/cloudops/cloudops_test:${REV}
docker push 10.60.128.219:888/cloudops/cloudops_test:${REV}
[10-60-128-219 opsservice]# /bin/sh build.sh

3.3 检测镜像

[ opsservice]# docker images|grep cloudops_test
cloudops_test                              ffbaa25             8cd31496a16a        18 hours ago        987MB
10.60.128.219:888/cloudops/cloudops_test   78b8ccc             ad7ef3db0a88        47 hours ago        987MB
cloudops_test                              78b8ccc             ad7ef3db0a88        47 hours ago        987MB
[10-60-128-219 opsservice]#

四、K8S拉取镜像创建pod

传送门:K8S拉取Django项目创建pod

相关推荐

inspuryhq / 0评论 2020-07-28