Accepting request 833745 from home:favogt:dockerfilemeta
New service, like kiwi_label_helper, but for Dockerfile. OBS-URL: https://build.opensuse.org/request/show/833745 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-docker_label_helper?expand=0&rev=1
This commit is contained in:
commit
9a2419ff77
23
.gitattributes
vendored
Normal file
23
.gitattributes
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
## Default LFS
|
||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bsp filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gem filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.jar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lzma filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.obscpio filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.oxt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pdf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rpm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tbz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tbz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ttf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.txz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.whl filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zst filter=lfs diff=lfs merge=lfs -text
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.osc
|
24
README
Normal file
24
README
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
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.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
FROM opensuse/tumbleweed
|
||||||
|
# labelprefix=org.opensuse.nano
|
||||||
|
PREFIXEDLABEL org.opencontainers.image.title="Example container"
|
||||||
|
PREFIXEDLABEL org.opencontainers.image.description="This contains nano"
|
||||||
|
```
|
||||||
|
|
||||||
|
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"
|
||||||
|
```
|
25
docker_label_helper
Normal file
25
docker_label_helper
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
if [ "${BUILD_DIST+x}" != "x" ]; then
|
||||||
|
echo "Not running in an OBS build container"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
BUILD_DATA="${BUILD_DIST/.dist/.data}"
|
||||||
|
if [ -e "${BUILD_DATA}" ]; then
|
||||||
|
. "${BUILD_DATA}"
|
||||||
|
|
||||||
|
# The build script renames the recipe (to strip _service:foo:), but doesn't update .data
|
||||||
|
RECIPEFILE="${RECIPEFILE##*:}"
|
||||||
|
|
||||||
|
if [ "${RECIPEFILE}" != "Dockerfile" ]; then
|
||||||
|
echo "Recipe is not a Dockerfile - exiting"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
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
|
4
docker_label_helper.service
Normal file
4
docker_label_helper.service
Normal file
@ -0,0 +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>
|
||||||
|
</service>
|
9
obs-service-docker_label_helper.changes
Normal file
9
obs-service-docker_label_helper.changes
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Fri Sep 11 10:07:44 UTC 2020 - Fabian Vogt <fvogt@suse.com>
|
||||||
|
|
||||||
|
- Add documentation and a test
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
Tue May 5 09:03:39 UTC 2020 - Fabian Vogt <fvogt@suse.com>
|
||||||
|
|
||||||
|
- Initial commit
|
58
obs-service-docker_label_helper.spec
Normal file
58
obs-service-docker_label_helper.spec
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#
|
||||||
|
# spec file for package obs-service-docker_label_helper
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020 SUSE LLC
|
||||||
|
#
|
||||||
|
# All modifications and additions to the file contributed by third parties
|
||||||
|
# remain the property of their copyright owners, unless otherwise agreed
|
||||||
|
# upon. The license for this file, and modifications and additions to the
|
||||||
|
# file, is the same license as for the pristine package itself (unless the
|
||||||
|
# license for the pristine package is not an Open Source License, in which
|
||||||
|
# case the license is the MIT License). An "Open Source License" is a
|
||||||
|
# license that conforms to the Open Source Definition (Version 1.9)
|
||||||
|
# published by the Open Source Initiative.
|
||||||
|
|
||||||
|
# Please submit bugfixes or comments via https://bugs.opensuse.org/
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
Name: obs-service-docker_label_helper
|
||||||
|
Version: 0.0
|
||||||
|
Release: 0
|
||||||
|
Summary: Service to duplicate labels with a custom prefix
|
||||||
|
License: GPL-2.0-or-later
|
||||||
|
Group: Development/Tools/Building
|
||||||
|
URL: https://build.opensuse.org
|
||||||
|
Source0: docker_label_helper.service
|
||||||
|
Source1: docker_label_helper
|
||||||
|
Source2: README
|
||||||
|
Source3: test.sh
|
||||||
|
Requires: gawk
|
||||||
|
BuildArch: noarch
|
||||||
|
# For %check
|
||||||
|
BuildRequires: diffutils
|
||||||
|
|
||||||
|
%description
|
||||||
|
This service can be used during buildtime to implement the
|
||||||
|
PREFIXEDLABEL instruction useful for building containers.
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%setup -q -D -T -n .
|
||||||
|
cp %{SOURCE2} .
|
||||||
|
|
||||||
|
%build
|
||||||
|
|
||||||
|
%install
|
||||||
|
mkdir -p %{buildroot}%{_prefix}/lib/obs/service
|
||||||
|
install -m 0644 %{SOURCE0} %{buildroot}%{_prefix}/lib/obs/service
|
||||||
|
install -m 0755 %{SOURCE1} %{buildroot}%{_prefix}/lib/obs/service
|
||||||
|
|
||||||
|
%check
|
||||||
|
sh %{SOURCE3}
|
||||||
|
|
||||||
|
%files
|
||||||
|
%doc README
|
||||||
|
%dir %{_prefix}/lib/obs
|
||||||
|
%{_prefix}/lib/obs/service
|
||||||
|
|
||||||
|
%changelog
|
24
test.sh
Normal file
24
test.sh
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
tmpdir=$(mktemp -d)
|
||||||
|
trap 'rm -rf ${tmpdir}' EXIT
|
||||||
|
|
||||||
|
script="$(realpath "$(dirname $0)")/docker_label_helper"
|
||||||
|
|
||||||
|
cd $tmpdir
|
||||||
|
|
||||||
|
cat >Dockerfile <<EOF
|
||||||
|
# labelprefix=org.opensuse.nano
|
||||||
|
PREFIXEDLABEL org.opencontainers.image.title="Example container"
|
||||||
|
PREFIXEDLABEL org.opencontainers.image.description="This contains nano"
|
||||||
|
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"
|
||||||
|
EOF
|
Loading…
Reference in New Issue
Block a user