Skip to content

Commit

Permalink
KOGITO-9681 CI: Use cloud shared libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste committed Aug 7, 2023
1 parent 2775085 commit 022a054
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 157 deletions.
32 changes: 12 additions & 20 deletions .ci/jenkins/Jenkinsfile.build-image
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ pipeline {
CONTAINER_ENGINE = 'docker'
CONTAINER_ENGINE_TLS_OPTIONS = ''

OPENSHIFT_API = credentials('OPENSHIFT_API')
OPENSHIFT_REGISTRY = credentials('OPENSHIFT_REGISTRY')
OPENSHIFT_CREDS_KEY = 'OPENSHIFT_CREDS'

IMAGE_BUILD_PLATFORMS = 'linux/amd64,linux/arm64'
}
stages {
Expand Down Expand Up @@ -55,13 +51,8 @@ pipeline {
}

// Login to final registry if deploy is needed
if (shouldDeployImage()) {
if (isDeployImageInOpenshiftRegistry()) {
cloud.loginOpenShift(env.OPENSHIFT_API, env.OPENSHIFT_CREDS_KEY)
cloud.loginOpenshiftRegistry(env.CONTAINER_ENGINE, env.CONTAINER_ENGINE_TLS_OPTIONS ?: '')
} else if (getDeployImageRegistryCredentials()) {
cloud.loginContainerRegistry(getDeployImageRegistry(), getDeployImageRegistryCredentials(), env.CONTAINER_ENGINE, env.CONTAINER_ENGINE_TLS_OPTIONS ?: '')
}
if (shouldDeployImage() && getDeployImageRegistryCredentials()) {
getContainerEngineService().loginContainerRegistry(getDeployImageRegistry(), getDeployImageRegistryCredentials())
}
}
}
Expand Down Expand Up @@ -107,7 +98,7 @@ pipeline {
script {
updateGithubCommitStatus('PENDING', 'Build in progress')

String localRegistry = cloud.startLocalRegistry()
String localRegistry = getContainerEngineService().startLocalRegistry()
cloud.prepareForDockerMultiplatformBuild([localRegistry],[cloud.getDockerIOMirrorRegistryConfig()], false)

// Generate the Dockerfile
Expand Down Expand Up @@ -214,11 +205,16 @@ pipeline {
}
}

ContainerEngineService getContainerEngineService() {
return new ContainerEngineService(this)
}

void clean() {
util.cleanNode(env.CONTAINER_ENGINE)
util.cleanNode()
getContainerEngineService().clean()
getContainerEngineService().cleanLocalRegistry()

cloud.cleanDockerMultiplatformBuild()
cloud.cleanLocalRegistry()
cloud.cleanSkopeo()

// Clean Cekit cache, in case we reuse an old node
Expand Down Expand Up @@ -260,20 +256,16 @@ void runPythonCommand(String cmd, boolean stdout = false) {
// Deploy image information
////////////////////////////////////////////////////////////////////////

boolean isDeployImageInOpenshiftRegistry() {
return params.DEPLOY_IMAGE_USE_OPENSHIFT_REGISTRY
}

String getDeployImageRegistryCredentials() {
return params.DEPLOY_IMAGE_REGISTRY_CREDENTIALS
}

String getDeployImageRegistry() {
return isDeployImageInOpenshiftRegistry() ? env.OPENSHIFT_REGISTRY : params.DEPLOY_IMAGE_REGISTRY
return params.DEPLOY_IMAGE_REGISTRY
}

String getDeployImageNamespace() {
return isDeployImageInOpenshiftRegistry() ? 'openshift' : params.DEPLOY_IMAGE_NAMESPACE
return params.DEPLOY_IMAGE_NAMESPACE
}

String getDeployImageNameSuffix() {
Expand Down
10 changes: 2 additions & 8 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ pipeline {
KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}")

PR_BRANCH_HASH = "${util.generateHash(10)}"

OPENSHIFT_REGISTRY = credentials('OPENSHIFT_REGISTRY')
}

stages {
Expand Down Expand Up @@ -282,7 +280,6 @@ void createBuildAndTestStageClosure(String image) {
buildParams.add(string(name: 'TESTS_KOGITO_EXAMPLES_REF', value: params.EXAMPLES_REF))

buildParams.add(booleanParam(name: 'DEPLOY_IMAGE', value: true))
buildParams.add(booleanParam(name: 'DEPLOY_IMAGE_USE_OPENSHIFT_REGISTRY', value: isDeployImageInOpenshiftRegistry()))
buildParams.add(string(name: 'DEPLOY_IMAGE_REGISTRY_CREDENTIALS', value: getDeployImageRegistryCredentials()))
buildParams.add(string(name: 'DEPLOY_IMAGE_REGISTRY', value: getDeployImageRegistry()))
buildParams.add(string(name: 'DEPLOY_IMAGE_NAMESPACE', value: getDeployImageNamespace()))
Expand Down Expand Up @@ -341,19 +338,16 @@ List getTestFailedImages() {
// Deploy image information
////////////////////////////////////////////////////////////////////////

boolean isDeployImageInOpenshiftRegistry() {
return params.IMAGE_USE_OPENSHIFT_REGISTRY
}

String getDeployImageRegistryCredentials() {
return params.IMAGE_REGISTRY_CREDENTIALS
}

String getDeployImageRegistry() {
return isDeployImageInOpenshiftRegistry() ? env.OPENSHIFT_REGISTRY : params.IMAGE_REGISTRY
return params.IMAGE_REGISTRY
}
String getDeployImageNamespace() {
return isDeployImageInOpenshiftRegistry() ? 'openshift' : params.IMAGE_NAMESPACE
return params.IMAGE_NAMESPACE
}
String getDeployImageNameSuffix() {
return params.IMAGE_NAME_SUFFIX
Expand Down
Loading

0 comments on commit 022a054

Please sign in to comment.