From 32652c04e2b54ce3d7c08e0d3abecdd6ed46421a Mon Sep 17 00:00:00 2001 From: Roberto Oliveira Date: Fri, 19 Jul 2024 10:59:31 -0400 Subject: [PATCH] [SRVLOGIC-286] add Operator image as part of OSL productized nightly --- .ci/jenkins/Jenkinsfile.prod.nightly | 56 ++++++++++++++++++++++++++- .ci/nightly-build-config.yaml | 7 +++- .ci/nightly-project-dependencies.yaml | 4 ++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile.prod.nightly b/.ci/jenkins/Jenkinsfile.prod.nightly index 733de23b5..2265a0250 100644 --- a/.ci/jenkins/Jenkinsfile.prod.nightly +++ b/.ci/jenkins/Jenkinsfile.prod.nightly @@ -99,6 +99,7 @@ pipeline { env.ARTIFACTS_VERSION = "${env.PRODUCT_VERSION}.redhat-${env.DATE_TIME_SUFFIX}" env.M2_FOLDER = '/home/jenkins/.m2/repository' env.IMAGES_REPOSITORY_PATH = "${env.WORKSPACE}/bc/kiegroup_kogito-images" + env.OPERATOR_REPOSITORY_PATH = "${env.WORKSPACE}/bc/kiegroup_kogito-serverless-operator" env.SLEEP_TIME = '30' // required as cekit-cache command fails if many invocations at the same time // Images names @@ -108,6 +109,7 @@ pipeline { env.JOBS_SERVICE_POSTGRESQL = 'jobs-service-postgresql' env.SWF_BUILDER = 'swf-builder' env.SWF_DEVMODE = 'swf-devmode' + env.OPERATOR = 'operator' // Images registries placeholders env.DATA_INDEX_EPHEMERAL_REGISTRY = '' @@ -116,6 +118,7 @@ pipeline { env.JOBS_SERVICE_POSTGRESQL_REGISTRY = '' env.SWF_BUILDER_REGISTRY = '' env.SWF_DEVMODE_REGISTRY = '' + env.OPERATOR_REGISTRY = '' } } } @@ -206,6 +209,17 @@ pipeline { } } } + stage('Operator image') { + steps { + script { + sleep(Integer.parseInt(env.SLEEP_TIME) * 6) + + def descriptorFile = 'images/prod-operator-image.yaml' + env.OPERATOR_REGISTRY = buildOperator(descriptorFile, env.NIGHTLY_BRANCH_NAME, env.OPERATOR_REPOSITORY_PATH) + } + } + } + } } stage('Upload maven repository') { @@ -244,7 +258,9 @@ pipeline { def sanitizedProjectName = f.replaceAll('/', '_').replaceAll('-', '_') def buildScript = env["PME_BUILD_SCRIPT_${sanitizedProjectName}"] def pomPath = maven.getProjectPomFromBuildCmd(buildScript) - env["VERSION_${f}"] = maven.mvnGetVersionProperty(new MavenCommand(this).withProperty('productized'), 'project.version', pomPath) + if (new File(pomPath).exists()) { + env["VERSION_${f}"] = maven.mvnGetVersionProperty(new MavenCommand(this).withProperty('productized'), 'project.version', pomPath) + } } } @@ -265,7 +281,7 @@ pipeline { env.ALREADY_BUILT_PROJECTS, ['serverlesslogic': env['VERSION_kiegroup_kogito-runtimes'], 'serverlesslogic-rhba': env['VERSION_kiegroup_kogito-runtimes'], 'drools': env.VERSION_kiegroup_drools, 'platform.quarkus.bom': env.QUARKUS_PLATFORM_VERSION, 'quarkus.bom': env.QUARKUS_VERSION], ["${env.DATA_INDEX_EPHEMERAL}": env.DATA_INDEX_EPHEMERAL_REGISTRY, "${env.DATA_INDEX_POSTGRESQL}": env.DATA_INDEX_POSTGRESQL_REGISTRY, "${env.JOBS_SERVICE_EPHEMERAL}": env.JOBS_SERVICE_EPHEMERAL_REGISTRY, "${JOBS_SERVICE_POSTGRESQL}": env.JOBS_SERVICE_POSTGRESQL_REGISTRY, - "${env.SWF_BUILDER}": env.SWF_BUILDER_REGISTRY, "${env.SWF_DEVMODE}": env.SWF_DEVMODE_REGISTRY], + "${env.SWF_BUILDER}": env.SWF_BUILDER_REGISTRY, "${env.SWF_DEVMODE}": env.SWF_DEVMODE_REGISTRY, "${env.OPERATOR}": env.OPERATOR_REGISTRY], gitHashesToCollection(env.GIT_INFORMATION_HASHES) ) echo "[INFO] Message Body: ${messageBody}" @@ -310,6 +326,42 @@ pipeline { } } +def buildOperator(String descriptorFile, String nightlyBranchName, String operatorRepository) { + // Create a different folder for operator, otherwise dir() will mess up with folders and impact other steps of pipeline + sh "cp -rp ${operatorRepository} ${env.WORKSPACE}/operator_repo" + dir("${env.WORKSPACE}/operator_repo") { + println "Building operator" + + // Remove go work files due to cachito limitation and push changes to a temporary prod branch + def prodBranch = "main-prod-nightly" + if (githubscm.isBranchExist("origin", prodBranch)) { + githubscm.removeRemoteBranch("origin", prodBranch) + } + githubscm.createBranch(prodBranch) + sh "rm -f go.work go.work.sum" + githubscm.commitChanges("remove go work files due to cachito limitation") + githubscm.pushObject("origin", prodBranch) + + // Replace branch and ref in descriptor file + sh """sed -i "s/branch:.*/branch: ${nightlyBranchName}/g" ${descriptorFile}""" + def reference = githubscm.getCommitHash() + sh """sed -i "s/ref:.*/ref: ${reference}/g" ${descriptorFile}""" + println "Diff of ${descriptorFile} after replacing branch name and ref" + sh "git diff ${descriptorFile}" + + println 'Using cekit version' + util.runWithPythonVirtualEnv('cekit --version', 'cekit') + + util.withKerberos('rhba-osbs-builder-keytab') { + def cekitBuildCmd = "cekit --redhat --descriptor ${descriptorFile} build osbs --user rhba-osbs-builder -y" + util.runWithPythonVirtualEnv("${cekitBuildCmd} | tee operator-build-log.txt", 'cekit') + } + + def imageRegistry = sh(script: "brew call --json-output getTaskResult \$(cat operator-build-log.txt | grep -oP '(?<=Task ).*(?= was)') | jq -nre 'input.repositories[0]'", returnStdout: true) + return imageRegistry.trim() + } +} + def buildImage(String imageName, String descriptorFile, String nightlyBranchName, Map artifacts, String imagesRepository) { // Create a different folder for each image during the build, otherwise dir() will mess up the builds during parallel run sh "cp -rp ${imagesRepository} ${env.WORKSPACE}/${imageName}_repo" diff --git a/.ci/nightly-build-config.yaml b/.ci/nightly-build-config.yaml index 8ca503ea2..997817dbe 100644 --- a/.ci/nightly-build-config.yaml +++ b/.ci/nightly-build-config.yaml @@ -60,4 +60,9 @@ build: export NIGHTLY_DEPLOY_FOLDER="${{ env.WORKSPACE }}/deployDirectory" echo "NIGHTLY_DEPLOY_FOLDER=${{ env.NIGHTLY_DEPLOY_FOLDER }}" ${{ env.PME_CMD }} ${{ env.PME_ALIGNMENT_PARAMS_kiegroup_kogito_images }} - bash -c "set -o pipefail ; ${{ env.PME_BUILD_SCRIPT_kiegroup_kogito_images }} ${{ env.BUILD_MVN_OPTS }} | tee ${{ env.WORKSPACE }}/kogito_images.maven.log" \ No newline at end of file + bash -c "set -o pipefail ; ${{ env.PME_BUILD_SCRIPT_kiegroup_kogito_images }} ${{ env.BUILD_MVN_OPTS }} | tee ${{ env.WORKSPACE }}/kogito_images.maven.log" + + - project: kiegroup/kogito-serverless-operator + build-command: + downstream: | + echo "Cloned operator repository for building Operator image" diff --git a/.ci/nightly-project-dependencies.yaml b/.ci/nightly-project-dependencies.yaml index 1cf197de2..0789b9fcb 100644 --- a/.ci/nightly-project-dependencies.yaml +++ b/.ci/nightly-project-dependencies.yaml @@ -23,3 +23,7 @@ dependencies: - project: kiegroup/kogito-images dependencies: - project: kiegroup/kie-tools + + - project: kiegroup/kogito-serverless-operator + dependencies: + - project: kiegroup/kogito-images \ No newline at end of file