1
0
mirror of https://github.com/docker-library/postgres.git synced 2025-04-18 00:57:36 +03:00
postgres/apply-templates.sh
Tianon Gravi 3e9b4eaaeb Replace su-exec with gosu
There's a major issue with `su-exec` whose fix has gone unreleased for 5 years (typos leading to running code as root, the opposite of the purpose of the program).

This also decreases our Debian vs Alpine variance.

Due to user scripts/downstream code potentially using `su-exec`, I have included a compatibility symlink to `su-exec` for all versions less than the 17 pre-release.
2024-06-03 13:57:56 -07:00

67 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
[ -f versions.json ] # run "versions.sh" first
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
jqt='.jq-template.awk'
if [ -n "${BASHBREW_SCRIPTS:-}" ]; then
jqt="$BASHBREW_SCRIPTS/jq-template.awk"
elif [ "$BASH_SOURCE" -nt "$jqt" ]; then
# https://github.com/docker-library/bashbrew/blob/master/scripts/jq-template.awk
wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/9f6a35772ac863a0241f147c820354e4008edf38/scripts/jq-template.awk'
fi
if [ "$#" -eq 0 ]; then
versions="$(jq -r 'keys | map(@sh) | join(" ")' versions.json)"
eval "set -- $versions"
fi
generated_warning() {
cat <<-EOH
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
EOH
}
for version; do
export version
major="$(jq -r '.[env.version].major' versions.json)"
variants="$(jq -r '.[env.version].variants | map(@sh) | join(" ")' versions.json)"
eval "variants=( $variants )"
rm -rf "$version"
for variant in "${variants[@]}"; do
export variant
dir="$version/$variant"
mkdir -p "$dir"
echo "processing $dir ..."
case "$variant" in
alpine*)
template='Dockerfile-alpine.template'
;;
*)
template='Dockerfile-debian.template'
;;
esac
{
generated_warning
gawk -f "$jqt" "$template"
} > "$dir/Dockerfile"
cp -a docker-entrypoint.sh docker-ensure-initdb.sh "$dir/"
done
done