Accepting request 1068356 from openSUSE:Tools

- Handle LABEL statements with any whitespace
- Handle LABEL values containing "=" properly

OBS-URL: https://build.opensuse.org/request/show/1068356
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/obs-service-docker_label_helper?expand=0&rev=6
This commit is contained in:
Dominique Leuenberger 2023-03-01 15:14:31 +00:00 committed by Git OBS Bridge
commit 6b550e76d6
4 changed files with 18 additions and 6 deletions

View File

@ -22,6 +22,6 @@ fi
# Note: Avoid assigning to $1 etc. as that converts whitespace (field separators) to single spaces.
gawk -i inplace '
match($0, /^# labelprefix=(.*)$/, m) { labelprefix=m[1]; next }
labelprefix != "" && match($0, /^(PREFIXED)?LABEL .*\.([^.]*)=(.*)$/, m) { printf "LABEL %s.%s=%s\n", labelprefix, m[2], m[3]; gsub(/^PREFIXEDLABEL/, "LABEL") }
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

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Mar 1 07:54:19 UTC 2023 - Fabian Vogt <fvogt@suse.com>
- Handle LABEL statements with any whitespace
- Handle LABEL values containing "=" properly
-------------------------------------------------------------------
Wed Dec 7 09:48:52 UTC 2022 - Dominique Leuenberger <dimstar@opensuse.org>

View File

@ -1,7 +1,7 @@
#
# spec file for package obs-service-docker_label_helper
#
# Copyright (c) 2022 SUSE LLC
# Copyright (c) 2023 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed

14
test.sh
View File

@ -12,7 +12,8 @@ cat >Dockerfile <<EOF
# labelprefix=org.opensuse.nano
PREFIXEDLABEL org.opencontainers.image.title="Example container."
PREFIXEDLABEL org.opencontainers.image.description="This contains nano"
PREFIXEDLABEL test.whitespace="Two spaces. One tab."
PREFIXEDLABEL org.opencontainers.image.source="https://build.opensuse.org/package/show/openSUSE:Factory/opensuse-tumbleweed-image?rev=1afbea7e9b8ecf976071564312c2db66"
PREFIXEDLABEL test.whitespace="Two spaces. One tab."
EOF
export BUILD_DIST=
@ -23,8 +24,10 @@ LABEL org.opensuse.nano.title="Example container."
LABEL org.opencontainers.image.title="Example container."
LABEL org.opensuse.nano.description="This contains nano"
LABEL org.opencontainers.image.description="This contains nano"
LABEL org.opensuse.nano.source="https://build.opensuse.org/package/show/openSUSE:Factory/opensuse-tumbleweed-image?rev=1afbea7e9b8ecf976071564312c2db66"
LABEL org.opencontainers.image.source="https://build.opensuse.org/package/show/openSUSE:Factory/opensuse-tumbleweed-image?rev=1afbea7e9b8ecf976071564312c2db66"
LABEL org.opensuse.nano.whitespace="Two spaces. One tab."
LABEL test.whitespace="Two spaces. One tab."
LABEL test.whitespace="Two spaces. One tab."
EOF
rm -f Dockerfile
@ -34,7 +37,8 @@ cat >Dockerfile <<EOF
# labelprefix=org.opensuse.nano
LABEL org.opencontainers.image.title="Example container."
LABEL org.opencontainers.image.description="This contains nano"
LABEL test.whitespace="Two spaces. One tab."
LABEL org.opencontainers.image.source="https://build.opensuse.org/package/show/openSUSE:Factory/opensuse-tumbleweed-image?rev=1afbea7e9b8ecf976071564312c2db66"
LABEL test.whitespace="Two spaces. One tab."
# endlabelprefix
LABEL not.expanded.label="example"
EOF
@ -47,7 +51,9 @@ LABEL org.opensuse.nano.title="Example container."
LABEL org.opencontainers.image.title="Example container."
LABEL org.opensuse.nano.description="This contains nano"
LABEL org.opencontainers.image.description="This contains nano"
LABEL org.opensuse.nano.source="https://build.opensuse.org/package/show/openSUSE:Factory/opensuse-tumbleweed-image?rev=1afbea7e9b8ecf976071564312c2db66"
LABEL org.opencontainers.image.source="https://build.opensuse.org/package/show/openSUSE:Factory/opensuse-tumbleweed-image?rev=1afbea7e9b8ecf976071564312c2db66"
LABEL org.opensuse.nano.whitespace="Two spaces. One tab."
LABEL test.whitespace="Two spaces. One tab."
LABEL test.whitespace="Two spaces. One tab."
LABEL not.expanded.label="example"
EOF