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#1213: configure for dockerhub registry #3087

Merged
merged 4 commits into from
Jun 26, 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
10 changes: 4 additions & 6 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,8 @@ void pushOperatorFinalImage() {
}

void removeOperatorImageTemporaryTag() {
if (!imageUtils.removeQuayTag(getOperatorImageNamespace(), getOperatorImageName(), getOperatorImageTemporaryTag())) {
String temporaryImageName = imageUtils.getImageFullName(getOperatorImageNamespace(), getOperatorImageName(),
getOperatorImageTemporaryTag())
error "Cannot remove the OptaPlanner Operator temporary image tag (${temporaryImageName}) from quay.io. "
+ "The tag should be removed manually."
}
String temporaryImageName = imageUtils.getImageFullName(getOperatorImageNamespace(), getOperatorImageName(),
getOperatorImageTemporaryTag())
// https://docs.docker.com/docker-hub/api/latest/#tag/repositories
error "Dockerhub API does not allow deleting tags via API. The OptaPlanner Operator temporary image tag (${temporaryImageName}) should be removed manually."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigonull maybe it's this line the CI is complaining about?

org.spockframework.runtime.UnallowedExceptionThrownError at JobScriptsSpec.groovy:97

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can use throw? https://www.jenkins.io/doc/book/pipeline/syntax/#flow-control

I'm not sure, I'm not a Jenkins SME just brainstorming. :)

}
9 changes: 5 additions & 4 deletions .ci/jenkins/config/branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,17 @@ maven:
creds_id: apache-nexus-kie-deploy-credentials
cloud:
image:
registry_credentials: tradisso_registry_token # TODO set to `kogito-quay-token`
registry: quay.io
namespace: tradisso
registry_user_credentials_id: DOCKERHUB_USER
registry_token_credentials_id: DOCKERHUB_TOKEN
registry: docker.io
namespace: apache
latest_git_branch: main
jenkins:
email_creds_id: OPTAPLANNER_CI_NOTIFICATION_EMAILS
agent:
docker:
builder:
image: quay.io/kiegroup/kogito-ci-build:main-latest
image: docker.io/apache/incubator-kie-kogito-ci-build:main-latest
args: --privileged --group-add docker
default_tools:
jdk: jdk_17_latest
Expand Down
6 changes: 4 additions & 2 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ void setupDeployJob(JobType jobType, String envName = '') {
stringParam('QUICKSTARTS_BUILD_BRANCH_NAME', Utils.isMainBranch(this) ? 'development' : "${GIT_BRANCH}", 'Base branch for quickstarts. Set if you are not on a multibranch pipeline.')

stringParam('OPERATOR_IMAGE_REGISTRY', "${CLOUD_IMAGE_REGISTRY}", 'Image registry to use to deploy images.')
stringParam('OPERATOR_IMAGE_REGISTRY_CREDENTIALS', "${CLOUD_IMAGE_REGISTRY_CREDENTIALS}", 'Image registry credentials.')
stringParam('OPERATOR_IMAGE_REGISTRY_USER_CREDENTIALS_ID', "${CLOUD_IMAGE_REGISTRY_USER_CREDENTIALS_ID}", 'Image registry user credentials id.')
stringParam('OPERATOR_IMAGE_REGISTRY_TOKEN_CREDENTIALS_ID', "${CLOUD_IMAGE_REGISTRY_TOKEN_CREDENTIALS_ID}", 'Image registry token credentials id.')
stringParam('OPERATOR_IMAGE_NAMESPACE', "${CLOUD_IMAGE_NAMESPACE}", 'Operator image namespace to use to deploy image.')
stringParam('OPERATOR_IMAGE_TAG', '', 'Image tag to use to deploy the operator image. OptaPlanner project version if not set.')
}
Expand Down Expand Up @@ -393,7 +394,8 @@ void setupPromoteJob(JobType jobType) {
booleanParam('SEND_NOTIFICATION', false, 'In case you want the pipeline to send a notification on CI channel for this run.')

stringParam('OPERATOR_IMAGE_REGISTRY', "${CLOUD_IMAGE_REGISTRY}", 'Image registry to use to deploy images.')
stringParam('OPERATOR_IMAGE_REGISTRY_CREDENTIALS', "${CLOUD_IMAGE_REGISTRY_CREDENTIALS}", 'Image registry credentials.')
stringParam('OPERATOR_IMAGE_REGISTRY_USER_CREDENTIALS_ID', "${CLOUD_IMAGE_REGISTRY_USER_CREDENTIALS_ID}", 'Image registry user credentials id.')
stringParam('OPERATOR_IMAGE_REGISTRY_TOKEN_CREDENTIALS_ID', "${CLOUD_IMAGE_REGISTRY_TOKEN_CREDENTIALS_ID}", 'Image registry token credentials id.')
stringParam('OPERATOR_IMAGE_NAMESPACE', "${CLOUD_IMAGE_NAMESPACE}", 'Operator image namespace to use to deploy image.')
}
}
Expand Down
38 changes: 14 additions & 24 deletions .ci/jenkins/scripts/imageUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ containerEngine = 'docker'
containerTlsOptions = ''

