侧边栏壁纸
博主头像
★街角晚灯★博主等级

博观而约取 厚积而薄发

  • 累计撰写 466 篇文章
  • 累计创建 185 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

JenkinsFile-Kubernetes Frontend Demo

WinJay
2023-07-21 / 0 评论 / 0 点赞 / 51 阅读 / 3724 字 / 正在检测是否收录...
温馨提示:
文章发布较早,内容可能过时,阅读注意甄别。。。。
pipeline {
  agent {
    kubernetes {
      yaml """\
        apiVersion: v1
        kind: Pod
        metadata:
          labels:
            name: market-dev
        spec:
          imagePullSecrets:
            - name: registry-secret
          containers:
          - name: node
            image: node:12.22.0-cnpm
            command:
            - cat
            imagePullPolicy: IfNotPresent
            tty: true
            resources:
              limits:
                cpu: "1"
                memory: 1536Mi
              requests:
                cpu: "1"
                memory: 1536Mi
          - name: kubectl
            image: kubectl:v1.22.10-aliyun.1
            command:
            - cat
            imagePullPolicy: IfNotPresent
            tty: true
            volumeMounts:
              - name: kube-config
                mountPath: /root/.kube
          - name: buildkit
            image: centos:latest
            command:
            - cat
            imagePullPolicy: IfNotPresent
            tty: true
            volumeMounts:
              - name: buildkit-client
                mountPath: /usr/local/bin/buildctl
              - name: buildkit-sock
                mountPath: /run/buildkit/buildkitd.sock
              - name: ctr-client
                mountPath: /usr/bin/ctr
              - name: ctr-sock
                mountPath: /var/run/containerd/containerd.sock
              - name: docker-config
                mountPath: /root/.docker
          volumes:
          - name: buildkit-client
            hostPath:
             path: /usr/local/bin/buildctl
             type: File
          - name: buildkit-sock
            hostPath:
              path: /run/buildkit/buildkitd.sock
              type: Socket
          - name: ctr-client
            hostPath:
             path: /usr/bin/ctr
             type: File
          - name: ctr-sock
            hostPath:
              path: /var/run/containerd/containerd.sock 
              type: Socket
          - name: kube-config
            configMap:
              name: kube-config
          - name: docker-config
            configMap:
              name: docker-config
        """.stripIndent()
    }
  }
  environment {
    REGISTRY_URL = 'registry-vpc.cn-beijing.cr.aliyuncs.com'
    NAMESPACE = 'dev'
    IMAGE_NAME = '${REGISTRY_URL}/${NAMESPACE}/${JOB_NAME}:${BUILD_NUMBER}'
    NAMESPACES = 'front-dev'
    DEPLOY_NAME = 'front-market'
    RESOURCES_TYPE = 'deployment'
    CONTAINER_NAME = 'front-market'
}

  stages {

    stage('拉取代码') {
      steps {
        git branch: 'develop', credentialsId: '624d2ec2-0791-4786-811a-5776b76a4f3b', url: 'http://xxxx/front.market.git'
      }
    }

    stage('编译代码') {
        steps {
          container('node') {
            sh """
            cnpm install 
			cnpm run build
            """
        }
      }
    }

      stage('生成镜像') {
        steps {
          withCredentials([usernamePassword(credentialsId: "9cd8351d-8157-468e-9ef1-f918ca04b137", passwordVariable: 'password', usernameVariable: 'username')]) {
            container('buildkit') {
              sh """
               buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${IMAGE_NAME} && \
               ctr -n buildkit i push -u ${username}:${password} ${IMAGE_NAME}
              """
           }
        }
      }
    }

      stage('部署到集群') {
        steps {
          container('kubectl') {
            sh """
            kubectl set image -n ${NAMESPACES} ${RESOURCES_TYPE} ${DEPLOY_NAME} ${CONTAINER_NAME}=${IMAGE_NAME} --record
            """
        }
      }
    }
  }
}


0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区