Skip to content

Commit

Permalink
kie-issues#1213: configure for dockerhub registry (#3087)
Browse files Browse the repository at this point in the history
* kie-issues#1213: configure for dockerhub registry

* Update .ci/jenkins/config/branch.yaml

Co-authored-by: Rodrigo Antunes <[email protected]>

* Use the new dockerhub credentials

* Remove quay.io references

---------

Co-authored-by: jstastny-cz <[email protected]>
Co-authored-by: Rodrigo Antunes <[email protected]>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent f604b5e commit f8b82da
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 36 deletions.
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."
}
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 @@ -363,7 +363,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 @@ -406,7 +407,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

0 comments on commit f8b82da

Please sign in to comment.