CentOS7下的Django2集成部署四:Jenkins的freestyle-job
Posted zhujingxiu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7下的Django2集成部署四:Jenkins的freestyle-job相关的知识,希望对你有一定的参考价值。
- 前提:Jenkins所在的客户机的ssh-key加入到GitLab中
- 目标:自动化部署GitLab上的新建的项目ok-admin
- 1.编写git项目的nginx配置文件
[[email protected] ~]# vim /etc/nginx/conf.d/my_ok.conf
server { listen 80; server_name www.my-ok.cc; location / { root /usr/share/nginx/html/ok-admin; index index.html index.htm; } }
- 2.编写发布脚本
[[email protected] ~]# mkdir /data/scripts [[email protected]-ct75211 ~]# cd /data/scripts/ [[email protected]-ct75211 ~]# vim /data/scripts/deploy.sh
1 #! /bin/bash 2 job_name=$1 3 app_name=app-$(date +%F)-$(($RANDOM+10000)) 4 echo $app_name 5 cd /var/lib/jenkins/workspace/${job_name} && tar czf /opt/${app_name}.tar.gz ./* 6 cd /var/webroot && mkdir ${app_name} 7 cp /opt/${app_name}.tar.gz /var/webroot/${app_name} 8 cd /var/webroot/${app_name} && tar xf ${app_name}.tar.gz && rm -f ${app_name}.tar.gz 9 cd /usr/share/nginx/html && rm -rf ok-admin && ln -s /var/webroot/${app_name} /usr/share/nginx/html/ok-admin
[[email protected] scripts]# mkdir /var/webroot
本地测试下
[[email protected] scripts]# ./deploy.sh my-freestyle-job app-2018-12-15-20566 [[email protected]-ct75211 scripts]# ll /usr/share/nginx/html/ total 8 -rw-r--r--. 1 root root 537 Dec 4 10:03 50x.html -rw-r--r--. 1 root root 612 Dec 4 10:03 index.html drwxr-xr-x. 3 root root 58 Dec 14 21:37 my_django lrwxrwxrwx 1 root root 33 Dec 15 09:56 ok-admin -> /var/webroot/app-2018-12-15-20566
- 3.编辑之前的my-freestyle-job,把gitlab的git地址配置到这个任务的源码管理里
- 构建触发器
- 需要将 GitLab CI Service URL 和 Secret Token 配置到GitLab的该git项目的settings-->intergrations中,并test下push event
- 4.本地看下浏览器
- 再次在本地项目中编辑后再看下测试结果
[email protected] MINGW64 /e/python/ok-admin (master) $ git fetch $ vim index.html [email protected]-BC8FMN2 MINGW64 /e/python/ok-admin (master) $ git add . $ git commit -m "modified index.html " [master 03743e9] modified index.html 1 file changed, 2 insertions(+), 2 deletions(-) [email protected]-BC8FMN2 MINGW64 /e/python/ok-admin (master) $ git push -u origin master Counting objects: 3, done. Delta compression using up to 6 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 321 bytes | 321.00 KiB/s, done. Total 3 (delta 2), reused 0 (delta 0) To 192.168.23.211:py3web/ok-admin.git b731093..03743e9 master -> master Branch ‘master‘ set up to track remote branch ‘master‘ from ‘origin‘.
-
- ok,已经看到了自动部署的结果
以上是关于CentOS7下的Django2集成部署四:Jenkins的freestyle-job的主要内容,如果未能解决你的问题,请参考以下文章
部署CentOS7+Python3+Django2+UWSGI2+Nginx生产环境(实测)