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

kie-issues#755: Fix kogito operator nightly deploy pipelines #323

Merged
merged 15 commits into from
Jan 9, 2024
Merged
22 changes: 10 additions & 12 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ helper = null

commitDone = false

def localRegistryUrl = '';

pipeline {
agent {
docker {
Expand All @@ -25,6 +23,8 @@ pipeline {
PR_BRANCH_HASH = "${util.generateHash(10)}"

IMAGE_BUILD_PLATFORMS = 'linux/amd64,linux/arm64'

CONTAINER_ENGINE = 'docker'
}

stages {
Expand Down Expand Up @@ -55,11 +55,10 @@ pipeline {

// Prepare for multiplatform build
int freePort = cloud.findFreePort()
localRegistryUrl = cloud.startLocalRegistry(freePort)
env.localRegistryUrl = cloud.startLocalRegistry(freePort)

// TODO docker buildx could be preinstalled onto the docker image
cloud.prepareForDockerMultiplatformBuild([localRegistryUrl],[cloud.getDockerIOMirrorRegistryConfig()], false)
cloud.installSkopeo()
cloud.prepareForDockerMultiplatformBuild([env.localRegistryUrl],[cloud.getDockerIOMirrorRegistryConfig()], false)
}
}
post {
Expand All @@ -81,7 +80,7 @@ pipeline {
steps {
script {
if (githubscm.isBranchExist('origin', helper.getPRBranch())) {
githubscm.removeRemoteBranch('origin', helper.getPRBranch())
githubscm.removeRemoteBranch('origin', helper.getPRBranch(), helper.getGitAuthorPushCredsId())
}
githubscm.createBranch(helper.getPRBranch())
}
Expand All @@ -96,6 +95,7 @@ pipeline {
script {
runPythonCommand("make bump-version new_version=${helper.getProjectVersion()}")

githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
// Commit changes
githubscm.commitChanges(getCommitMessage(), {
sh '''
Expand Down Expand Up @@ -206,14 +206,14 @@ pipeline {
}
steps {
script {
githubscm.pushObject('origin', helper.getPRBranch(), helper.getGitAuthorCredsID())
githubscm.pushObject('origin', helper.getPRBranch(), helper.getGitAuthorPushCredsId())

def prMsg = getCommitMessage()
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}.\nPlease do not merge, it shoud be merged automatically."
String prLink = githubscm.createPR(prMsg, prBody, helper.getBuildBranch(), helper.getGitAuthorCredsID())
String prLink = githubscm.createPR(prMsg, prBody, helper.getBuildBranch(), helper.getGitAuthorPushCredsId())
properties.add("${helper.getRepoName()}.pr.link", prLink)

properties.add("${helper.getRepoName()}.pr.source.uri", "https://github.com/${helper.getGitAuthorCredsID()}/${helper.getRepoName()}")
properties.add("${helper.getRepoName()}.pr.source.uri", "https://github.com/${helper.getGitAuthor()}/${helper.getRepoName()}")
properties.add("${helper.getRepoName()}.pr.source.ref", helper.getPRBranch())
properties.add("${helper.getRepoName()}.pr.target.uri", "https://github.com/${helper.getGitAuthor()}/${helper.getRepoName()}")
properties.add("${helper.getRepoName()}.pr.target.ref", helper.getBuildBranch())
Expand All @@ -236,8 +236,6 @@ pipeline {
helper.cleanGoPath()
util.cleanNode(env.CONTAINER_ENGINE)
cloud.cleanDockerMultiplatformBuild()
cloud.cleanLocalRegistry()
cloud.cleanSkopeo()
}
}
}
Expand All @@ -264,7 +262,7 @@ String getBuiltImage() {
}

String getTempBuiltImageTag() {
return "${localRegistryUrl}/kogito-serverless-operator:${getOperatorVersion()}"
return "${env.localRegistryUrl}/kogito-serverless-operator:${getOperatorVersion()}"
}

void runPythonCommand(String cmd, boolean stdout = false) {
Expand Down
20 changes: 9 additions & 11 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ pipeline {
// Login old and new registries
helper.loginRegistry(baseImageParamsPrefix)
helper.loginRegistry(promoteImageParamsPrefix)

cloud.installSkopeo()
}
}
}
Expand Down Expand Up @@ -86,8 +84,8 @@ pipeline {
// Merge PR
String prLink = properties.retrieve("${helper.getRepoName()}.pr.link")
if (prLink) {
githubscm.mergePR(prLink, helper.getGitAuthorCredsID())
githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorCredsID())
githubscm.mergePR(prLink, helper.getGitAuthorPushCredsId())
githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorPushCredsId())
}

// Tag api / container-builder
Expand Down Expand Up @@ -117,13 +115,13 @@ pipeline {
steps {
script {
dir(helper.getRepoName()) {
if(githubscm.isReleaseExist(helper.getGitTag(), helper.getGitAuthorCredsID())) {
githubscm.deleteReleaseAndTag(helper.getGitTag(), helper.getGitAuthorCredsID())
if(githubscm.isReleaseExist(helper.getGitTag(), helper.getGitAuthorCredsId())) {
githubscm.deleteReleaseAndTag(helper.getGitTag(), helper.getGitAuthorPushCredsId())
}
githubscm.createReleaseWithGeneratedReleaseNotes(helper.getGitTag(), helper.getBuildBranch(), githubscm.getPreviousTagFromVersion(helper.getProjectVersion(), 'v', '', ['/']), helper.getGitAuthorCredsID())
githubscm.updateReleaseBody(helper.getGitTag(), helper.getGitAuthorCredsID())
githubscm.createReleaseWithGeneratedReleaseNotes(helper.getGitTag(), helper.getBuildBranch(), githubscm.getPreviousTagFromVersion(helper.getProjectVersion(), 'v', '', ['/']), helper.getGitAuthorPushCredsId())
githubscm.updateReleaseBody(helper.getGitTag(), helper.getGitAuthorPushCredsId())

withCredentials([usernamePassword(credentialsId: helper.getGitAuthorCredsID(), usernameVariable: 'GH_USER', passwordVariable: 'GH_TOKEN')]) {
withCredentials([usernamePassword(credentialsId: helper.getGitAuthorPushCredsId(), usernameVariable: 'GH_USER', passwordVariable: 'GH_TOKEN')]) {
sh """
gh release upload ${helper.getGitTag()} "operator.yaml"
"""
Expand All @@ -141,7 +139,6 @@ pipeline {
script {
helper.cleanGoPath()
util.cleanNode(containerEngine)
cloud.cleanSkopeo()
}
}
}
Expand All @@ -168,8 +165,9 @@ void updateInternalGoModuleWithTag(String moduleName, String tagName) {

void commitAndPush(String remote, String commitMsg, Closure preCommit) {
if (githubscm.isThereAnyChanges()) {
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges(commitMsg, preCommit)
githubscm.pushObject(remote, helper.getBuildBranch(), helper.getGitAuthorCredsID())
githubscm.pushObject(remote, helper.getBuildBranch(), helper.getGitAuthorPushCredsId())
} else {
echo "No change... Skipping commit and push"
}
Expand Down
3 changes: 2 additions & 1 deletion .ci/jenkins/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ pipeline {
git checkout -- go.sum
'''
if (githubscm.isThereAnyChanges()) {
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges("[${helper.getBuildBranch()}] Update version to ${helper.getProjectVersion()}", {
sh '''
git add .
'''
})
githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorCredsID())
githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorPushCredsId())
} else {
println '[WARN] no changes to commit'
}
Expand Down
14 changes: 8 additions & 6 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ void createSetupBranchJob() {
JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",

GIT_AUTHOR: "${GIT_AUTHOR_NAME}",
AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",

IS_MAIN_BRANCH: "${Utils.isMainBranch(this)}"
])
Expand All @@ -86,8 +86,8 @@ void setupDeployJob(JobType jobType) {
JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",

GIT_AUTHOR: "${GIT_AUTHOR_NAME}",
AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",

OPERATOR_IMAGE_NAME: 'kogito-serverless-operator',
MAX_REGISTRY_RETRIES: 3,
Expand Down Expand Up @@ -137,8 +137,8 @@ void setupPromoteJob(JobType jobType) {

GIT_AUTHOR: "${GIT_AUTHOR_NAME}",

AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",
])
KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
parameters {
Expand Down Expand Up @@ -182,6 +182,8 @@ void setupE2EJob(JobType jobType, String clusterName, Map extraEnv = [:]) {

GIT_AUTHOR: "${GIT_AUTHOR_NAME}",

GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",

OPERATOR_IMAGE_NAME: 'kogito-serverless-operator',
MAX_REGISTRY_RETRIES: 3,
PROPERTIES_FILE_NAME: 'deployment.properties',
Expand Down
20 changes: 13 additions & 7 deletions .ci/jenkins/scripts/helper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void initPipeline() {
openshift.openshiftApiCredsKey = env.OPENSHIFT_CREDS_KEY

container = load '.ci/jenkins/scripts/container.groovy'
container.containerEngine = env.CONTAINER_ENGINE
container.containerEngine = env.CONTAINER_ENGINE ?: 'docker'
container.containerEngineTlsOptions = env.CONTAINER_ENGINE_TLS_OPTIONS ?: ''
container.containerOpenshift = openshift

Expand Down Expand Up @@ -48,14 +48,16 @@ String getTempTag() {
void checkoutRepo(String repoName = '', String directory = '') {
repoName = repoName ?: getRepoName()
closure = {
deleteDir()
checkout(githubscm.resolveRepository(repoName, getGitAuthor(), getBuildBranch(), false))
checkout(githubscm.resolveRepository(repoName, getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsId()))
// need to manually checkout branch since on a detached branch after checkout command
//sh "git checkout ${getBuildBranch()}"
}

if (directory) {
dir(directory, closure)
dir(directory) {
deleteDir()
closure()
}
} else {
closure()
}
Expand All @@ -70,7 +72,7 @@ void loginRegistry(String paramsPrefix = defaultImageParamsPrefix) {
}

void createTag(String tagName = getGitTag()) {
githubscm.tagLocalAndRemoteRepository('origin', tagName, getGitAuthorCredsID(), '', true)
githubscm.tagLocalAndRemoteRepository('origin', tagName, getGitAuthorPushCredsId(), '', true)
}

// Set images public on quay. Useful when new images are introduced.
Expand Down Expand Up @@ -237,8 +239,12 @@ String getGitAuthor() {
return "${GIT_AUTHOR}"
}

String getGitAuthorCredsID() {
return env.AUTHOR_CREDS_ID
String getGitAuthorCredsId() {
return env.GIT_AUTHOR_CREDS_ID
}

String getGitAuthorPushCredsId() {
return env.GIT_AUTHOR_PUSH_CREDS_ID
}

String getPRBranch() {
Expand Down
4 changes: 2 additions & 2 deletions .ci/jenkins/scripts/minikube.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void preChecks() {
${minikubeContainerEngine} info

if [[ ! \$(command -v minikube) ]]; then
curl -LO https://github.com/kubernetes/minikube/releases/download/v${minikubeVersion}/minikube-${minikubeVersion}-0.x86_64.rpm
sudo yum localinstall -y minikube-${minikubeVersion}-0.x86_64.rpm
sudo ./hack/ci/install-minikube.sh /usr/local/bin
sudo chmod +x /usr/local/bin/minikube
fi
"""
}
Expand Down