diff --git a/mainline/alpine-perl/20-envsubst-on-templates.sh b/mainline/alpine-perl/20-envsubst-on-templates.sh new file mode 100755 index 0000000000000000000000000000000000000000..b2b6e123044347b835c01e64ae121073919f3259 --- /dev/null +++ b/mainline/alpine-perl/20-envsubst-on-templates.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +ME=$(basename $0) + +auto_envsubst() { + local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}" + local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" + local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}" + + local template defined_envs relative_path output_path subdir + defined_envs=$(printf '${%s} ' $(env | cut -d= -f1)) + [ -d "$template_dir" ] || return 0 + if [ ! -w "$output_dir" ]; then + echo "$ME: ERROR: $template_dir exists, but $output_dir is not writable, exiting" 1>&2 + return 0 + fi + for template in $(find "$template_dir" -follow -name "*$suffix"); do + relative_path="${template#$template_dir/}" + output_path="$output_dir/${relative_path%$suffix}" + subdir=$(dirname "$relative_path") + # create a subdirectory where the template file exists + mkdir -p "$output_dir/$subdir" + echo "$ME: Running envsubst on $template to $output_path" + envsubst "$defined_envs" < "$template" > "$output_path" + done +} + +auto_envsubst + +exit 0 diff --git a/mainline/alpine-perl/Dockerfile b/mainline/alpine-perl/Dockerfile index 3ac6f43180709aeb81d448fd8d61999ac7cea2f1..3202a0527beef433acbe43029ef7b86e3eb94930 100644 --- a/mainline/alpine-perl/Dockerfile +++ b/mainline/alpine-perl/Dockerfile @@ -110,6 +110,7 @@ RUN set -x \ COPY docker-entrypoint.sh / COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d +COPY 20-envsubst-on-templates.sh /docker-entrypoint.d ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 80 diff --git a/mainline/alpine/20-envsubst-on-templates.sh b/mainline/alpine/20-envsubst-on-templates.sh new file mode 100755 index 0000000000000000000000000000000000000000..b2b6e123044347b835c01e64ae121073919f3259 --- /dev/null +++ b/mainline/alpine/20-envsubst-on-templates.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +ME=$(basename $0) + +auto_envsubst() { + local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}" + local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" + local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}" + + local template defined_envs relative_path output_path subdir + defined_envs=$(printf '${%s} ' $(env | cut -d= -f1)) + [ -d "$template_dir" ] || return 0 + if [ ! -w "$output_dir" ]; then + echo "$ME: ERROR: $template_dir exists, but $output_dir is not writable, exiting" 1>&2 + return 0 + fi + for template in $(find "$template_dir" -follow -name "*$suffix"); do + relative_path="${template#$template_dir/}" + output_path="$output_dir/${relative_path%$suffix}" + subdir=$(dirname "$relative_path") + # create a subdirectory where the template file exists + mkdir -p "$output_dir/$subdir" + echo "$ME: Running envsubst on $template to $output_path" + envsubst "$defined_envs" < "$template" > "$output_path" + done +} + +auto_envsubst + +exit 0 diff --git a/mainline/alpine/Dockerfile b/mainline/alpine/Dockerfile index afc8a8f19874d2858ed697a5d3d7c5184de9ba3c..e660c4c03b97acbfc1e0a1085a9d36c2c3034203 100644 --- a/mainline/alpine/Dockerfile +++ b/mainline/alpine/Dockerfile @@ -109,6 +109,7 @@ RUN set -x \ COPY docker-entrypoint.sh / COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d +COPY 20-envsubst-on-templates.sh /docker-entrypoint.d ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 80 diff --git a/mainline/buster-perl/20-envsubst-on-templates.sh b/mainline/buster-perl/20-envsubst-on-templates.sh new file mode 100755 index 0000000000000000000000000000000000000000..b2b6e123044347b835c01e64ae121073919f3259 --- /dev/null +++ b/mainline/buster-perl/20-envsubst-on-templates.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +ME=$(basename $0) + +auto_envsubst() { + local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}" + local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" + local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}" + + local template defined_envs relative_path output_path subdir + defined_envs=$(printf '${%s} ' $(env | cut -d= -f1)) + [ -d "$template_dir" ] || return 0 + if [ ! -w "$output_dir" ]; then + echo "$ME: ERROR: $template_dir exists, but $output_dir is not writable, exiting" 1>&2 + return 0 + fi + for template in $(find "$template_dir" -follow -name "*$suffix"); do + relative_path="${template#$template_dir/}" + output_path="$output_dir/${relative_path%$suffix}" + subdir=$(dirname "$relative_path") + # create a subdirectory where the template file exists + mkdir -p "$output_dir/$subdir" + echo "$ME: Running envsubst on $template to $output_path" + envsubst "$defined_envs" < "$template" > "$output_path" + done +} + +auto_envsubst + +exit 0 diff --git a/mainline/buster-perl/Dockerfile b/mainline/buster-perl/Dockerfile index 8bf66cfb753198629b557f2018644f41147a7359..e7ce87396d4189970152f42e9251bf05be5d2b2f 100644 --- a/mainline/buster-perl/Dockerfile +++ b/mainline/buster-perl/Dockerfile @@ -101,6 +101,7 @@ RUN set -x \ COPY docker-entrypoint.sh / COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d +COPY 20-envsubst-on-templates.sh /docker-entrypoint.d ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 80 diff --git a/mainline/buster/20-envsubst-on-templates.sh b/mainline/buster/20-envsubst-on-templates.sh new file mode 100755 index 0000000000000000000000000000000000000000..b2b6e123044347b835c01e64ae121073919f3259 --- /dev/null +++ b/mainline/buster/20-envsubst-on-templates.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +ME=$(basename $0) + +auto_envsubst() { + local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}" + local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" + local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}" + + local template defined_envs relative_path output_path subdir + defined_envs=$(printf '${%s} ' $(env | cut -d= -f1)) + [ -d "$template_dir" ] || return 0 + if [ ! -w "$output_dir" ]; then + echo "$ME: ERROR: $template_dir exists, but $output_dir is not writable, exiting" 1>&2 + return 0 + fi + for template in $(find "$template_dir" -follow -name "*$suffix"); do + relative_path="${template#$template_dir/}" + output_path="$output_dir/${relative_path%$suffix}" + subdir=$(dirname "$relative_path") + # create a subdirectory where the template file exists + mkdir -p "$output_dir/$subdir" + echo "$ME: Running envsubst on $template to $output_path" + envsubst "$defined_envs" < "$template" > "$output_path" + done +} + +auto_envsubst + +exit 0 diff --git a/mainline/buster/Dockerfile b/mainline/buster/Dockerfile index 4529d063ef2b8a5ff188ce0f76c89e08aa08db7c..856f3fd03501da84b43e43968166556cbc344de7 100644 --- a/mainline/buster/Dockerfile +++ b/mainline/buster/Dockerfile @@ -100,6 +100,7 @@ RUN set -x \ COPY docker-entrypoint.sh / COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d +COPY 20-envsubst-on-templates.sh /docker-entrypoint.d ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 80 diff --git a/stable/alpine-perl/20-envsubst-on-templates.sh b/stable/alpine-perl/20-envsubst-on-templates.sh new file mode 100755 index 0000000000000000000000000000000000000000..b2b6e123044347b835c01e64ae121073919f3259 --- /dev/null +++ b/stable/alpine-perl/20-envsubst-on-templates.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +ME=$(basename $0) + +auto_envsubst() { + local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}" + local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" + local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}" + + local template defined_envs relative_path output_path subdir + defined_envs=$(printf '${%s} ' $(env | cut -d= -f1)) + [ -d "$template_dir" ] || return 0 + if [ ! -w "$output_dir" ]; then + echo "$ME: ERROR: $template_dir exists, but $output_dir is not writable, exiting" 1>&2 + return 0 + fi + for template in $(find "$template_dir" -follow -name "*$suffix"); do + relative_path="${template#$template_dir/}" + output_path="$output_dir/${relative_path%$suffix}" + subdir=$(dirname "$relative_path") + # create a subdirectory where the template file exists + mkdir -p "$output_dir/$subdir" + echo "$ME: Running envsubst on $template to $output_path" + envsubst "$defined_envs" < "$template" > "$output_path" + done +} + +auto_envsubst + +exit 0 diff --git a/stable/alpine-perl/Dockerfile b/stable/alpine-perl/Dockerfile index f2556fbb41b81f484ca9bb82bfd4348e389089df..c4e7d17e5325760cc7d44cb4dea4252af17be8c0 100644 --- a/stable/alpine-perl/Dockerfile +++ b/stable/alpine-perl/Dockerfile @@ -110,6 +110,7 @@ RUN set -x \ COPY docker-entrypoint.sh / COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d +COPY 20-envsubst-on-templates.sh /docker-entrypoint.d ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 80 diff --git a/stable/alpine/20-envsubst-on-templates.sh b/stable/alpine/20-envsubst-on-templates.sh new file mode 100755 index 0000000000000000000000000000000000000000..b2b6e123044347b835c01e64ae121073919f3259 --- /dev/null +++ b/stable/alpine/20-envsubst-on-templates.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +ME=$(basename $0) + +auto_envsubst() { + local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}" + local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" + local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}" + + local template defined_envs relative_path output_path subdir + defined_envs=$(printf '${%s} ' $(env | cut -d= -f1)) + [ -d "$template_dir" ] || return 0 + if [ ! -w "$output_dir" ]; then + echo "$ME: ERROR: $template_dir exists, but $output_dir is not writable, exiting" 1>&2 + return 0 + fi + for template in $(find "$template_dir" -follow -name "*$suffix"); do + relative_path="${template#$template_dir/}" + output_path="$output_dir/${relative_path%$suffix}" + subdir=$(dirname "$relative_path") + # create a subdirectory where the template file exists + mkdir -p "$output_dir/$subdir" + echo "$ME: Running envsubst on $template to $output_path" + envsubst "$defined_envs" < "$template" > "$output_path" + done +} + +auto_envsubst + +exit 0 diff --git a/stable/alpine/Dockerfile b/stable/alpine/Dockerfile index 462670470098feef0a93be532f40fa3fc7ab6028..09e6b6185adbcb893ddad62d1df10e1ee7345db1 100644 --- a/stable/alpine/Dockerfile +++ b/stable/alpine/Dockerfile @@ -109,6 +109,7 @@ RUN set -x \ COPY docker-entrypoint.sh / COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d +COPY 20-envsubst-on-templates.sh /docker-entrypoint.d ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 80 diff --git a/stable/buster-perl/20-envsubst-on-templates.sh b/stable/buster-perl/20-envsubst-on-templates.sh new file mode 100755 index 0000000000000000000000000000000000000000..b2b6e123044347b835c01e64ae121073919f3259 --- /dev/null +++ b/stable/buster-perl/20-envsubst-on-templates.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +ME=$(basename $0) + +auto_envsubst() { + local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}" + local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" + local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}" + + local template defined_envs relative_path output_path subdir + defined_envs=$(printf '${%s} ' $(env | cut -d= -f1)) + [ -d "$template_dir" ] || return 0 + if [ ! -w "$output_dir" ]; then + echo "$ME: ERROR: $template_dir exists, but $output_dir is not writable, exiting" 1>&2 + return 0 + fi + for template in $(find "$template_dir" -follow -name "*$suffix"); do + relative_path="${template#$template_dir/}" + output_path="$output_dir/${relative_path%$suffix}" + subdir=$(dirname "$relative_path") + # create a subdirectory where the template file exists + mkdir -p "$output_dir/$subdir" + echo "$ME: Running envsubst on $template to $output_path" + envsubst "$defined_envs" < "$template" > "$output_path" + done +} + +auto_envsubst + +exit 0 diff --git a/stable/buster-perl/Dockerfile b/stable/buster-perl/Dockerfile index 5212e28e0fdebcf5dbf9bdedcc11004c972caa73..bb582472f6fd1c60ebff869780e44c692ee0e8f2 100644 --- a/stable/buster-perl/Dockerfile +++ b/stable/buster-perl/Dockerfile @@ -101,6 +101,7 @@ RUN set -x \ COPY docker-entrypoint.sh / COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d +COPY 20-envsubst-on-templates.sh /docker-entrypoint.d ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 80 diff --git a/stable/buster/20-envsubst-on-templates.sh b/stable/buster/20-envsubst-on-templates.sh new file mode 100755 index 0000000000000000000000000000000000000000..b2b6e123044347b835c01e64ae121073919f3259 --- /dev/null +++ b/stable/buster/20-envsubst-on-templates.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +ME=$(basename $0) + +auto_envsubst() { + local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}" + local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" + local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}" + + local template defined_envs relative_path output_path subdir + defined_envs=$(printf '${%s} ' $(env | cut -d= -f1)) + [ -d "$template_dir" ] || return 0 + if [ ! -w "$output_dir" ]; then + echo "$ME: ERROR: $template_dir exists, but $output_dir is not writable, exiting" 1>&2 + return 0 + fi + for template in $(find "$template_dir" -follow -name "*$suffix"); do + relative_path="${template#$template_dir/}" + output_path="$output_dir/${relative_path%$suffix}" + subdir=$(dirname "$relative_path") + # create a subdirectory where the template file exists + mkdir -p "$output_dir/$subdir" + echo "$ME: Running envsubst on $template to $output_path" + envsubst "$defined_envs" < "$template" > "$output_path" + done +} + +auto_envsubst + +exit 0 diff --git a/stable/buster/Dockerfile b/stable/buster/Dockerfile index 3050aa882bfe30e316396cf09ea117bae0f15494..6c98f2f7fe904ab1e9cb971f059e0a0fbadb7213 100644 --- a/stable/buster/Dockerfile +++ b/stable/buster/Dockerfile @@ -100,6 +100,7 @@ RUN set -x \ COPY docker-entrypoint.sh / COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d +COPY 20-envsubst-on-templates.sh /docker-entrypoint.d ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 80