Skip to content

Commit 10fa7fc

Browse files
committed
Updated entrypoints and dockerfiles after recent commits.
1 parent 526d1db commit 10fa7fc

10 files changed

+126
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# vim:sw=2:ts=2:sts=2:et
3+
4+
set -eu
5+
6+
LC_ALL=C
7+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
8+
9+
if [ "${NGINX_ENTRYPOINT_LOCAL_RESOLVERS}" ]; then
10+
export NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
11+
fi

mainline/alpine-slim/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ RUN set -x \
110110

111111
COPY docker-entrypoint.sh /
112112
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
113+
COPY 15-local-resolvers.envsh /docker-entrypoint.d
113114
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
114115
COPY 30-tune-worker-processes.sh /docker-entrypoint.d
115116
ENTRYPOINT ["/docker-entrypoint.sh"]
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# vim:sw=2:ts=2:sts=2:et
3+
4+
set -eu
5+
6+
LC_ALL=C
7+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
8+
9+
if [ "${NGINX_ENTRYPOINT_LOCAL_RESOLVERS}" ]; then
10+
export NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
11+
fi

mainline/debian/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ RUN set -x \
107107

108108
COPY docker-entrypoint.sh /
109109
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
110+
COPY 15-local-resolvers.envsh /docker-entrypoint.d
110111
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
111112
COPY 30-tune-worker-processes.sh /docker-entrypoint.d
112113
ENTRYPOINT ["/docker-entrypoint.sh"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# vim:sw=2:ts=2:sts=2:et
3+
4+
set -eu
5+
6+
LC_ALL=C
7+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
8+
9+
if [ "${NGINX_ENTRYPOINT_LOCAL_RESOLVERS}" ]; then
10+
export NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
11+
fi

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

+39
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,30 @@ entrypoint_log() {
1010
fi
1111
}
1212

13+
add_stream_block() {
14+
local conffile="/etc/nginx/nginx.conf"
15+
16+
if grep -q -E "\s*stream\s*\{" "$conffile"; then
17+
entrypoint_log "$ME: $conffile contains a stream block; include $stream_output_dir/*.conf to enable stream templates"
18+
else
19+
# check if the file can be modified, e.g. not on a r/o filesystem
20+
touch "$conffile" 2>/dev/null || { entrypoint_log "$ME: info: can not modify $conffile (read-only file system?)"; exit 0; }
21+
entrypoint_log "$ME: Appending stream block to $conffile to include $stream_output_dir/*.conf"
22+
cat << END >> "$conffile"
23+
# added by "$ME" on "$(date)"
24+
stream {
25+
include $stream_output_dir/*.conf;
26+
}
27+
END
28+
fi
29+
}
30+
1331
auto_envsubst() {
1432
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
1533
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
1634
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
35+
local stream_suffix="${NGINX_ENVSUBST_STREAM_TEMPLATE_SUFFIX:-.stream-template}"
36+
local stream_output_dir="${NGINX_ENVSUBST_STREAM_OUTPUT_DIR:-/etc/nginx/stream-conf.d}"
1737
local filter="${NGINX_ENVSUBST_FILTER:-}"
1838

1939
local template defined_envs relative_path output_path subdir
@@ -32,6 +52,25 @@ auto_envsubst() {
3252
entrypoint_log "$ME: Running envsubst on $template to $output_path"
3353
envsubst "$defined_envs" < "$template" > "$output_path"
3454
done
55+
56+
# Print the first file with the stream suffix, this will be false if there are none
57+
if test -n "$(find "$template_dir" -name "*$stream_suffix" -print -quit)"; then
58+
mkdir -p "$stream_output_dir"
59+
if [ ! -w "$stream_output_dir" ]; then
60+
entrypoint_log "$ME: ERROR: $template_dir exists, but $stream_output_dir is not writable"
61+
return 0
62+
fi
63+
add_stream_block
64+
find "$template_dir" -follow -type f -name "*$stream_suffix" -print | while read -r template; do
65+
relative_path="${template#$template_dir/}"
66+
output_path="$stream_output_dir/${relative_path%$stream_suffix}"
67+
subdir=$(dirname "$relative_path")
68+
# create a subdirectory where the template file exists
69+
mkdir -p "$stream_output_dir/$subdir"
70+
entrypoint_log "$ME: Running envsubst on $template to $output_path"
71+
envsubst "$defined_envs" < "$template" > "$output_path"
72+
done
73+
fi
3574
}
3675

3776
auto_envsubst

stable/alpine-slim/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ RUN set -x \
110110

111111
COPY docker-entrypoint.sh /
112112
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
113+
COPY 15-local-resolvers.envsh /docker-entrypoint.d
113114
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
114115
COPY 30-tune-worker-processes.sh /docker-entrypoint.d
115116
ENTRYPOINT ["/docker-entrypoint.sh"]
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# vim:sw=2:ts=2:sts=2:et
3+
4+
set -eu
5+
6+
LC_ALL=C
7+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
8+
9+
if [ "${NGINX_ENTRYPOINT_LOCAL_RESOLVERS}" ]; then
10+
export NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
11+
fi

stable/debian/20-envsubst-on-templates.sh

+39
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,30 @@ entrypoint_log() {
1010
fi
1111
}
1212

13+
add_stream_block() {
14+
local conffile="/etc/nginx/nginx.conf"
15+
16+
if grep -q -E "\s*stream\s*\{" "$conffile"; then
17+
entrypoint_log "$ME: $conffile contains a stream block; include $stream_output_dir/*.conf to enable stream templates"
18+
else
19+
# check if the file can be modified, e.g. not on a r/o filesystem
20+
touch "$conffile" 2>/dev/null || { entrypoint_log "$ME: info: can not modify $conffile (read-only file system?)"; exit 0; }
21+
entrypoint_log "$ME: Appending stream block to $conffile to include $stream_output_dir/*.conf"
22+
cat << END >> "$conffile"
23+
# added by "$ME" on "$(date)"
24+
stream {
25+
include $stream_output_dir/*.conf;
26+
}
27+
END
28+
fi
29+
}
30+
1331
auto_envsubst() {
1432
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
1533
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
1634
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
35+
local stream_suffix="${NGINX_ENVSUBST_STREAM_TEMPLATE_SUFFIX:-.stream-template}"
36+
local stream_output_dir="${NGINX_ENVSUBST_STREAM_OUTPUT_DIR:-/etc/nginx/stream-conf.d}"
1737
local filter="${NGINX_ENVSUBST_FILTER:-}"
1838

1939
local template defined_envs relative_path output_path subdir
@@ -32,6 +52,25 @@ auto_envsubst() {
3252
entrypoint_log "$ME: Running envsubst on $template to $output_path"
3353
envsubst "$defined_envs" < "$template" > "$output_path"
3454
done
55+
56+
# Print the first file with the stream suffix, this will be false if there are none
57+
if test -n "$(find "$template_dir" -name "*$stream_suffix" -print -quit)"; then
58+
mkdir -p "$stream_output_dir"
59+
if [ ! -w "$stream_output_dir" ]; then
60+
entrypoint_log "$ME: ERROR: $template_dir exists, but $stream_output_dir is not writable"
61+
return 0
62+
fi
63+
add_stream_block
64+
find "$template_dir" -follow -type f -name "*$stream_suffix" -print | while read -r template; do
65+
relative_path="${template#$template_dir/}"
66+
output_path="$stream_output_dir/${relative_path%$stream_suffix}"
67+
subdir=$(dirname "$relative_path")
68+
# create a subdirectory where the template file exists
69+
mkdir -p "$stream_output_dir/$subdir"
70+
entrypoint_log "$ME: Running envsubst on $template to $output_path"
71+
envsubst "$defined_envs" < "$template" > "$output_path"
72+
done
73+
fi
3574
}
3675

3776
auto_envsubst

stable/debian/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ RUN set -x \
107107

108108
COPY docker-entrypoint.sh /
109109
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
110+
COPY 15-local-resolvers.envsh /docker-entrypoint.d
110111
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
111112
COPY 30-tune-worker-processes.sh /docker-entrypoint.d
112113
ENTRYPOINT ["/docker-entrypoint.sh"]

0 commit comments

Comments
 (0)