Skip to content

Commit

Permalink
ci: set base image in rebuild pipeline, not script [skip ci] (#18832)
Browse files Browse the repository at this point in the history
Signed-off-by: Rado <[email protected]>
  • Loading branch information
radnov authored Oct 22, 2024
1 parent d2d5028 commit 3edb93a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
7 changes: 1 addition & 6 deletions dhis-2/build-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion jenkinsfiles/rebuild-image
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
}
}
}
Expand Down

0 comments on commit 3edb93a

Please sign in to comment.