Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0.x] NO-ISSUE: Kogito Images release deploy job fixes #1799

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions .ci/jenkins/Jenkinsfile.build-image
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,23 @@ pipeline {

if (getMavenArtifactRepository()) {
echo "Setup Repository url to '${getMavenArtifactRepository()}'"
runPythonCommand("python scripts/update-repository.py --repo-url ${getMavenArtifactRepository()}")
runPythonCommand("python scripts/update-repository.py --repo-urls ${getMavenArtifactRepository()}")
}
}
}
}

stage('Update kogito version') {
stage('Update project version') {
when {
expression { params.UPDATE_KOGITO_VERSION != '' }
}
steps {
script {
runPythonCommand("python scripts/manage-kogito-version.py --bump-to ${params.UPDATE_KOGITO_VERSION} --confirm")
versionCmd = "python scripts/manage-kogito-version.py --bump-to ${params.UPDATE_KOGITO_VERSION} --confirm"
if (isRelease()) {
versionCmd += " --examples-ref ${getSourceBranch()}"
}
sh versionCmd
}
}
}
Expand Down Expand Up @@ -128,7 +132,7 @@ pipeline {

int freePort = cloud.findFreePort()
env.localRegistryUrl = cloud.startLocalRegistry(freePort)
cloud.prepareForDockerMultiplatformBuild([env.localRegistryUrl],[cloud.getDockerIOMirrorRegistryConfig()], false)
cloud.prepareForDockerMultiplatformBuild([env.localRegistryUrl], [cloud.getDockerIOMirrorRegistryConfig()], false)

// Generate the Dockerfile
runPythonCommand("make build-image ${getMakeBuildImageArgs()} image_name=${getBuildImageName()} ignore_test=true ignore_tag=true build_options='--dry-run'")
Expand Down Expand Up @@ -184,7 +188,7 @@ pipeline {
script {
updateGithubCommitStatus('PENDING', 'Tests in progress')

String testImageTag = "docker.io/apache/incubator-kie-${getBuildImageName()}:${getImageVersion()}"
String testImageTag = "${getDeployImageRegistry()}/${getDeployImageNamespace()}/incubator-kie-${getBuildImageName()}:${getImageVersion()}"
String builtImageTag = getBuiltImageTag()
// Pull and tag to test image
sh """
Expand All @@ -208,11 +212,12 @@ pipeline {
}
steps {
script {
def resultingFileName = "incubator-kie-${getImageArtifactReleaseVersion()}-${getBuildImageName()}-image.tar.gz"
def signatureFileName = "${resultingFileName}.asc"
String resultingFileName = "incubator-kie-${getImageArtifactReleaseVersion()}-${getBuildImageName()}-image.tar.gz"
String signatureFileName = "${resultingFileName}.asc"
sh """
docker pull ${getBuiltImageTag()}
docker save ${getBuiltImageTag()} | gzip > ${resultingFileName}
docker tag ${getBuiltImageTag()} ${getBuiltDeployImageTag()}
docker save ${getBuiltDeployImageTag()} | gzip > ${resultingFileName}
"""
releaseUtils.gpgImportKeyFromStringWithoutPassword(getReleaseGpgSignKeyCredsId())
releaseUtils.gpgSignFileDetachedSignatureWithoutPassword(resultingFileName, signatureFileName)
Expand Down Expand Up @@ -269,9 +274,13 @@ String getImageVersion() {
return runPythonCommand('make display-image-version', true).trim()
}

String getBuiltDeployImageTag(String imageTag = '') {
return "${getDeployImageRegistry()}/${getDeployImageNamespace()}/${getFinalImageName()}:${imageTag ?: getDeployImageTag()}"
}

String getBuiltImageTag(String imageTag = '') {
if (shouldDeployImage()) {
return "${getDeployImageRegistry()}/${getDeployImageNamespace()}/${getFinalImageName()}:${imageTag ?: getDeployImageTag()}"
return getBuiltDeployImageTag(imageTag)
}
return "${env.localRegistryUrl}/${getBuildImageName()}:${githubscm.getCommitHash()}"
}
Expand Down Expand Up @@ -316,7 +325,7 @@ String getDeployImageTag() {
}

String getFinalImageName() {
return "incubator-kie-" + getBuildImageName() + (getDeployImageNameSuffix() ? "-${getDeployImageNameSuffix()}" : '')
return 'incubator-kie-' + getBuildImageName() + (getDeployImageNameSuffix() ? "-${getDeployImageNameSuffix()}" : '')
}

boolean isDeployLatestTag() {
Expand Down Expand Up @@ -440,7 +449,7 @@ String getTriggeringProjectName() {
if (currentBuild.upstreamBuilds) {
return currentBuild.upstreamBuilds[0].projectName
}
return ""
return ''
}
String getReleaseGpgSignKeyCredsId() {
return env.RELEASE_GPG_SIGN_KEY_CREDS_ID
Expand All @@ -461,3 +470,7 @@ String getReleaseSvnCredsId() {
String getImageArtifactReleaseVersion() {
return params.IMAGE_ARTIFACT_RELEASE_VERSION
}

boolean isRelease() {
return env.RELEASE ? env.RELEASE.toBoolean() : false
}
30 changes: 23 additions & 7 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST_FAILED_IMAGES = Collections.synchronizedList([])

pipeline {
agent {
docker {
docker {
image env.AGENT_DOCKER_BUILDER_IMAGE
args env.AGENT_DOCKER_BUILDER_ARGS
label util.avoidFaultyNodes()
Expand Down Expand Up @@ -99,14 +99,12 @@ pipeline {
dir(getRepoName()) {
versionCmd = "python scripts/manage-kogito-version.py --bump-to ${getProjectVersion()} --confirm"
if (getBuildBranch() != 'main') {
versionCmd += " --examples-ref ${!isRelease() ? 'nightly-' : ''}${getBuildBranch()}"
versionCmd += " --examples-ref ${getBuildBranch()}"
}
if (getKogitoArtifactsVersion()) {
versionCmd += " --artifacts-version ${getKogitoArtifactsVersion()}"
}
sh versionCmd

commitAndTagChanges("[${getBuildBranch()}] Update version to ${getProjectVersion()}")
}
}
}
Expand Down Expand Up @@ -154,6 +152,22 @@ pipeline {
}
}
}

stage('Commit and Tag changes') {
when {
expression { return isRelease() }
}
steps {
script {
if (!getBuildFailedImages()) {
dir(getRepoName()) {
commitAndTagChanges("[${getBuildBranch()}] Update version to ${getProjectVersion()}")
}
}
}
}
}

stage('Finalize') {
steps {
script {
Expand Down Expand Up @@ -217,16 +231,18 @@ void createBuildAndTestStageClosure(String image) {
List buildParams = []
buildParams.add(string(name: 'DISPLAY_NAME', value: "${params.DISPLAY_NAME} - ${image}"))
buildParams.add(string(name: 'BUILD_IMAGE_NAME', value: image))
buildParams.add(string(name: 'SOURCE_AUTHOR', value: isRelease() ? getGitAuthor() : getGitAuthor()))
buildParams.add(string(name: 'SOURCE_BRANCH', value: isRelease() ? getPRBranch() : getBuildBranch()))
buildParams.add(string(name: 'SOURCE_AUTHOR', value: getGitAuthor()))
buildParams.add(string(name: 'SOURCE_BRANCH', value: getBuildBranch()))

buildParams.add(string(name: 'MAVEN_ARTIFACTS_REPOSITORY', value: env.MAVEN_ARTIFACT_REPOSITORY ?: (isRelease() ? env.DEFAULT_STAGING_REPOSITORY : '')))
buildParams.add(string(name: 'MAVEN_ARTIFACTS_REPOSITORY', value: env.MAVEN_ARTIFACT_REPOSITORY))
buildParams.add(string(name: 'BUILD_KOGITO_APPS_URI', value: params.APPS_URI))
buildParams.add(string(name: 'BUILD_KOGITO_APPS_REF', value: params.APPS_REF))
buildParams.add(booleanParam(name: 'SKIP_TESTS', value: params.SKIP_TESTS))
buildParams.add(string(name: 'TESTS_KOGITO_EXAMPLES_URI', value: params.EXAMPLES_URI))
buildParams.add(string(name: 'TESTS_KOGITO_EXAMPLES_REF', value: params.EXAMPLES_REF))

buildParams.add(string(name: 'UPDATE_KOGITO_VERSION', value: isRelease() ? getProjectVersion() : ''))

buildParams.add(booleanParam(name: 'DEPLOY_IMAGE', value: isDeployImage()))
buildParams.add(booleanParam(name: 'DEPLOY_IMAGE_USE_OPENSHIFT_REGISTRY', value: isDeployImageInOpenshiftRegistry()))
buildParams.add(string(name: 'DEPLOY_IMAGE_REGISTRY_USER_CREDENTIALS_ID', value: getDeployImageRegistryUserCredentialsId()))
Expand Down
4 changes: 2 additions & 2 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ void setupBuildImageJob(JobType jobType) {

RELEASE_GPG_SIGN_KEY_CREDS_ID: Utils.getReleaseGpgSignKeyCredentialsId(this),
RELEASE_GPG_SIGN_PASSPHRASE_CREDS_ID: Utils.getReleaseGpgSignPassphraseCredentialsId(this),
RELEASE_SVN_REPOSITORY: Utils.getReleaseSvnCredentialsId(this),
RELEASE_SVN_CREDS_ID: Utils.getReleaseSvnStagingRepository(this)
RELEASE_SVN_REPOSITORY: Utils.getReleaseSvnStagingRepository(this),
RELEASE_SVN_CREDS_ID: Utils.getReleaseSvnCredentialsId(this)
])
KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
logRotator {
Expand Down
13 changes: 13 additions & 0 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,19 @@ def update_maven_repo_in_setup_maven(repo_url, replace_default_repository):
replacement = 'export MAVEN_REPO_URL="{}"'.format(repo_url)
update_in_file(SETUP_MAVEN_SCRIPT, pattern, replacement)

def update_maven_repos_in_setup_maven(repos_url):
"""
Update maven repositories into setup-maven.sh script
:param repos_url: Maven repositories urls
"""
repo_list = repos_url.split(',')
print("Set maven repos {} in setup-maven script".format(repo_list))
pattern = re.compile(r'(# export MAVEN_REPO_URL=.*)')
replacement = f"export MAVEN_REPOS={','.join(['REPO_' + str(i) for i, _ in enumerate(repo_list)])}\n"
for i, value in enumerate(repo_list):
replacement += f"export REPO_{i}_MAVEN_REPO_URL={value}\n"
update_in_file(SETUP_MAVEN_SCRIPT, pattern, replacement)

def update_env_value(env_name, env_value):
"""
Update environment value into the given yaml module/image file
Expand Down
4 changes: 4 additions & 0 deletions scripts/update-repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Update Maven information in repo from the given artifact url and '
'version.')
parser.add_argument('--repo-urls', dest='repo_urls', help='Defines the urls of the repositories to setup maven, comma (,) separated')
parser.add_argument('--repo-url', dest='repo_url', help='Defines the url of the repository to setup into the tests')
parser.add_argument('--replace-default-repo', dest='replace_default_repo', default=False, action='store_true',
help='Enable if repo-url should replace the default repository')
Expand All @@ -53,6 +54,9 @@
parser.add_argument('--tests-only', dest='tests_only', default=False, action='store_true', help='Update product modules/images')
args = parser.parse_args()

if args.repo_urls:
common.update_maven_repos_in_setup_maven(args.repo_urls)

if args.repo_url:
common.update_maven_repo_in_build_config(args.repo_url, args.replace_default_repo)
common.update_maven_repo_in_setup_maven(args.repo_url, args.replace_default_repo)
Expand Down
Loading