日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/6/17 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CentOS7下的Django2集成部署五:Jenkins的流水线部署pipeline-job 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.Push本地的項目到GitLab

  準備工作:由于之前在MySQL設置時禁止了root用戶的遠程訪問,此處需要授權一個新的用戶

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)

#新建數據庫

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

  本地項目初始目錄

    

  在GitLab上新建項目

    

  push本地項目到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.創建Jenkins的pipeline-job

  創建步驟

    

  基本設置

      

   構建觸發器

      

  流水線構建

      

  重新保存下設置。

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

      

  此時需要在項目中添加下Jenkinsfile,以便后面的調試

      

  提交后,Jenkins這邊就已經自動觸發了

      

  執行完成后可以看到流水線記錄

      

  基本上pipeline已經就緒了

3.初步調試構建

  給my-blog項目配置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

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

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那邊的顯示為

    

    

  可以看到觸發的腳本事件正常運行了,訪問下看下

[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)

  因為虛擬環境的pip里只裝了Django,但項目中還有用到了其他模塊,此處需要同步下pip環境。其實到這里,pipeline的部署已經基本完結了,后面的基本就屬于Django項目的環境問題了

轉載于:https://www.cnblogs.com/zhujingxiu/p/10127084.html

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。