EdShao 2020-04-29
之前的Django项目直接部署到Docker容器中,简单高效; 不过生产中还是要部署到K8S中,在此总结一下工作经历
传送门:Harbor单点仓库部署
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}
[ harbor]# cd /data/web/xxx/ [ xxx]# git pull #### 各位看官,请跟实际环境操作
[ 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
[ 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]#