From d31f24723beec580a676a8b0c1cfcaa7819e53c7261cda474588f372c81d6e9f Mon Sep 17 00:00:00 2001 From: Fabian Vogt Date: Fri, 23 Jul 2021 09:50:31 +0000 Subject: [PATCH] Accepting request 907914 from home:brunoleon:branches:openSUSE:Tools - Improve regexp instead of having two as proposed by Fabian Vogt - Retain compatibility with old syntax. Update documentation. - Use entry/exit point to determine whether labels should be expanded. Doing so makes the Dockerfile compatible with standard docker build command. OBS-URL: https://build.opensuse.org/request/show/907914 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-docker_label_helper?expand=0&rev=3 --- README | 39 ++++++++++++++++++++++++- docker_label_helper | 7 +++-- docker_label_helper.service | 2 +- obs-service-docker_label_helper.changes | 17 +++++++++++ obs-service-docker_label_helper.spec | 6 ++-- test.sh | 23 +++++++++++++++ 6 files changed, 86 insertions(+), 8 deletions(-) diff --git a/README b/README index c7241ca..5459fce 100644 --- a/README +++ b/README @@ -2,7 +2,44 @@ obs-service-docker_label_helper =============================== This service can be enabled to run during buildtime, when it will edit the -Dockerfile to expand the PREFIXEDLABEL instruction. +Dockerfile to expand the LABEL instruction. + +A new syntax using entry/exit flags has been introduced to provide +compatibility with stock docker build command while allowing OBS +to add its prefix to existing LABEL instructions values. + +Both new and old syntax are supported, but you should not mix both in the +same Dockerfile. + +1 - New syntax using entry/exit flags + +Only LABEL between # labelprefix and # endlabelprefix will be considered + +Example: + +``` +FROM opensuse/tumbleweed +# labelprefix=org.opensuse.nano +LABEL org.opencontainers.image.title="Example container" +LABEL org.opencontainers.image.description="This contains nano" +# endlabelprefix +LABEL not.expanded.label="example +``` + +expands to + +``` +FROM opensuse/tumbleweed +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 not.expanded.label="example" +``` + +2 - Old syntax + +Expand the PREFIXEDLABEL instruction. Example: diff --git a/docker_label_helper b/docker_label_helper index f0cae5b..03e5af1 100644 --- a/docker_label_helper +++ b/docker_label_helper @@ -20,6 +20,7 @@ if [ -e "${BUILD_DATA}" ]; then fi gawk -i inplace ' - match($0, /^# labelprefix=(.*)$/, m) { labelprefix=m[1]; next } - labelprefix != "" && match($0, /^PREFIXEDLABEL .*\.([^.]*)=(.*)$/, m) { printf "LABEL %s.%s=%s\n", labelprefix, m[1], m[2]; $1 = "LABEL" } - 1' Dockerfile + 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]; $1 = "LABEL" } + match($0, /^# endlabelprefix/) { labelprefix=""; next } + 1' Dockerfile diff --git a/docker_label_helper.service b/docker_label_helper.service index 29af0f5..68aa4e9 100644 --- a/docker_label_helper.service +++ b/docker_label_helper.service @@ -1,4 +1,4 @@ Allows automatic duplication of labels with a custom prefix. - Implements the PREFIXEDLABEL pseudo command for Dockerfile. + Expand LABEL instructions with mandatory openSUSE prefixes for Dockerfile. diff --git a/obs-service-docker_label_helper.changes b/obs-service-docker_label_helper.changes index bb6f82e..6663c54 100644 --- a/obs-service-docker_label_helper.changes +++ b/obs-service-docker_label_helper.changes @@ -1,3 +1,20 @@ +------------------------------------------------------------------- +Fri Jul 23 08:50:08 UTC 2021 - Bruno Leon + +- Improve regexp instead of having two as proposed by Fabian Vogt + +------------------------------------------------------------------- +Wed Jul 21 10:38:53 UTC 2021 - Bruno Leon + +- Retain compatibility with old syntax. Update documentation. + +------------------------------------------------------------------- +Tue Jul 20 14:28:28 UTC 2021 - Bruno Leon + +- Use entry/exit point to determine whether labels should be expanded. + Doing so makes the Dockerfile compatible with standard + docker build command. + ------------------------------------------------------------------- Fri Sep 11 10:07:44 UTC 2020 - Fabian Vogt diff --git a/obs-service-docker_label_helper.spec b/obs-service-docker_label_helper.spec index 7e8d43c..3ca00b8 100644 --- a/obs-service-docker_label_helper.spec +++ b/obs-service-docker_label_helper.spec @@ -1,7 +1,7 @@ # # spec file for package obs-service-docker_label_helper # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -33,8 +33,8 @@ BuildArch: noarch BuildRequires: diffutils %description -This service can be used during buildtime to implement the -PREFIXEDLABEL instruction useful for building containers. +This service can be used during buildtime to expand LABEL +instructions with mandatory openSUSE prefixes. %prep %setup -q -D -T -n . diff --git a/test.sh b/test.sh index f6ba6e0..ff57c61 100644 --- a/test.sh +++ b/test.sh @@ -7,6 +7,7 @@ script="$(realpath "$(dirname $0)")/docker_label_helper" cd $tmpdir +# Test old syntax cat >Dockerfile <Dockerfile <