obs-service-docker_label_he.../test.sh
Fabian Vogt d31f24723b 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
2021-07-23 09:50:31 +00:00

48 lines
1.2 KiB
Bash

#!/bin/sh
set -eu
tmpdir=$(mktemp -d)
trap 'rm -rf ${tmpdir}' EXIT
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"
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
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