Sync from SUSE:SLFO:Main obs-service-docker_label_helper revision aaa909addea4b68d3143ac9c83073f33

This commit is contained in:
Adrian Schröter 2024-10-03 17:41:02 +02:00
parent 5fa0eac737
commit 3073a8095f
3 changed files with 50 additions and 4 deletions

View File

@ -1,6 +1,8 @@
#!/bin/bash
set -eu
file="Dockerfile"
if [ "${BUILD_DIST+x}" != "x" ]; then
echo "Not running in an OBS build container"
exit 1
@ -11,10 +13,10 @@ if [ -e "${BUILD_DATA}" ]; then
. "${BUILD_DATA}"
# The build script renames the recipe (to strip _service:foo:), but doesn't update .data
RECIPEFILE="${RECIPEFILE##*:}"
file="${RECIPEFILE##*:}"
if [ "${RECIPEFILE}" != "Dockerfile" ]; then
echo "Recipe is not a Dockerfile - exiting"
if [[ ! "${file}" =~ ^Dockerfile.* ]]; then
echo "Recipe ${file} is not a Dockerfile - exiting"
exit 0
fi
fi
@ -24,4 +26,4 @@ gawk -i inplace '
match($0, /^# labelprefix=(.*)$/, m) { labelprefix=m[1]; next }
labelprefix != "" && match($0, /^(PREFIXED)?LABEL[[:space:]]+[^=]*\.([^.=]*)=(.*)$/, m) { printf "LABEL %s.%s=%s\n", labelprefix, m[2], m[3]; gsub(/^PREFIXEDLABEL/, "LABEL") }
match($0, /^# endlabelprefix/) { labelprefix=""; next }
1' Dockerfile
1' "${file}"

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Fri Jun 7 08:31:35 UTC 2024 - Andrea Mazzotti <andrea.mazzotti@suse.com>
- Support Docker.FLAVOR in _multibuild (boo#1225985)
-------------------------------------------------------------------
Wed Mar 1 07:54:19 UTC 2023 - Fabian Vogt <fvogt@suse.com>

39
test.sh
View File

@ -57,3 +57,42 @@ LABEL org.opensuse.nano.whitespace="Two spaces. One tab."
LABEL test.whitespace="Two spaces. One tab."
LABEL not.expanded.label="example"
EOF
# Test _multibuild
cat >Dockerfile.FLAVOR <<EOF
# labelprefix=org.opensuse.nano
LABEL org.opencontainers.image.title="Example container."
# endlabelprefix
EOF
export BUILD_DIST="$tmpdir/test_multibuild/.build/build.dist"
mkdir -p "$tmpdir/test_multibuild/.build"
cat >"$tmpdir/test_multibuild/.build/build.data" <<EOF
RECIPEFILE=_service:obs_scm:Dockerfile.FLAVOR
EOF
sh "${script}"
diff -u Dockerfile.FLAVOR - <<EOF
LABEL org.opensuse.nano.title="Example container."
LABEL org.opencontainers.image.title="Example container."
EOF
# Test _multibuild when not a Dockerfile.*
cat >NotADockerfile <<EOF
# labelprefix=org.opensuse.nano
LABEL org.opencontainers.image.title="Example container."
# endlabelprefix
EOF
export BUILD_DIST="$tmpdir/test_multibuild/.build/build.dist"
mkdir -p "$tmpdir/test_multibuild/.build"
cat >"$tmpdir/test_multibuild/.build/build.data" <<EOF
RECIPEFILE=_service:obs_scm:NotADockerfile
EOF
sh "${script}"
diff -u NotADockerfile - <<EOF
# labelprefix=org.opensuse.nano
LABEL org.opencontainers.image.title="Example container."
# endlabelprefix
EOF