| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // 与 whole/Jenkinsfile 相同逻辑
- def sparseCheckoutProduShared() {
- checkout scm: [
- $class: 'GitSCM',
- branches: scm.branches,
- extensions: [
- [$class: 'CloneOption', depth: 1, shallow: true, noTags: true],
- [$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [
- [path: 'docs/jenkins/produ/_shared/'],
- ]],
- ],
- userRemoteConfigs: scm.userRemoteConfigs,
- ]
- }
- def getProduLibs() {
- sparseCheckoutProduShared()
- def k8s = load 'docs/jenkins/produ/_shared/k8s-produ-lib.groovy'
- def reg = load 'docs/jenkins/produ/_shared/service-registry.groovy'
- return [k8s, reg]
- }
- pipeline {
- agent any
- options {
- buildDiscarder(logRotator(numToKeepStr: '20'))
- disableConcurrentBuilds()
- timestamps()
- timeout(time: 120, unit: 'MINUTES')
- }
- parameters {
- choice(name: 'DEPLOY_MODE', choices: ['whole', 'single', 'multi'])
- choice(name: 'SINGLE_SERVICE', choices: [
- 'gateway', 'store', 'second', 'store-platform', 'lawyer', 'job', 'dining',
- ])
- booleanParam(name: 'MULTI_gateway', defaultValue: false)
- booleanParam(name: 'MULTI_store', defaultValue: false)
- booleanParam(name: 'MULTI_second', defaultValue: false)
- booleanParam(name: 'MULTI_store_platform', defaultValue: false)
- booleanParam(name: 'MULTI_lawyer', defaultValue: false)
- booleanParam(name: 'MULTI_job', defaultValue: false)
- booleanParam(name: 'MULTI_dining', defaultValue: false)
- string(name: 'SOURCE_TAG', defaultValue: '', trim: true)
- string(name: 'TARGET_TAG', defaultValue: '', trim: true)
- string(name: 'HARBOR_REGISTRY', defaultValue: '39.105.153.68', trim: true)
- string(name: 'HARBOR_PROJECT', defaultValue: 'alien_cloud', trim: true)
- choice(name: 'DEPLOY_STRATEGY', choices: ['rolling', 'canary', 'skip'])
- string(name: 'CANARY_WEIGHT', defaultValue: '10', trim: true)
- string(name: 'K8S_NAMESPACE', defaultValue: 'alien-produ', trim: true)
- booleanParam(name: 'DRY_RUN', defaultValue: false)
- }
- environment {
- HARBOR_CREDENTIALS = 'harbor-robot-alien'
- KUBECONFIG_CREDENTIALS = 'ack-kubeconfig-alien'
- }
- stages {
- stage('Plan') {
- steps {
- script {
- def (k8s, reg) = getProduLibs()
- def services = reg.filterServices(reg.getServiceRegistry(), params)
- env.PROMOTE_LIST = services*.prodDir.join(',')
- env.TARGET_TAG_RESOLVED = k8s.resolveTargetTag(this, params.TARGET_TAG)
- echo ">>> 服务=${env.PROMOTE_LIST} ${params.SOURCE_TAG} → ${env.TARGET_TAG_RESOLVED}"
- }
- }
- }
- stage('Promote images') {
- steps {
- script {
- def (k8s, reg) = getProduLibs()
- def services = reg.filterServices(reg.getServiceRegistry(), params)
- k8s.promoteHarborImages(this, services, [
- harborRegistry: params.HARBOR_REGISTRY,
- harborProject: params.HARBOR_PROJECT,
- sourceTag: params.SOURCE_TAG,
- targetTag: env.TARGET_TAG_RESOLVED,
- harborCredentialsId: env.HARBOR_CREDENTIALS,
- dryRun: params.DRY_RUN == true,
- ])
- }
- }
- }
- stage('Deploy to ACK') {
- when { expression { return params.DEPLOY_STRATEGY != 'skip' && !params.DRY_RUN } }
- steps {
- script {
- def (k8s, reg) = getProduLibs()
- def services = reg.filterServices(reg.getServiceRegistry(), params)
- def regHost = params.HARBOR_REGISTRY.trim()
- def proj = params.HARBOR_PROJECT.trim()
- def tgtTag = env.TARGET_TAG_RESOLVED
- def strategy = params.DEPLOY_STRATEGY
- services.each { s ->
- def imageRef = "${regHost}/${proj}/${s.prodDir}:${tgtTag}"
- k8s.deployToAck(this, [
- k8sNamespace: params.K8S_NAMESPACE,
- imageRef: imageRef,
- deployStrategy: strategy == 'canary' ? 'canary' : 'rolling',
- deploymentStable: s.deployName,
- deploymentCanary: "${s.deployName}-canary",
- ingressCanary: "${s.deployName}-canary",
- canaryWeight: (params.CANARY_WEIGHT ?: '10').trim(),
- kubeCredentialsId: env.KUBECONFIG_CREDENTIALS,
- ])
- }
- }
- }
- }
- }
- }
|