fix(pipeline): add registryCredentialsId parameter to ImageBuilder and update related references

Signed-off-by: 孙振宇 <>
This commit is contained in:
孙振宇 2025-02-08 12:07:41 +08:00
parent cf209c4cc3
commit fbf00a1046
3 changed files with 26 additions and 13 deletions

View File

@ -17,7 +17,7 @@ class ImageBuilder {
this.builderType = builderType this.builderType = builderType
} }
def build(name, repository, registry, architectures, version) { def build(name, repository, registry, architectures, version, registryCredentialsId) {
steps.log.info("ImageBuilder", "Building image with ${builderType.builder}") steps.log.info("ImageBuilder", "Building image with ${builderType.builder}")
steps.log.info("ImageBuilder", "Workspace sets to: ${workspace}") steps.log.info("ImageBuilder", "Workspace sets to: ${workspace}")
steps.log.info("ImageBuilder", "Using dockerfile at: ${dockerfile}, context root sets to: ${contextRoot}") steps.log.info("ImageBuilder", "Using dockerfile at: ${dockerfile}, context root sets to: ${contextRoot}")
@ -27,8 +27,26 @@ class ImageBuilder {
architectures = ['linux/amd64'] architectures = ['linux/amd64']
} }
steps.log.info("ImageBuilder", "Login to ${registry}") steps.withCredentials([usernamePassword(credentialsId: registryCredentialsId, passwordVariable: 'DOCKER_PASSWORD', usernameVariable: 'DOCKER_USERNAME')]) {
steps.sh "docker login ${registry}" steps.log.info("ImageBuilder", "Authentication to ${registry}")
switch(builderType) {
case ImageBuilderTypes.DOCKER_IN_DOCKER:
steps.sh "docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD} ${registry}"
break
case ImageBuilderTypes.KANIKO:
def auth = "${DOCKER_USERNAME}:${DOCKER_PASSWORD}".bytes.encodeBase64().toString()
steps.writeFile file: '/kaniko/.docker/config.json', text: """{
"auths": {
"${registry}": {
"auth": "${auth}"
}
}
}"""
break
default:
steps.error("Unsupported builder type: ${builderType.builder}")
}
}
switch(builderType) { switch(builderType) {
case ImageBuilderTypes.DOCKER_IN_DOCKER: case ImageBuilderTypes.DOCKER_IN_DOCKER:

View File

@ -74,8 +74,8 @@ executeFreeleapsPipeline {
imageBuildRoot: '.', imageBuildRoot: '.',
// imageReleaseArchitectures used to specify the released image architectures // imageReleaseArchitectures used to specify the released image architectures
imageReleaseArchitectures: ['linux/amd64', 'linux/arm64'], imageReleaseArchitectures: ['linux/amd64', 'linux/arm64'],
// registryCredentialName used to specify the registry credential that stored in Freeleaps Kubernetes Cluster // registryCredentialsId used to specify the registry credential that stored in Jenkins
registryCredentialName: 'gitops-mvp-app-secret', registryCredentialsId: 'gitops-mvp-app-secret',
// semanticReleaseEnabled used to specify whether to enable semantic release // semanticReleaseEnabled used to specify whether to enable semantic release
semanticReleaseEnabled: true semanticReleaseEnabled: true
], ],
@ -121,8 +121,8 @@ executeFreeleapsPipeline {
imageBuildRoot: '.', imageBuildRoot: '.',
// imageReleaseArchitectures used to specify the released image architectures // imageReleaseArchitectures used to specify the released image architectures
imageReleaseArchitectures: ['linux/amd64', 'linux/arm64'], imageReleaseArchitectures: ['linux/amd64', 'linux/arm64'],
// registryCredentialName used to specify the registry credential that stored in Freeleaps Kubernetes Cluster // registryCredentialsId used to specify the registry credential that stored in Jenkins
registryCredentialName: 'gitops-mvp-app-secret', registryCredentialsId: 'gitops-mvp-app-secret',
// semanticReleaseEnabled used to specify whether to enable semantic release // semanticReleaseEnabled used to specify whether to enable semantic release
semanticReleaseEnabled: true semanticReleaseEnabled: true
] ]

View File

@ -370,11 +370,6 @@ def generateComponentStages(component, configurations) {
}, },
// Image Building & Publishing // Image Building & Publishing
stage("${component.name} :: Image Building & Publishing") { stage("${component.name} :: Image Building & Publishing") {
when {
expression {
return (env.executeMode == "fully" || env.changedComponents.contains(component.name)) && env.imageBuilderImage != null && !env.imageBuilderImage.isEmpty()
}
}
podTemplate( podTemplate(
label: "image-builder-${component.name}", label: "image-builder-${component.name}",
containers: [ containers: [
@ -424,7 +419,7 @@ def generateComponentStages(component, configurations) {
} }
def version def version
imageBuilder.build(component.imageName, component.imageRepository, component.imageRegistry, component.imageReleaseArchitectures, env.LATEST_VERSION) imageBuilder.build(component.imageName, component.imageRepository, component.imageRegistry, component.imageReleaseArchitectures, env.LATEST_VERSION, component.registryCredentialsId)
} }
} }
} }