coding Jenkinsfile for continuous integration

pipeline {
  agent any
  stages {
    stage('检出') {
      steps {
        checkout([
          $class: 'GitSCM',
          branches: [[name: GIT_BUILD_REF]],
          userRemoteConfigs: [[
            url: GIT_REPO_URL,
            credentialsId: CREDENTIALS_ID
          ]]])
        }
      }

      stage('Node.js') {
        steps {
          sh 'rm -rf /usr/lib/node_modules/npm/'
          dir('/root/.cache/downloads') {
            sh 'wget -nc "https://nodejs.org/dist/v16.14.0/node-v16.14.0-linux-x64.tar.xz" -O node-v16.14.0-linux-x64.tar.xz | true'
            sh 'tar -xf node-v16.14.0-linux-x64.tar.xz -C /usr --strip-components 1'
          }

          sh 'npm install yarn -g'
        }
      }

      stage('安装依赖并打包') {
        steps {
          sh 'yarn install'
          sh 'cd packages/eee_energy/ && npm run build'
          echo '打包成功'
        }
      }

      stage('制作docker镜像后上传coding') {
        steps {
          sh 'docker -v'
          sh 'docker login -u energy -p 838838 xxxx-docker.pkg.coding.net'
          sh 'cd packages/ssss/ && ./energy_xxx_build.sh'
          echo '制作镜像成功'
          echo '上传成功'
        }
      }

    }
  }

energy_xxx_build.sh file content (make docker image upload coding product library and export docker image)

#!/bin/bash

# 设置变量
IMAGE_NAME="xxx-docker.pkg.coding.net/yyyyy/enejjd/xxxxs"         # 镜像名称
IMAGE_TAG="latest"            # 镜像标签
EXPORT_PATH="./mmmm.tar" # 导出路径和文件名
PUTH_NAME="coding" # 导出路径和文件名

# 执行 Docker 构建
docker rmi "$IMAGE_NAME"
docker build -t "$IMAGE_NAME:$IMAGE_TAG" .
docker push "$IMAGE_NAME:$IMAGE_TAG"
echo "镜像已push到 $PUTH_NAME"
# 导出镜像为 tar 文件
# docker save "$IMAGE_NAME:$IMAGE_TAG" -o "$EXPORT_PATH"

# echo "镜像已导出到 $EXPORT_PATH"

Make a mirror and start the sh file of the docker service

#!/bin/bash

# 设置变量
IMAGE_NAME="werr"         # 镜像名称
IMAGE_TAG="latest"            # 镜像标签
EXPORT_PATH="./eeee.tar" # 导出路径和文件名

docker stop "$IMAGE_NAME"
docker rm "$IMAGE_NAME"
# 执行 Docker 构建
docker rmi "$IMAGE_NAME"
docker build -t "$IMAGE_NAME:$IMAGE_TAG" .
docker run --name "$IMAGE_NAME" -itd -p 8048:80 "$IMAGE_NAME:$IMAGE_TAG"


echo "前端服务已启动 http://localhost:8048/xxxx/"

Automatic deployment server installation npm environment

      stage('Node.js') {
        steps {
          sh 'rm -rf /usr/lib/node_modules/npm/'
          dir('/root/.cache/downloads') {
            sh 'wget -nc "https://nodejs.org/dist/v16.14.0/node-v16.14.0-linux-x64.tar.xz" -O node-v16.14.0-linux-x64.tar.xz | true'
            sh 'tar -xf node-v16.14.0-linux-x64.tar.xz -C /usr --strip-components 1'
          }

          sh 'npm install yarn -g'
        }
      }

The first deployment of the test environment 

Install and start the watchtower mirror

Of course, if you only want Watchtower to update a specific container, you can reverse the above idea: that is, if it is used in the command line parameters of Watchtower --label-enable, then Watchtower will only update those com.centurylinklabs.watchtower.enable=truecontainers with labels. In this case, you only need to add this label to the container you want Watchtower to update, and other containers without this label will be ignored by Watchtower.

Then the command line parameters when Watchtower is established should be changed to:

docker run -d --name=watchtower -v /var/run/docker.sock:/var/run/docker.sock  -v /root/.docker/config.json:/config.json  --restart=always containrrr/watchtower --label-enable --cleanup --interval 60

Pull the image from the coding product library

docker pull xxxx-docker.pkg.coding.net/xxxn/dddd/fffds:latest

The second step is to start the service but add --label=com.centurylinklabs.watchtower.enable=true 
docker run --label=com.centurylinklabs.watchtower.enable=true --name rgy_sqqqdom -itd -p 8048:80 xxxx- docker.pkg.coding.net/xxxn/dddd/fffds:latest

Refer to  the wonderful use of docker seven: docker automatically updates the container - Watchtower full strategy (including most common parameters)_NAS storage_what is worth buying 

Guess you like

Origin blog.csdn.net/txl910514/article/details/131184294
Recommended