群智/信创社区构建脚本

郭超 6a4daa7f36 Merge branch 'private-release-v2021' into 'master' il y a 3 ans
.idea 9c1c5352f6 修改ip il y a 3 ans
crowd-service 8ad39915f8 add readme.md il y a 3 ans
shell b636004a03 修改oss.sh il y a 3 ans
.DS_Store 40f4659eeb 更新文件 il y a 3 ans
readme.md 8ad39915f8 add readme.md il y a 3 ans

readme.md

项目说明

  1. 项目名称:信创平台私有云部署项目
  2. 项目负责人:郭超
  3. 项目文件夹说明:
  4. 需要结合jenkins构建脚本理解此项目。
  5. entity:jenkins构建时会先下载此项目,将所需的docker镜像放置crowd-service/entity中。
  6. nginx:docker-compose中的crowd_frontend会将nginx挂载至容器中,所以nginx的配置就是信创平台的配置。
  7. private-docker:里边是起mysql的初始化文件,jenkins打mysql镜像时会使用private-docker/mysql中的Dockerfile文件,此Dockerfile会执行对应的三个.sql文件,对数据库进行初始化操作。如果开发时有对数据库字表格结构进行修改,则在部署时需要修改.sql文件。
  8. TestFileSystem:这是存放平台文件的地方,注意:如果加了文件或文件夹,记得修改对应的权限,chmod 775 ...,否则可能会出现图片访问403

    pipeline {
    agent any
    stages {
        stage('prepare-framework') {
            steps {
                //sh 'if [ ! -d framework ]; then mkdir -p framework; fi && cd framework'
                echo "crowd-service private cloud [framework] preparing..."
                git branch: 'private-release-v2021', credentialsId: 'jenkins_git_com', url: 'ssh://git@git.mooctest.com:1022/crowd-2019/crowd-test-service-private-cloud.git'
                sh 'pwd && ls -al'
                sh 'chmod -R 777 ./crowd-service/TestFileSystem/'
            }
        }
        stage('cofotest-backend-job') {
            //后端构建
            steps{
                echo "crowd-service private cloud [backend] building..."
                //sh 'docker rmi $(docker images --filter=reference="crowd-backend" -q)'
                build job: '构建-群智项目后端-私有云环境', quietPeriod: 0
                echo "copy [backend image] to ./crowd-service/entity "
                sh 'cp ../构建-群智项目后端-私有云环境/crowd-backend.tar ./crowd-service/entity/'
            } 
        }
        stage('cofotest-frontend-job') {
            //前端构建
            steps{
                echo "crowd-service private cloud [frontend] building..."
                //sh 'docker rmi $(docker images --filter=reference="crowd-frontend" -q)'
                build job: '构建-群智项目前端-私有云环境', quietPeriod: 0
                echo "copy [fronend image] to ./crowd-service/ ..."
                sh 'cp -r ../构建-群智项目前端-私有云环境/crowd-frontend.tar ./crowd-service/entity/'
            }
        }
        stage('cofotest-user-job') {
            //后端构建
            steps{
                echo "crowd-service private cloud [user] building..."
                //sh 'docker rmi $(docker images --filter=reference="crowd-user" -q)'
                build job: '构建-群智用户服务-私有云环境', quietPeriod: 0
                echo "copy [user image] to ./crowd-service/entity "
                sh 'cp ../构建-群智用户服务-私有云环境/crowd-user.tar ./crowd-service/entity/'
            } 
        }
        stage('cofotest-mysql-job') {
            steps{
                echo 'cofotest db build'
                //sh 'docker rmi $(docker images --filter=reference="crowd-mysql" -q)'
                sh 'cd ./crowd-service/private-docker/mysql/ && docker build -t crowd-mysql .'
                sh 'docker save -o ./crowd-service/entity/crowd-mysql.tar crowd-mysql && ls -sl ./crowd-service/entity/'
            }
        }
        stage('cofotest-redis-job') {
            steps{
                echo 'redis docker build'
                //sh 'docker rmi $(docker images --filter=reference="crowd-redis" -q)'
                sh 'docker pull redis:latest'
                sh 'docker tag redis:latest crowd-redis'
                sh 'docker save -o ./crowd-service/entity/crowd-redis.tar crowd-redis && ls -sl ./crowd-service/entity/'
            }
        }
        stage('zip-job') {
            //压缩部署环境
            steps{
                echo 'zip private crowd-service'
                sh "zip -r private-crowd-service.zip ./crowd-service/"
                echo '看一下private-crowd-service.zip的大小'
                sh "ls -alh"
            }
        }
        stage('upload-job') {
            //上传到oss
            steps{
                echo 'upload private crowd-service'
                sh 'echo v${BUILD_NUMBER} >> private_crowd_service.txt'
                sh 'env LANG=en_US.UTF-8 date'
                // sh "env LANG=en_US.UTF-8 /bin/bash ./shell/oss.sh put private_crowd_service.txt private-cloud/crowd-test-service/private_crowd_service.txt"
                sh "env LANG=en_US.UTF-8 /bin/bash ./shell/oss.sh put private-crowd-service.zip private-cloud/crowd-test-service/private-crowd-service.v${BUILD_NUMBER}.zip"
            }
        }
    }
        
    post {
        // 后续的清理工作
        always {
            echo "试一下post"
        }
            
        success {
            // build job: '私有云自动化部署', quietPeriod: 2
            echo "success"
        }
    }
    }
    
    1. 文件说明
    2. .env:docker-compose中使用的变量
    3. 带有local.sh字样的是用于本地自己测试部署的。不带有此字样的是正式环境部署的。
    4. load-images.sh/remove-images.sh:加载和卸载镜像。
    5. shell文件夹中的是将Jenkins打包好的zip包上传至oss。