|
@@ -1,31 +1,34 @@
|
|
|
/**
|
|
/**
|
|
|
- * Harbor ???? + ACK ??????? Jenkins ????
|
|
|
|
|
- * ????produ/<prodDir>/Jenkinsfile
|
|
|
|
|
- * ??/???produ/whole/Jenkinsfile ? produ/promote-image/Jenkinsfile
|
|
|
|
|
|
|
+ * Harbor image promote + optional ACK deploy (loaded from Jenkinsfile, not a job entry).
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-/** ???? tag */
|
|
|
|
|
def resolveTargetTag(def script, String targetTagParam) {
|
|
def resolveTargetTag(def script, String targetTagParam) {
|
|
|
def t = (targetTagParam ?: '').trim()
|
|
def t = (targetTagParam ?: '').trim()
|
|
|
return t ?: "produ-${script.env.BUILD_NUMBER}"
|
|
return t ?: "produ-${script.env.BUILD_NUMBER}"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * ?????????? Harbor ???pull ? tag ? tag ?? tag ? push?
|
|
|
|
|
- * cfg: harborRegistry, harborProject, sourceTag, targetTag, harborCredentialsId, dryRun
|
|
|
|
|
- * services: List<Map> ? prodDir
|
|
|
|
|
- */
|
|
|
|
|
|
|
+def requireSourceTag(def script, String sourceTag) {
|
|
|
|
|
+ def srcTag = (sourceTag ?: '').trim()
|
|
|
|
|
+ if (!srcTag) {
|
|
|
|
|
+ script.error('SOURCE_TAG is required (e.g. uat-build-42). Check Harbor for an existing tag.')
|
|
|
|
|
+ }
|
|
|
|
|
+ if (srcTag == 'uat-latest') {
|
|
|
|
|
+ script.echo 'WARNING: SOURCE_TAG=uat-latest is usually not in Harbor; use the real UAT build tag.'
|
|
|
|
|
+ }
|
|
|
|
|
+ return srcTag
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
def promoteHarborImages(def script, List services, Map cfg) {
|
|
def promoteHarborImages(def script, List services, Map cfg) {
|
|
|
def regHost = cfg.harborRegistry.trim()
|
|
def regHost = cfg.harborRegistry.trim()
|
|
|
def proj = cfg.harborProject.trim()
|
|
def proj = cfg.harborProject.trim()
|
|
|
- def srcTag = (cfg.sourceTag ?: 'uat-latest').trim()
|
|
|
|
|
|
|
+ def srcTag = requireSourceTag(script, cfg.sourceTag)
|
|
|
def tgtTag = cfg.targetTag
|
|
def tgtTag = cfg.targetTag
|
|
|
def dryRun = cfg.dryRun == true
|
|
def dryRun = cfg.dryRun == true
|
|
|
|
|
|
|
|
services.each { s ->
|
|
services.each { s ->
|
|
|
def src = "${regHost}/${proj}/${s.prodDir}:${srcTag}"
|
|
def src = "${regHost}/${proj}/${s.prodDir}:${srcTag}"
|
|
|
def tgt = "${regHost}/${proj}/${s.prodDir}:${tgtTag}"
|
|
def tgt = "${regHost}/${proj}/${s.prodDir}:${tgtTag}"
|
|
|
- echo ">>> ???? ${s.prodDir}: ${src} ? ${tgt}"
|
|
|
|
|
|
|
+ echo ">>> promote ${s.prodDir}: ${src} -> ${tgt}"
|
|
|
if (dryRun) {
|
|
if (dryRun) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -39,7 +42,10 @@ def promoteHarborImages(def script, List services, Map cfg) {
|
|
|
usernameVariable: 'HARBOR_USER',
|
|
usernameVariable: 'HARBOR_USER',
|
|
|
passwordVariable: 'HARBOR_PASS',
|
|
passwordVariable: 'HARBOR_PASS',
|
|
|
)]) {
|
|
)]) {
|
|
|
- script.sh "echo \${HARBOR_PASS} | docker login ${regHost} -u \${HARBOR_USER} --password-stdin"
|
|
|
|
|
|
|
+ script.sh """
|
|
|
|
|
+ set -e
|
|
|
|
|
+ echo "\${HARBOR_PASS}" | docker login ${regHost} -u "\${HARBOR_USER}" --password-stdin
|
|
|
|
|
+ """
|
|
|
services.each { s ->
|
|
services.each { s ->
|
|
|
def src = "${regHost}/${proj}/${s.prodDir}:${srcTag}"
|
|
def src = "${regHost}/${proj}/${s.prodDir}:${srcTag}"
|
|
|
def tgt = "${regHost}/${proj}/${s.prodDir}:${tgtTag}"
|
|
def tgt = "${regHost}/${proj}/${s.prodDir}:${tgtTag}"
|
|
@@ -81,11 +87,10 @@ def deployToAck(def script, Map cfg) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/** ?????? + ?? ACK */
|
|
|
|
|
def promoteOneServiceToAck(def script, Map svc, Map params, Map env) {
|
|
def promoteOneServiceToAck(def script, Map svc, Map params, Map env) {
|
|
|
def regHost = params.HARBOR_REGISTRY.trim()
|
|
def regHost = params.HARBOR_REGISTRY.trim()
|
|
|
def proj = params.HARBOR_PROJECT.trim()
|
|
def proj = params.HARBOR_PROJECT.trim()
|
|
|
- def srcTag = (params.SOURCE_TAG ?: 'uat-latest').trim()
|
|
|
|
|
|
|
+ def srcTag = requireSourceTag(script, params.SOURCE_TAG)
|
|
|
def tgtTag = resolveTargetTag(script, params.TARGET_TAG)
|
|
def tgtTag = resolveTargetTag(script, params.TARGET_TAG)
|
|
|
def dryRun = params.DRY_RUN == true
|
|
def dryRun = params.DRY_RUN == true
|
|
|
def strategy = params.DEPLOY_STRATEGY ?: 'rolling'
|
|
def strategy = params.DEPLOY_STRATEGY ?: 'rolling'
|