void loginRegistry() {
loginContainerRegistry(getOperatorImageRegistry(), getOperatorImageRegistryCredentials())
loginContainerRegistry(getOperatorImageRegistry(), getOperatorImageRegistryUserCredentialsId(), getOperatorImageRegistryTokenCredentialsId())
}

void loginContainerRegistry(String registry, String credsId) {
echo "Using credentials ($credsId) to login to registry ($registry)"
withCredentials([usernamePassword(credentialsId: credsId, usernameVariable: 'REGISTRY_USER', passwordVariable: 'REGISTRY_PWD')]) {
sh "${containerEngine} login ${containerTlsOptions} -u ${REGISTRY_USER} -p ${REGISTRY_PWD} ${registry}"
void loginContainerRegistry(String registry, String userCredsId, String tokenCredsId) {
withCredentials([string(credentialsId: userCredsId, variable: 'REGISTRY_USER')]) {
withCredentials([string(credentialsId: tokenCredsId, variable: 'REGISTRY_TOKEN')]) {
sh """
echo "${REGISTRY_TOKEN}" | ${containerEngine} login -u "${REGISTRY_USER}" --password-stdin ${registry}
""".trim()
}
}
}

String getOperatorImageRegistryCredentials() {
return params.OPERATOR_IMAGE_REGISTRY_CREDENTIALS
String getOperatorImageRegistryUserCredentialsId() {
return params.OPERATOR_IMAGE_REGISTRY_USER_CREDENTIALS_ID
}

String getOperatorImageRegistryTokenCredentialsId() {
return params.OPERATOR_IMAGE_REGISTRY_TOKEN_CREDENTIALS_ID
}

String getOperatorImageRegistry() {
Expand Down Expand Up @@ -64,21 +71,4 @@ void pushImage(String image) {
}
}

boolean removeQuayTag(String namespace, String imageName, String tag) {
String image = "quay.io/${namespace}/${imageName}:${tag}"
echo "Removing a temporary image tag ${image}"
try {
def output = 'false'
withCredentials([usernamePassword(credentialsId: getOperatorImageRegistryCredentials(), usernameVariable: 'QUAY_USER', passwordVariable: 'QUAY_TOKEN')]) {
output = sh(returnStdout: true, script: "curl -H 'Content-Type: application/json' -H 'Authorization: Bearer ${QUAY_TOKEN}' -X DELETE https://quay.io/api/v1/repository/${namespace}/${imageName}/tag/${tag}").trim()
if (output != '') {
echo "$output"
}
}
return output == ''
} catch (err) {
echo "[ERROR] Cannot remove a temporary image tag ${image}."
}
}

return this
Loading