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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Jenkins搭建前后端分离项目流水线实战

發(fā)布時間:2023/12/8 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Jenkins搭建前后端分离项目流水线实战 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

  • 項目簡介
  • 流水線建設(shè)
    • 前端流水線pipline script
    • nginx配置流水線pipline script
    • 后端流水線pipline script
    • 后端數(shù)據(jù)庫初始化流水線pipline script

項目簡介

飛雪測試平臺是我做的一個Django+Vue前后端分離demo項目。主要用于日志管理,主要是興趣驅(qū)動,體驗一下全棧研發(fā)。順便記錄一下流水線搭建的一些關(guān)鍵代碼。

前端地址:https://github.com/tdx1997tdx/my_tapd_frontend
后端地址:https://github.com/tdx1997tdx/my_tapd_backend
demo地址:http://139.198.36.243

流水線建設(shè)

對于這個項目建立了4條流水線

前端流水線pipline script

pipeline {agent anystages {stage('git clone') {steps {git credentialsId: 'f4209992-d0c8-4f10-bcea-c5edaa0846f1', url: 'https://github.com/tdx1997tdx/my_tapd_frontend.git'}}stage('npm build') {steps {sh 'npm install'sh 'npm run build'}}stage('copy files to nginx') {steps {sh 'rm -rf /usr/local/nginx/html/*'sh 'cp -r ./dist/* /usr/local/nginx/html/'}}} }

主要流程就是npm打包出來的產(chǎn)物轉(zhuǎn)移到nginx上

nginx配置流水線pipline script

pipeline {agent anystages {stage('change_conf') {steps {writeFile encoding: 'utf-8', file: '/usr/local/nginx/conf/nginx.conf', text: ''' worker_processes 1;events {worker_connections 1024; }http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;#gzip on;server {listen 80;server_name 139.198.36.243;location / {root html;index index.html index.htm;}location /api/ {proxy_pass http://127.0.0.1:8080;}} } '''}}stage('restart nginx') {steps {sh 'systemctl restart nginx.service'}}} }

對于靜態(tài)文件直接獲取,對于后端接口,也就是api開頭的,轉(zhuǎn)發(fā)到8080端口

后端流水線pipline script

pipeline {agent anystages {stage('git pull') {steps {git credentialsId: 'f4209992-d0c8-4f10-bcea-c5edaa0846f1', url: 'https://github.com/tdx1997tdx/my_tapd_backend.git'}}stage('start') {steps {sh 'killall gunicorn || true'sh 'JENKINS_NODE_COOKIE=dontKillMe nohup /usr/local/python3/bin/gunicorn my_tapd_backend.wsgi -w 4 -b 0.0.0.0:8080 &'}}} }

后端數(shù)據(jù)庫初始化流水線pipline script

pipeline {agent anystages {stage('git pull') {steps {git credentialsId: 'f4209992-d0c8-4f10-bcea-c5edaa0846f1', url: 'https://github.com/tdx1997tdx/my_tapd_backend.git'}}stage('migrate') {steps {sh 'pip3 install -r requirements.txt'sh 'python3 manage.py makemigrations'sh 'python3 manage.py migrate'}}} }

總結(jié)

以上是生活随笔為你收集整理的Jenkins搭建前后端分离项目流水线实战的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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