From 3edb93abb60e14ac9824ab2a748f2da35229cc3b Mon Sep 17 00:00:00 2001 From: radnov Date: Tue, 22 Oct 2024 20:11:57 +0300 Subject: [PATCH] ci: set base image in rebuild pipeline, not script [skip ci] (#18832) Signed-off-by: Rado --- dhis-2/build-docker-image.sh | 7 +------ jenkinsfiles/rebuild-image | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/dhis-2/build-docker-image.sh b/dhis-2/build-docker-image.sh index d9ae638b253e..3762a8e9c226 100755 --- a/dhis-2/build-docker-image.sh +++ b/dhis-2/build-docker-image.sh @@ -2,6 +2,7 @@ set -euo pipefail +BASE_IMAGE=${BASE_IMAGE} IMAGE_REPOSITORY=${IMAGE_REPOSITORY:-'dhis2/core'} IMAGE_APP_ROOT=${IMAGE_APP_ROOT:-'/usr/local/tomcat/webapps/ROOT'} IMAGE_USER=${IMAGE_USER:-'65534'} @@ -211,12 +212,6 @@ else use_new_war fi -jdk_version="$( - echo "$stable_versions_json" | - jq -r --argjson major "$major" '.versions[] | select(.version == $major) .jdk' -)" -BASE_IMAGE="${BASE_IMAGE:-"tomcat:10.0-jre$jdk_version"}" - build_main_image create_additional_manifests diff --git a/jenkinsfiles/rebuild-image b/jenkinsfiles/rebuild-image index a09f27b29382..4e28f976c6bc 100644 --- a/jenkinsfiles/rebuild-image +++ b/jenkinsfiles/rebuild-image @@ -20,7 +20,7 @@ pipeline { stage('Rebuild Docker images') { environment { OLD_VERSION_SCHEMA_PREFIX = '2' - SUPPORTED_VERSIONS_JSON = sh(returnStdout: true, script: 'curl -fsSL "https://raw.githubusercontent.com/dhis2/dhis2-releases/master/downloads/v1/versions/stable.json" | jq -r \'.versions[] | select(.supported == true)\'').trim() + SUPPORTED_VERSIONS_JSON = sh(returnStdout: true, script: 'curl -fsSL "https://releases.dhis2.org/v1/versions/stable.json" | jq -r \'.versions[] | select(.supported == true)\'').trim() } steps { @@ -38,16 +38,37 @@ pipeline { // We don't have 2.M.m.p tags with 0 patch version in the dhis2-core git repo, // hence we have to use the version "name" from the stable.json as the matching git tag. env.VERSIONS_TO_REBUILD.tokenize(" ").each { version -> + def majorVersion = version.split('\\.')[0].toInteger() + if (majorVersion >= 42) { + env.BASE_IMAGE = "tomcat:10.0-jre17" + } else if (majorVersion == 41) { + env.BASE_IMAGE = "tomcat:9.0-jre17" + } else { + env.BASE_IMAGE = "tomcat:9.0-jre11" + } + sh """#!/bin/bash export VERSION_NAME=\$(jq -r '.patchVersions[] | select(.displayName == \"$version\") .name' <<< \$SUPPORTED_VERSIONS_JSON) export DHIS2_VERSION=\$VERSION_NAME + export DHIS2_DB_DUMP_URL="https://databases.dhis2.org/sierra-leone/\$DHIS2_VERSION/dhis2-db-sierra-leone.sql.gz" + export DHIS2_IMAGE="dhis2/core:\$DHIS2_VERSION" export GIT_BRANCH=\$DHIS2_VERSION export GIT_COMMIT=\$(git rev-parse \$VERSION_NAME) echo "DHIS2 version is \$DHIS2_VERSION" echo "Git commit is \$GIT_COMMIT" ./dhis-2/build-docker-image.sh -t \"$version\" -r + + docker compose up -d """ + + catchError(message: "DHIS2 version ${version} didn't respond with 200", buildResult: 'FAILURE', stageResult: 'FAILURE') { + timeout(5) { + waitFor.statusOk("localhost:8080") + } + } + + sh 'docker compose down --remove-orphans --volumes' } } }