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
parent
96f4e59cbc
commit
93da924aab
|
@ -18,17 +18,10 @@ def call(args) {
|
||||||
project = 'containerimages'
|
project = 'containerimages'
|
||||||
}
|
}
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = env.JOB_NAME.
|
name = escapeImageName(env.JOB_NAME.split('/')[1])
|
||||||
split('/')[1].
|
|
||||||
toLowerCase().
|
|
||||||
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
||||||
replaceAll('^[.-]', '_')
|
|
||||||
}
|
}
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
tag = env.BRANCH_NAME.
|
tag = escapeImageName(env.BRANCH_NAME)
|
||||||
toLowerCase().
|
|
||||||
replaceAll('[^a-zA-z0-9._-]', '-').
|
|
||||||
replaceAll('^[.-]', '_')
|
|
||||||
}
|
}
|
||||||
if (archlist == null) {
|
if (archlist == null) {
|
||||||
archlist = ['amd64']
|
archlist = ['amd64']
|
||||||
|
@ -60,7 +53,7 @@ def call(args) {
|
||||||
sh "buildah manifest create '${full_name}'"
|
sh "buildah manifest create '${full_name}'"
|
||||||
archlist.each { arch ->
|
archlist.each { arch ->
|
||||||
unstash 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') {
|
container('buildah') {
|
||||||
withBuildahCreds(registry) {
|
withBuildahCreds(registry) {
|
||||||
sh "buildah build -t '${full_name}' ."
|
sh "buildah build -t '${full_name}' ."
|
||||||
sh "buildah push '${full_name}' oci-archive:\${PWD}/${name}-${arch}.tar"
|
sh "buildah push '${full_name}' oci-archive:\${PWD}/${escapeImageName(name)}-${arch}.tar"
|
||||||
stash name: arch, includes: "${name}-*.tar"
|
stash name: arch, includes: "${escapeImageName(name)}-*.tar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,3 +135,10 @@ def withBuildahCreds(registry, block) {
|
||||||
block()
|
block()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def escapeImageName(name) {
|
||||||
|
return name.
|
||||||
|
toLowerCase().
|
||||||
|
replaceAll('[^a-zA-z0-9._-]', '-').
|
||||||
|
replaceAll('^[.-]', '_')
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue