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
This commit is contained in:
parent
cc0df88efc
commit
d31f24723b
39
README
39
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:
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
<service name="docker_label_helper">
|
||||
<summary>Allows automatic duplication of labels with a custom prefix.</summary>
|
||||
<description>Implements the PREFIXEDLABEL pseudo command for Dockerfile.</description>
|
||||
<description>Expand LABEL instructions with mandatory openSUSE prefixes for Dockerfile.</description>
|
||||
</service>
|
||||
|
@ -1,3 +1,20 @@
|
||||
-------------------------------------------------------------------
|
||||
Fri Jul 23 08:50:08 UTC 2021 - Bruno Leon <bruno.leon@suse.com>
|
||||
|
||||
- Improve regexp instead of having two as proposed by Fabian Vogt
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Wed Jul 21 10:38:53 UTC 2021 - Bruno Leon <bruno.leon@suse.com>
|
||||
|
||||
- Retain compatibility with old syntax. Update documentation.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue Jul 20 14:28:28 UTC 2021 - Bruno Leon <bruno.leon@suse.com>
|
||||
|
||||
- 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 <fvogt@suse.com>
|
||||
|
||||
|
@ -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 .
|
||||
|
23
test.sh
23
test.sh
@ -7,6 +7,7 @@ script="$(realpath "$(dirname $0)")/docker_label_helper"
|
||||
|
||||
cd $tmpdir
|
||||
|
||||
# Test old syntax
|
||||
cat >Dockerfile <<EOF
|
||||
# labelprefix=org.opensuse.nano
|
||||
PREFIXEDLABEL org.opencontainers.image.title="Example container"
|
||||
@ -22,3 +23,25 @@ LABEL org.opencontainers.image.title="Example container"
|
||||
LABEL org.opensuse.nano.description="This contains nano"
|
||||
LABEL org.opencontainers.image.description="This contains nano"
|
||||
EOF
|
||||
|
||||
rm -f Dockerfile
|
||||
|
||||
# Test new syntax
|
||||
cat >Dockerfile <<EOF
|
||||
# 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"
|
||||
EOF
|
||||
|
||||
export BUILD_DIST=
|
||||
sh "${script}"
|
||||
|
||||
diff -u Dockerfile - <<EOF
|
||||
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"
|
||||
EOF
|
||||
|
Loading…
Reference in New Issue
Block a user