• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
飘飞雪
帮助1

项目简介

飞雪测试平台是我做的一个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
系列文章
更多 icon
同类精品
更多 icon
继续加载