- Handle LABEL statements with any whitespace

- Handle LABEL values containing "=" properly

OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-docker_label_helper?expand=0&rev=11
This commit is contained in:
Fabian Vogt 2023-03-01 07:55:24 +00:00 committed by Git OBS Bridge
parent 155965c650
commit 490d2e1694
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. # Note: Avoid assigning to $1 etc. as that converts whitespace (field separators) to single spaces.
gawk -i inplace ' gawk -i inplace '
match($0, /^# labelprefix=(.*)$/, m) { labelprefix=m[1]; next } 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 } match($0, /^# endlabelprefix/) { labelprefix=""; next }
1' Dockerfile 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> 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 # 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 # All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed # remain the property of their copyright owners, unless otherwise agreed

View File

@ -12,6 +12,7 @@ cat >Dockerfile <<EOF
# labelprefix=org.opensuse.nano # labelprefix=org.opensuse.nano
PREFIXEDLABEL org.opencontainers.image.title="Example container." PREFIXEDLABEL org.opencontainers.image.title="Example container."
PREFIXEDLABEL org.opencontainers.image.description="This contains nano" PREFIXEDLABEL org.opencontainers.image.description="This contains nano"
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." PREFIXEDLABEL test.whitespace="Two spaces. One tab."
EOF EOF
@ -23,6 +24,8 @@ LABEL org.opensuse.nano.title="Example container."
LABEL org.opencontainers.image.title="Example container." LABEL org.opencontainers.image.title="Example container."
LABEL org.opensuse.nano.description="This contains nano" LABEL org.opensuse.nano.description="This contains nano"
LABEL org.opencontainers.image.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 org.opensuse.nano.whitespace="Two spaces. One tab."
LABEL test.whitespace="Two spaces. One tab." LABEL test.whitespace="Two spaces. One tab."
EOF EOF
@ -34,6 +37,7 @@ cat >Dockerfile <<EOF
# labelprefix=org.opensuse.nano # labelprefix=org.opensuse.nano
LABEL org.opencontainers.image.title="Example container." LABEL org.opencontainers.image.title="Example container."
LABEL org.opencontainers.image.description="This contains nano" LABEL org.opencontainers.image.description="This contains nano"
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." LABEL test.whitespace="Two spaces. One tab."
# endlabelprefix # endlabelprefix
LABEL not.expanded.label="example" LABEL not.expanded.label="example"
@ -47,6 +51,8 @@ LABEL org.opensuse.nano.title="Example container."
LABEL org.opencontainers.image.title="Example container." LABEL org.opencontainers.image.title="Example container."
LABEL org.opensuse.nano.description="This contains nano" LABEL org.opensuse.nano.description="This contains nano"
LABEL org.opencontainers.image.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 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" LABEL not.expanded.label="example"