日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

CentOS7下的Django2集成部署五:Jenkins的流水线部署pipeline-job

發(fā)布時(shí)間:2025/6/17 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CentOS7下的Django2集成部署五:Jenkins的流水线部署pipeline-job 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.Push本地的項(xiàng)目到GitLab

  準(zhǔn)備工作:由于之前在MySQL設(shè)置時(shí)禁止了root用戶的遠(yuǎn)程訪問,此處需要授權(quán)一個(gè)新的用戶

mysql> GRANT ALL PRIVILEGES ON *.* TO 'py3web'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

#新建數(shù)據(jù)庫

? mysql> CREATE DATABASE pyblog DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
? Query OK, 1 row affected (0.01 sec)

  本地項(xiàng)目初始目錄

    

  在GitLab上新建項(xiàng)目

    

  push本地項(xiàng)目到GitLab

admin@DESKTOP-BC8FMN2 MINGW64 /e/python $ cd my-blog/$ git init Initialized empty Git repository in E:/python/my-blog/.git/$ git remote add origin git@192.168.23.211:root/my-blog.git$ git add .$ git commit -m "initial code"admin@DESKTOP-BC8FMN2 MINGW64 /e/python/my-blog (master) $ git push -u origin master Counting objects: 117, done. Delta compression using up to 6 threads. Compressing objects: 100% (113/113), done. Writing objects: 100% (117/117), 1.35 MiB | 7.15 MiB/s, done. Total 117 (delta 14), reused 0 (delta 0) remote: Resolving deltas: 100% (14/14), done. To 192.168.23.211:root/my-blog.git* [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'.

2.創(chuàng)建Jenkins的pipeline-job

  創(chuàng)建步驟

    

  基本設(shè)置

      

   構(gòu)建觸發(fā)器

      

  流水線構(gòu)建

      

  重新保存下設(shè)置。

  同樣的,需要將 Build Triggers里的GitLab CI Service URL?http://192.168.23.211:8080/project/blog-pipeline-job 和?Secret Token?配置到GitLab的該git項(xiàng)目的settings-->intergrations中

      

  此時(shí)需要在項(xiàng)目中添加下Jenkinsfile,以便后面的調(diào)試

      

  提交后,Jenkins這邊就已經(jīng)自動(dòng)觸發(fā)了

      

  執(zhí)行完成后可以看到流水線記錄

      

  基本上pipeline已經(jīng)就緒了

3.初步調(diào)試構(gòu)建

  給my-blog項(xiàng)目配置nginx的conf

[root@home-ct75211 ~]# vim /etc/nginx/conf.d/my_blog.conf 1 server { 2 listen 80; 3 server_name www.my-blog.cc; 4 5 #charset koi8-r; 6 7 #access_log logs/host.access.log main; 8 9 location / { 10 include uwsgi_params; 11 uwsgi_pass 127.0.0.1:21190; 12 uwsgi_param UWSGI_SCRIPT luffy_blog.wsgi; 13 uwsgi_param UWSGI_CHDIR /usr/share/nginx/html/my_blog; 14 index index.html index.htm; 15 client_max_body_size 35m; 16 #uwsgi_cache_valid 1m; 17 #uwsgi_temp_file_write_size 64k; 18 #uwsgi_busy_buffers_size 64k; 19 #uwsgi_buffers 8 64k; 20 #uwsgi_buffer_size 64k; 21 #uwsgi_read_timeout 300; 22 #uwsgi_send_timeout 300; 23 #uwsgi_connect_timeout 300; 24 } 25 26 #error_page 404 /404.html; 27 28 # redirect server error pages to the static page /50x.html 29 # 30 error_page 500 502 503 504 /50x.html; 31 location = /50x.html { 32 root html; 33 } 34 35 36 } /etc/nginx/conf.d/my_blog.conf [root@home-ct75211 ~]# systemctl restart nginx

  要自動(dòng)部署,后面的流水線腳本則需要重新修改下

1 pipeline { 2 agent any 3 stages{ 4 stage("fetch code"){ 5 steps { 6 echo "fetch code" 7 sh "pwd" 8 } 9 } 10 stage("unit test"){ 11 steps { 12 echo "unit test" 13 echo "${BUILD_NUMBER}" 14 } 15 } 16 stage("package"){ 17 steps { 18 echo "package" 19 sh 'tar czf /opt/blog-${BUILD_ID}.tar.gz ./* --exclude=./git --exclude=Jenkinsfile' 20 } 21 22 } 23 stage('deploy'){ 24 steps { 25 sh 'cd /var/webroot && mkdir blog-${BUILD_ID}' 26 sh 'cp /opt/blog-${BUILD_ID}.tar.gz /var/webroot/blog-${BUILD_ID}' 27 sh 'cd /var/webroot/blog-${BUILD_ID} && tar xf blog-${BUILD_ID}.tar.gz && rm -f blog-${BUILD_ID}.tar.gz' 28 sh 'cd /var/webroot && rm -rf my_blog && ln -s /var/webroot/blog-${BUILD_ID} /usr/share/nginx/html/my_blog' 29 } 30 31 } 32 stage('finished'){ 33 steps { 34 echo "finished" 35 sh "date +%F" 36 } 37 38 } 39 } 40 } Jenkinsfile

  提交后,Jenkins那邊的顯示為

    

    

  可以看到觸發(fā)的腳本事件正常運(yùn)行了,訪問下看下

[root@home-ct75211 my_blog]# elinks http://www.my-blog.cc --dump Internal Server Error
# 看下uwsgi的日志
[root@home
-ct75211 my_blog]# tailf /var/log/uwsgi21190.log added /root/py3web/lib/python3.7/site-packages/ to pythonpath. ModuleNotFoundError: No module named 'my_blog' unable to load app 1 (mountpoint='www.my-blog.cc|') (callable not found or import error) --- no python application found, check your startup logs for errors --- www.my-blog.cc [pid: 831|app: -1|req: -1/5] 127.0.0.1 () {42 vars in 539 bytes} [Sun Dec 16 08:09:16 2018] GET / => generated 21 bytes in 64 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

  因?yàn)樘摂M環(huán)境的pip里只裝了Django,但項(xiàng)目中還有用到了其他模塊,此處需要同步下pip環(huán)境。其實(shí)到這里,pipeline的部署已經(jīng)基本完結(jié)了,后面的基本就屬于Django項(xiàng)目的環(huán)境問題了

轉(zhuǎn)載于:https://www.cnblogs.com/zhujingxiu/p/10127084.html

總結(jié)

以上是生活随笔為你收集整理的CentOS7下的Django2集成部署五:Jenkins的流水线部署pipeline-job的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。