buildContainerImage2: Handle names with slashes

If the provided container image name includes a `/` character, the build
will fail when copying the OCI image to a tarball:

> + buildah push git.pyrocufflink.net/containerimages/build/selinux:dev-ci oci-archive:/home/jenkins/agent/workspace/ainerImages_build.selinux_dev_ci/build/selinux-amd64.tar
> Error: lstat /home/jenkins/agent/workspace/ainerImages_build.selinux_dev_ci/build: no such file or directory

To resolve this, we need to escape the image name when constructing the
path to the tar file.
bci2-resources
Dustin 2023-10-24 18:27:09 -05:00
parent 96f4e59cbc
commit 93da924aab
1 changed files with 12 additions and 12 deletions

View File

@ -18,17 +18,10 @@ def call(args) {
project = 'containerimages'
}
if (name == null) {
name = env.JOB_NAME.
split('/')[1].
toLowerCase().
replaceAll('[^a-zA-z0-9._-]', '-').
replaceAll('^[.-]', '_')
name = escapeImageName(env.JOB_NAME.split('/')[1])
}
if (tag == null) {
tag = env.BRANCH_NAME.
toLowerCase().
replaceAll('[^a-zA-z0-9._-]', '-').
replaceAll('^[.-]', '_')
tag = escapeImageName(env.BRANCH_NAME)
}
if (archlist == null) {
archlist = ['amd64']
@ -60,7 +53,7 @@ def call(args) {
sh "buildah manifest create '${full_name}'"
archlist.each { arch ->
unstash arch
sh "buildah manifest add '${full_name}' oci-archive:\${PWD}/${name}-${arch}.tar"
sh "buildah manifest add '${full_name}' oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar"
}
}
}
@ -96,8 +89,8 @@ def buildStage(args) {
container('buildah') {
withBuildahCreds(registry) {
sh "buildah build -t '${full_name}' ."
sh "buildah push '${full_name}' oci-archive:\${PWD}/${name}-${arch}.tar"
stash name: arch, includes: "${name}-*.tar"
sh "buildah push '${full_name}' oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar"
stash name: arch, includes: "${escapeImageName(name)}-*.tar"
}
}
}
@ -142,3 +135,10 @@ def withBuildahCreds(registry, block) {
block()
}
}
def escapeImageName(name) {
return name.
toLowerCase().
replaceAll('[^a-zA-z0-9._-]', '-').
replaceAll('^[.-]', '_')
}