Skip to content

Commit 0029c30

Browse files
committed
Multiple updates (to align with upstream changes)
* Source entrypoint files with .envsh extension * Add optional filter for environment variables passed to envsubs * Use a portable source command * Use awk instead of xargs to get the environment
1 parent c03e750 commit 0029c30

22 files changed

+121
-11
lines changed

entrypoint/20-envsubst-on-templates.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ auto_envsubst() {
1414
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
1515
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
1616
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
17+
local filter="${NGINX_ENVSUBST_FILTER:-}"
1718

1819
local template defined_envs relative_path output_path subdir
19-
defined_envs=$(printf '${%s} ' $(xargs -0n1 -a /proc/self/environ sh -c 'echo "$@" | grep -oEm1 "^[^=]+"' --));
20+
defined_envs=$(printf '${%s} ' $(awk "END { for (name in ENVIRON) { print ( name ~ /${filter}/ ) ? name : \"\" } }" < /dev/null ))
2021
[ -d "$template_dir" ] || return 0
2122
if [ ! -w "$output_dir" ]; then
2223
entrypoint_log "$ME: ERROR: $template_dir exists, but $output_dir is not writable"

entrypoint/docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
1616
entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/"
1717
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
1818
case "$f" in
19+
*.envsh)
20+
if [ -x "$f" ]; then
21+
echo >&3 "$0: Sourcing $f";
22+
. "$f"
23+
else
24+
# warn on shell scripts without exec bit
25+
echo >&3 "$0: Ignoring $f, not executable";
26+
fi
27+
;;
1928
*.sh)
2029
if [ -x "$f" ]; then
2130
entrypoint_log "$0: Launching $f";

mainline/alpine-perl/20-envsubst-on-templates.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ auto_envsubst() {
1414
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
1515
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
1616
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
17+
local filter="${NGINX_ENVSUBST_FILTER:-}"
1718

1819
local template defined_envs relative_path output_path subdir
19-
defined_envs=$(printf '${%s} ' $(xargs -0n1 -a /proc/self/environ sh -c 'echo "$@" | grep -oEm1 "^[^=]+"' --));
20+
defined_envs=$(printf '${%s} ' $(awk "END { for (name in ENVIRON) { print ( name ~ /${filter}/ ) ? name : \"\" } }" < /dev/null ))
2021
[ -d "$template_dir" ] || return 0
2122
if [ ! -w "$output_dir" ]; then
2223
entrypoint_log "$ME: ERROR: $template_dir exists, but $output_dir is not writable"

mainline/alpine-perl/docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
1616
entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/"
1717
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
1818
case "$f" in
19+
*.envsh)
20+
if [ -x "$f" ]; then
21+
echo >&3 "$0: Sourcing $f";
22+
. "$f"
23+
else
24+
# warn on shell scripts without exec bit
25+
echo >&3 "$0: Ignoring $f, not executable";
26+
fi
27+
;;
1928
*.sh)
2029
if [ -x "$f" ]; then
2130
entrypoint_log "$0: Launching $f";

mainline/alpine-slim/20-envsubst-on-templates.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ auto_envsubst() {
1414
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
1515
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
1616
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
17+
local filter="${NGINX_ENVSUBST_FILTER:-}"
1718

1819
local template defined_envs relative_path output_path subdir
19-
defined_envs=$(printf '${%s} ' $(xargs -0n1 -a /proc/self/environ sh -c 'echo "$@" | grep -oEm1 "^[^=]+"' --));
20+
defined_envs=$(printf '${%s} ' $(awk "END { for (name in ENVIRON) { print ( name ~ /${filter}/ ) ? name : \"\" } }" < /dev/null ))
2021
[ -d "$template_dir" ] || return 0
2122
if [ ! -w "$output_dir" ]; then
2223
entrypoint_log "$ME: ERROR: $template_dir exists, but $output_dir is not writable"

mainline/alpine-slim/docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
1616
entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/"
1717
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
1818
case "$f" in
19+
*.envsh)
20+
if [ -x "$f" ]; then
21+
echo >&3 "$0: Sourcing $f";
22+
. "$f"
23+
else
24+
# warn on shell scripts without exec bit
25+
echo >&3 "$0: Ignoring $f, not executable";
26+
fi
27+
;;
1928
*.sh)
2029
if [ -x "$f" ]; then
2130
entrypoint_log "$0: Launching $f";

mainline/alpine/20-envsubst-on-templates.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ auto_envsubst() {
1414
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
1515
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
1616
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
17+
local filter="${NGINX_ENVSUBST_FILTER:-}"
1718

1819
local template defined_envs relative_path output_path subdir
19-
defined_envs=$(printf '${%s} ' $(xargs -0n1 -a /proc/self/environ sh -c 'echo "$@" | grep -oEm1 "^[^=]+"' --));
20+
defined_envs=$(printf '${%s} ' $(awk "END { for (name in ENVIRON) { print ( name ~ /${filter}/ ) ? name : \"\" } }" < /dev/null ))
2021
[ -d "$template_dir" ] || return 0
2122
if [ ! -w "$output_dir" ]; then
2223
entrypoint_log "$ME: ERROR: $template_dir exists, but $output_dir is not writable"

mainline/alpine/docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
1616
entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/"
1717
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
1818
case "$f" in
19+
*.envsh)
20+
if [ -x "$f" ]; then
21+
echo >&3 "$0: Sourcing $f";
22+
. "$f"
23+
else
24+
# warn on shell scripts without exec bit
25+
echo >&3 "$0: Ignoring $f, not executable";
26+
fi
27+
;;
1928
*.sh)
2029
if [ -x "$f" ]; then
2130
entrypoint_log "$0: Launching $f";

mainline/debian-perl/20-envsubst-on-templates.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ auto_envsubst() {
1414
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
1515
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
1616
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
17+
local filter="${NGINX_ENVSUBST_FILTER:-}"
1718

1819
local template defined_envs relative_path output_path subdir
19-
defined_envs=$(printf '${%s} ' $(xargs -0n1 -a /proc/self/environ sh -c 'echo "$@" | grep -oEm1 "^[^=]+"' --));
20+
defined_envs=$(printf '${%s} ' $(awk "END { for (name in ENVIRON) { print ( name ~ /${filter}/ ) ? name : \"\" } }" < /dev/null ))
2021
[ -d "$template_dir" ] || return 0
2122
if [ ! -w "$output_dir" ]; then
2223
entrypoint_log "$ME: ERROR: $template_dir exists, but $output_dir is not writable"

mainline/debian-perl/docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
1616
entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/"
1717
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
1818
case "$f" in
19+
*.envsh)
20+
if [ -x "$f" ]; then
21+
echo >&3 "$0: Sourcing $f";
22+
. "$f"
23+
else
24+
# warn on shell scripts without exec bit
25+
echo >&3 "$0: Ignoring $f, not executable";
26+
fi
27+
;;
1928
*.sh)
2029
if [ -x "$f" ]; then
2130
entrypoint_log "$0: Launching $f";

0 commit comments

Comments
 (0)