|
@@ -5,8 +5,9 @@
|
|
|
* Script Path: docs/jenkins/Jenkinsfile-uat-build-deploy.groovy
|
|
* Script Path: docs/jenkins/Jenkinsfile-uat-build-deploy.groovy
|
|
|
*
|
|
*
|
|
|
* Harbor (153.68): when PUSH_TO_HARBOR=true, push e.g.
|
|
* Harbor (153.68): when PUSH_TO_HARBOR=true, push e.g.
|
|
|
- * 39.105.153.68/alien_cloud/gateway:uat-build-<BUILD_NUMBER>
|
|
|
|
|
- * Production promote jobs use SOURCE_TAG=uat-build-<same number>.
|
|
|
|
|
|
|
+ * 39.105.153.68/alien_cloud/gateway:uat-latest
|
|
|
|
|
+ * Before push: existing uat-latest is archived as uat-build-<BUILD_NUMBER> (same digest).
|
|
|
|
|
+ * New image is pushed only as uat-latest. Prod promote: SOURCE_TAG=uat-latest.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
/** HARBOR_PUSH_SCOPE: all-java-services | <repo>-only */
|
|
/** HARBOR_PUSH_SCOPE: all-java-services | <repo>-only */
|
|
@@ -26,8 +27,8 @@ def filterHarborPushScope(List allServices, String scope) {
|
|
|
error("Unknown HARBOR_PUSH_SCOPE: ${scope}")
|
|
error("Unknown HARBOR_PUSH_SCOPE: ${scope}")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/** Delete oldest uat-build-* tags in Harbor, keep newest KEEP (never deletes CURRENT_TAG). */
|
|
|
|
|
-def pruneHarborUatTags(def script, String reg, String proj, List repoNames, int keepCount, String tagPrefix, String currentTag) {
|
|
|
|
|
|
|
+/** Delete oldest uat-build-* tags in Harbor, keep newest KEEP. Never deletes uat-latest or current build tag. */
|
|
|
|
|
+def pruneHarborUatTags(def script, String reg, String proj, List repoNames, int keepCount, String tagPrefix, String currentBuildTag, String latestTag) {
|
|
|
if (repoNames == null || repoNames.isEmpty() || keepCount < 1) {
|
|
if (repoNames == null || repoNames.isEmpty() || keepCount < 1) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -38,7 +39,8 @@ def pruneHarborUatTags(def script, String reg, String proj, List repoNames, int
|
|
|
PROJ='${proj}'
|
|
PROJ='${proj}'
|
|
|
KEEP=${keepCount}
|
|
KEEP=${keepCount}
|
|
|
PREFIX='${tagPrefix}'
|
|
PREFIX='${tagPrefix}'
|
|
|
- CURRENT='${currentTag}'
|
|
|
|
|
|
|
+ CURRENT='${currentBuildTag}'
|
|
|
|
|
+ LATEST='${latestTag}'
|
|
|
if ! command -v jq >/dev/null 2>&1; then
|
|
if ! command -v jq >/dev/null 2>&1; then
|
|
|
echo '>>> Harbor prune skipped: jq not installed on Jenkins agent'
|
|
echo '>>> Harbor prune skipped: jq not installed on Jenkins agent'
|
|
|
exit 0
|
|
exit 0
|
|
@@ -57,7 +59,7 @@ def pruneHarborUatTags(def script, String reg, String proj, List repoNames, int
|
|
|
i=0
|
|
i=0
|
|
|
while [ "\${i}" -lt "\${del_count}" ]; do
|
|
while [ "\${i}" -lt "\${del_count}" ]; do
|
|
|
t="\${tags[\$i]}"
|
|
t="\${tags[\$i]}"
|
|
|
- if [ "\${t}" = "\${CURRENT}" ]; then
|
|
|
|
|
|
|
+ if [ "\${t}" = "\${CURRENT}" ] || [ "\${t}" = "\${LATEST}" ]; then
|
|
|
i=\$((i + 1))
|
|
i=\$((i + 1))
|
|
|
continue
|
|
continue
|
|
|
fi
|
|
fi
|
|
@@ -93,7 +95,7 @@ pipeline {
|
|
|
booleanParam(
|
|
booleanParam(
|
|
|
name: 'PUSH_TO_HARBOR',
|
|
name: 'PUSH_TO_HARBOR',
|
|
|
defaultValue: true,
|
|
defaultValue: true,
|
|
|
- description: 'After Maven: docker build + push to Harbor (tag uat-build-<BUILD_NUMBER>). Uncheck for jar-only UAT deploy.'
|
|
|
|
|
|
|
+ description: 'After Maven: docker build + push to Harbor (tags uat-latest and uat-build-<N>). Uncheck for jar-only UAT deploy.'
|
|
|
)
|
|
)
|
|
|
choice(
|
|
choice(
|
|
|
name: 'HARBOR_PUSH_SCOPE',
|
|
name: 'HARBOR_PUSH_SCOPE',
|
|
@@ -114,7 +116,7 @@ pipeline {
|
|
|
booleanParam(
|
|
booleanParam(
|
|
|
name: 'HARBOR_PRUNE_OLD_TAGS',
|
|
name: 'HARBOR_PRUNE_OLD_TAGS',
|
|
|
defaultValue: true,
|
|
defaultValue: true,
|
|
|
- description: 'After push: delete old uat-build-* tags in Harbor, keep last N per repo (not base/*)'
|
|
|
|
|
|
|
+ description: 'After push: delete old uat-build-* tags in Harbor, keep last N per repo (never deletes uat-latest)'
|
|
|
)
|
|
)
|
|
|
string(name: 'HARBOR_KEEP_TAG_COUNT', defaultValue: '10', trim: true,
|
|
string(name: 'HARBOR_KEEP_TAG_COUNT', defaultValue: '10', trim: true,
|
|
|
description: 'How many uat-build-* tags to keep per repository')
|
|
description: 'How many uat-build-* tags to keep per repository')
|
|
@@ -126,7 +128,8 @@ pipeline {
|
|
|
GIT_URL = 'http://8.152.195.41:3000/alien/alien_cloud'
|
|
GIT_URL = 'http://8.152.195.41:3000/alien/alien_cloud'
|
|
|
GIT_CREDENTIALS = 'zhanghaomimapingzheng'
|
|
GIT_CREDENTIALS = 'zhanghaomimapingzheng'
|
|
|
HARBOR_CREDENTIALS = 'harbor-robot-alien'
|
|
HARBOR_CREDENTIALS = 'harbor-robot-alien'
|
|
|
- UAT_HARBOR_IMAGE_TAG = "uat-build-${env.BUILD_NUMBER}"
|
|
|
|
|
|
|
+ UAT_HARBOR_LATEST_TAG = 'uat-latest'
|
|
|
|
|
+ UAT_HARBOR_BUILD_TAG = "uat-build-${env.BUILD_NUMBER}"
|
|
|
DOCKERFILE_JAVA = 'docs/jenkins/produ/docker/Dockerfile.java-service'
|
|
DOCKERFILE_JAVA = 'docs/jenkins/produ/docker/Dockerfile.java-service'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -239,7 +242,8 @@ pipeline {
|
|
|
script {
|
|
script {
|
|
|
def reg = params.HARBOR_REGISTRY.trim()
|
|
def reg = params.HARBOR_REGISTRY.trim()
|
|
|
def proj = params.HARBOR_PROJECT.trim()
|
|
def proj = params.HARBOR_PROJECT.trim()
|
|
|
- def tag = env.UAT_HARBOR_IMAGE_TAG
|
|
|
|
|
|
|
+ def latestTag = env.UAT_HARBOR_LATEST_TAG
|
|
|
|
|
+ def buildTag = env.UAT_HARBOR_BUILD_TAG
|
|
|
def baseImage = "${reg}/${proj}/base/openjdk8-ffmpeg:v1"
|
|
def baseImage = "${reg}/${proj}/base/openjdk8-ffmpeg:v1"
|
|
|
def dockerfile = env.DOCKERFILE_JAVA
|
|
def dockerfile = env.DOCKERFILE_JAVA
|
|
|
|
|
|
|
@@ -266,7 +270,8 @@ pipeline {
|
|
|
"""
|
|
"""
|
|
|
harborServices.each { svc ->
|
|
harborServices.each { svc ->
|
|
|
def jarName = "${svc.module}-1.0.0.jar"
|
|
def jarName = "${svc.module}-1.0.0.jar"
|
|
|
- def imageRef = "${reg}/${proj}/${svc.repo}:${tag}"
|
|
|
|
|
|
|
+ def imageLatest = "${reg}/${proj}/${svc.repo}:${latestTag}"
|
|
|
|
|
+ def imageBuild = "${reg}/${proj}/${svc.repo}:${buildTag}"
|
|
|
sh """
|
|
sh """
|
|
|
set -e
|
|
set -e
|
|
|
test -f ${WORKSPACE}/${svc.module}/target/${jarName}
|
|
test -f ${WORKSPACE}/${svc.module}/target/${jarName}
|
|
@@ -279,25 +284,31 @@ pipeline {
|
|
|
touch .jenkins_docker_ctx/lib/.keep
|
|
touch .jenkins_docker_ctx/lib/.keep
|
|
|
fi
|
|
fi
|
|
|
cd .jenkins_docker_ctx
|
|
cd .jenkins_docker_ctx
|
|
|
|
|
+ if docker pull ${imageLatest} 2>/dev/null; then
|
|
|
|
|
+ echo ">>> archive previous ${latestTag} -> ${buildTag}"
|
|
|
|
|
+ docker tag ${imageLatest} ${imageBuild}
|
|
|
|
|
+ docker push ${imageBuild}
|
|
|
|
|
+ fi
|
|
|
docker build -f ${WORKSPACE}/${dockerfile} \\
|
|
docker build -f ${WORKSPACE}/${dockerfile} \\
|
|
|
--build-arg BASE_IMAGE=${baseImage} \\
|
|
--build-arg BASE_IMAGE=${baseImage} \\
|
|
|
--build-arg JAR_FILE=${jarName} \\
|
|
--build-arg JAR_FILE=${jarName} \\
|
|
|
--build-arg SERVER_PORT=${svc.port} \\
|
|
--build-arg SERVER_PORT=${svc.port} \\
|
|
|
--build-arg WITH_LIB=${svc.withLib} \\
|
|
--build-arg WITH_LIB=${svc.withLib} \\
|
|
|
- -t ${imageRef} .
|
|
|
|
|
- docker push ${imageRef}
|
|
|
|
|
- echo ">>> pushed ${imageRef}"
|
|
|
|
|
|
|
+ -t ${imageLatest} .
|
|
|
|
|
+ docker push ${imageLatest}
|
|
|
|
|
+ echo ">>> pushed ${imageLatest} (archived prior latest as ${buildTag} if any)"
|
|
|
"""
|
|
"""
|
|
|
}
|
|
}
|
|
|
if (params.HARBOR_PRUNE_OLD_TAGS == true) {
|
|
if (params.HARBOR_PRUNE_OLD_TAGS == true) {
|
|
|
def keepN = (params.HARBOR_KEEP_TAG_COUNT ?: '10').trim() as int
|
|
def keepN = (params.HARBOR_KEEP_TAG_COUNT ?: '10').trim() as int
|
|
|
pruneHarborUatTags(
|
|
pruneHarborUatTags(
|
|
|
this, reg, proj, harborServices*.repo,
|
|
this, reg, proj, harborServices*.repo,
|
|
|
- keepN, 'uat-build-', tag,
|
|
|
|
|
|
|
+ keepN, 'uat-build-', buildTag, latestTag,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- echo ">>> Harbor tag for prod promote: SOURCE_TAG=${tag}"
|
|
|
|
|
|
|
+ echo ">>> Harbor latest: ${env.UAT_HARBOR_LATEST_TAG}; archived tag this run: ${env.UAT_HARBOR_BUILD_TAG}"
|
|
|
|
|
+ echo ">>> Prod promote: SOURCE_TAG=${env.UAT_HARBOR_LATEST_TAG}"
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -361,8 +372,8 @@ pipeline {
|
|
|
success {
|
|
success {
|
|
|
script {
|
|
script {
|
|
|
if (params.PUSH_TO_HARBOR) {
|
|
if (params.PUSH_TO_HARBOR) {
|
|
|
- echo ">>> Harbor images tagged: ${env.UAT_HARBOR_IMAGE_TAG}"
|
|
|
|
|
- echo ">>> Prod promote: SOURCE_TAG=${env.UAT_HARBOR_IMAGE_TAG}"
|
|
|
|
|
|
|
+ echo ">>> Harbor latest: ${env.UAT_HARBOR_LATEST_TAG}"
|
|
|
|
|
+ echo ">>> Prod promote: SOURCE_TAG=${env.UAT_HARBOR_LATEST_TAG}"
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|