Jenkins搭建前后端分离项目流水线
项目简介
飞雪测试平台是我做的一个Django Vue前后端分离demo项目。主要用于日志管理,主要是兴趣驱动,体验一下全栈研发。顺便记录一下流水线搭建的一些关键代码。
前端地址:https://github.com/tdx1997tdx/my_tapd_frontend
后端地址:https://github.com/tdx1997tdx/my_tapd_backend
demo地址:http://139.198.36.243
流水线建设
对于这个项目建立了4条流水线
前端流水线pipline script
pipeline {
agent any
stages {
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打包出来的产物转移到nginx上
nginx配置流水线pipline script
pipeline {
agent any
stages {
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'
}
}
}
}
对于静态文件直接获取,对于后端接口,也就是api开头的,转发到8080端口
后端流水线pipline script
pipeline {
agent any
stages {
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 &'
}
}
}
}
后端数据库初始化流水线pipline script
pipeline {
agent any
stages {
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'
}
}
}
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhibaika
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22