Fabian Vogt
d31f24723b
- 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
27 lines
750 B
Bash
27 lines
750 B
Bash
#!/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, /^(PREFIXED)?LABEL .*\.([^.]*)=(.*)$/, m) { printf "LABEL %s.%s=%s\n", labelprefix, m[2], m[3]; $1 = "LABEL" }
|
|
match($0, /^# endlabelprefix/) { labelprefix=""; next }
|
|
1' Dockerfile
|