commit 9a2419ff77417c44950c6e5760ffe383fe313303cac57f6aff9898fce7d774b6 Author: Alberto Planas Dominguez Date: Thu Sep 17 13:35:39 2020 +0000 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 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/README b/README new file mode 100644 index 0000000..c7241ca --- /dev/null +++ b/README @@ -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" +``` diff --git a/docker_label_helper b/docker_label_helper new file mode 100644 index 0000000..f0cae5b --- /dev/null +++ b/docker_label_helper @@ -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 diff --git a/docker_label_helper.service b/docker_label_helper.service new file mode 100644 index 0000000..29af0f5 --- /dev/null +++ b/docker_label_helper.service @@ -0,0 +1,4 @@ + + Allows automatic duplication of labels with a custom prefix. + Implements the PREFIXEDLABEL pseudo command for Dockerfile. + diff --git a/obs-service-docker_label_helper.changes b/obs-service-docker_label_helper.changes new file mode 100644 index 0000000..bb6f82e --- /dev/null +++ b/obs-service-docker_label_helper.changes @@ -0,0 +1,9 @@ +------------------------------------------------------------------- +Fri Sep 11 10:07:44 UTC 2020 - Fabian Vogt + +- Add documentation and a test + +------------------------------------------------------------------- +Tue May 5 09:03:39 UTC 2020 - Fabian Vogt + +- Initial commit diff --git a/obs-service-docker_label_helper.spec b/obs-service-docker_label_helper.spec new file mode 100644 index 0000000..7e8d43c --- /dev/null +++ b/obs-service-docker_label_helper.spec @@ -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 diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..f6ba6e0 --- /dev/null +++ b/test.sh @@ -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 <