Skip to content

Commit 8fe0244

Browse files
authored
Add IPv6 support for local-resolvers substitution script (#186)
* And address Alpine bug and shell linter warnings
1 parent ad49205 commit 8fe0244

25 files changed

+50
-45
lines changed

entrypoint/10-listen-on-ipv6-by-default.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
ME=$(basename $0)
12+
ME=$(basename "$0")
1313
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"
1414

1515
# check if we have ipv6 available

entrypoint/15-local-resolvers.envsh

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
88

99
[ "${NGINX_ENTRYPOINT_LOCAL_RESOLVERS:-}" ] || return 0
1010

11-
export NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
11+
NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {if ($2 ~ ":") {print "["$2"]"} else {print $2}}' /etc/resolv.conf)
12+
export NGINX_LOCAL_RESOLVERS

entrypoint/20-envsubst-on-templates.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
ME=$(basename $0)
5+
ME=$(basename "$0")
66

77
entrypoint_log() {
88
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
@@ -44,8 +44,8 @@ auto_envsubst() {
4444
return 0
4545
fi
4646
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
47-
relative_path="${template#$template_dir/}"
48-
output_path="$output_dir/${relative_path%$suffix}"
47+
relative_path="${template#"$template_dir/"}"
48+
output_path="$output_dir/${relative_path%"$suffix"}"
4949
subdir=$(dirname "$relative_path")
5050
# create a subdirectory where the template file exists
5151
mkdir -p "$output_dir/$subdir"
@@ -62,8 +62,8 @@ auto_envsubst() {
6262
fi
6363
add_stream_block
6464
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}"
65+
relative_path="${template#"$template_dir/"}"
66+
output_path="$stream_output_dir/${relative_path%"$stream_suffix"}"
6767
subdir=$(dirname "$relative_path")
6868
# create a subdirectory where the template file exists
6969
mkdir -p "$stream_output_dir/$subdir"

entrypoint/30-tune-worker-processes.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -eu
55

66
LC_ALL=C
7-
ME=$( basename "$0" )
7+
ME=$(basename "$0")
88
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
99

1010
[ "${NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE:-}" ] || exit 0

entrypoint/docker-entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
12+
if [ "$1" = "nginx" ] || [ "$1" = "nginx-debug" ]; then
1313
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
1414
entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
1515

mainline/alpine-slim/10-listen-on-ipv6-by-default.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
ME=$(basename $0)
12+
ME=$(basename "$0")
1313
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"
1414

1515
# check if we have ipv6 available

mainline/alpine-slim/15-local-resolvers.envsh

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
88

99
[ "${NGINX_ENTRYPOINT_LOCAL_RESOLVERS:-}" ] || return 0
1010

11-
export NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
11+
NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {if ($2 ~ ":") {print "["$2"]"} else {print $2}}' /etc/resolv.conf)
12+
export NGINX_LOCAL_RESOLVERS

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
ME=$(basename $0)
5+
ME=$(basename "$0")
66

77
entrypoint_log() {
88
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
@@ -44,8 +44,8 @@ auto_envsubst() {
4444
return 0
4545
fi
4646
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
47-
relative_path="${template#$template_dir/}"
48-
output_path="$output_dir/${relative_path%$suffix}"
47+
relative_path="${template#"$template_dir/"}"
48+
output_path="$output_dir/${relative_path%"$suffix"}"
4949
subdir=$(dirname "$relative_path")
5050
# create a subdirectory where the template file exists
5151
mkdir -p "$output_dir/$subdir"
@@ -62,8 +62,8 @@ auto_envsubst() {
6262
fi
6363
add_stream_block
6464
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}"
65+
relative_path="${template#"$template_dir/"}"
66+
output_path="$stream_output_dir/${relative_path%"$stream_suffix"}"
6767
subdir=$(dirname "$relative_path")
6868
# create a subdirectory where the template file exists
6969
mkdir -p "$stream_output_dir/$subdir"

mainline/alpine-slim/30-tune-worker-processes.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -eu
55

66
LC_ALL=C
7-
ME=$( basename "$0" )
7+
ME=$(basename "$0")
88
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
99

1010
[ "${NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE:-}" ] || exit 0

mainline/alpine-slim/docker-entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
12+
if [ "$1" = "nginx" ] || [ "$1" = "nginx-debug" ]; then
1313
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
1414
entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
1515

mainline/debian/10-listen-on-ipv6-by-default.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
ME=$(basename $0)
12+
ME=$(basename "$0")
1313
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"
1414

1515
# check if we have ipv6 available

mainline/debian/15-local-resolvers.envsh

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
88

99
[ "${NGINX_ENTRYPOINT_LOCAL_RESOLVERS:-}" ] || return 0
1010

11-
export NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
11+
NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {if ($2 ~ ":") {print "["$2"]"} else {print $2}}' /etc/resolv.conf)
12+
export NGINX_LOCAL_RESOLVERS

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
ME=$(basename $0)
5+
ME=$(basename "$0")
66

77
entrypoint_log() {
88
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
@@ -44,8 +44,8 @@ auto_envsubst() {
4444
return 0
4545
fi
4646
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
47-
relative_path="${template#$template_dir/}"
48-
output_path="$output_dir/${relative_path%$suffix}"
47+
relative_path="${template#"$template_dir/"}"
48+
output_path="$output_dir/${relative_path%"$suffix"}"
4949
subdir=$(dirname "$relative_path")
5050
# create a subdirectory where the template file exists
5151
mkdir -p "$output_dir/$subdir"
@@ -62,8 +62,8 @@ auto_envsubst() {
6262
fi
6363
add_stream_block
6464
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}"
65+
relative_path="${template#"$template_dir/"}"
66+
output_path="$stream_output_dir/${relative_path%"$stream_suffix"}"
6767
subdir=$(dirname "$relative_path")
6868
# create a subdirectory where the template file exists
6969
mkdir -p "$stream_output_dir/$subdir"

mainline/debian/30-tune-worker-processes.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -eu
55

66
LC_ALL=C
7-
ME=$( basename "$0" )
7+
ME=$(basename "$0")
88
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
99

1010
[ "${NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE:-}" ] || exit 0

mainline/debian/docker-entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
12+
if [ "$1" = "nginx" ] || [ "$1" = "nginx-debug" ]; then
1313
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
1414
entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
1515

stable/alpine-slim/10-listen-on-ipv6-by-default.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
ME=$(basename $0)
12+
ME=$(basename "$0")
1313
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"
1414

1515
# check if we have ipv6 available

stable/alpine-slim/15-local-resolvers.envsh

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
88

99
[ "${NGINX_ENTRYPOINT_LOCAL_RESOLVERS:-}" ] || return 0
1010

11-
export NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
11+
NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {if ($2 ~ ":") {print "["$2"]"} else {print $2}}' /etc/resolv.conf)
12+
export NGINX_LOCAL_RESOLVERS

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
ME=$(basename $0)
5+
ME=$(basename "$0")
66

77
entrypoint_log() {
88
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
@@ -44,8 +44,8 @@ auto_envsubst() {
4444
return 0
4545
fi
4646
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
47-
relative_path="${template#$template_dir/}"
48-
output_path="$output_dir/${relative_path%$suffix}"
47+
relative_path="${template#"$template_dir/"}"
48+
output_path="$output_dir/${relative_path%"$suffix"}"
4949
subdir=$(dirname "$relative_path")
5050
# create a subdirectory where the template file exists
5151
mkdir -p "$output_dir/$subdir"
@@ -62,8 +62,8 @@ auto_envsubst() {
6262
fi
6363
add_stream_block
6464
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}"
65+
relative_path="${template#"$template_dir/"}"
66+
output_path="$stream_output_dir/${relative_path%"$stream_suffix"}"
6767
subdir=$(dirname "$relative_path")
6868
# create a subdirectory where the template file exists
6969
mkdir -p "$stream_output_dir/$subdir"

stable/alpine-slim/30-tune-worker-processes.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -eu
55

66
LC_ALL=C
7-
ME=$( basename "$0" )
7+
ME=$(basename "$0")
88
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
99

1010
[ "${NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE:-}" ] || exit 0

stable/alpine-slim/docker-entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
12+
if [ "$1" = "nginx" ] || [ "$1" = "nginx-debug" ]; then
1313
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
1414
entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
1515

stable/debian/10-listen-on-ipv6-by-default.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
ME=$(basename $0)
12+
ME=$(basename "$0")
1313
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"
1414

1515
# check if we have ipv6 available

stable/debian/15-local-resolvers.envsh

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
88

99
[ "${NGINX_ENTRYPOINT_LOCAL_RESOLVERS:-}" ] || return 0
1010

11-
export NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
11+
NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {if ($2 ~ ":") {print "["$2"]"} else {print $2}}' /etc/resolv.conf)
12+
export NGINX_LOCAL_RESOLVERS

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
ME=$(basename $0)
5+
ME=$(basename "$0")
66

77
entrypoint_log() {
88
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
@@ -44,8 +44,8 @@ auto_envsubst() {
4444
return 0
4545
fi
4646
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
47-
relative_path="${template#$template_dir/}"
48-
output_path="$output_dir/${relative_path%$suffix}"
47+
relative_path="${template#"$template_dir/"}"
48+
output_path="$output_dir/${relative_path%"$suffix"}"
4949
subdir=$(dirname "$relative_path")
5050
# create a subdirectory where the template file exists
5151
mkdir -p "$output_dir/$subdir"
@@ -62,8 +62,8 @@ auto_envsubst() {
6262
fi
6363
add_stream_block
6464
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}"
65+
relative_path="${template#"$template_dir/"}"
66+
output_path="$stream_output_dir/${relative_path%"$stream_suffix"}"
6767
subdir=$(dirname "$relative_path")
6868
# create a subdirectory where the template file exists
6969
mkdir -p "$stream_output_dir/$subdir"

stable/debian/30-tune-worker-processes.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -eu
55

66
LC_ALL=C
7-
ME=$( basename "$0" )
7+
ME=$(basename "$0")
88
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
99

1010
[ "${NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE:-}" ] || exit 0

stable/debian/docker-entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entrypoint_log() {
99
fi
1010
}
1111

12-
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
12+
if [ "$1" = "nginx" ] || [ "$1" = "nginx-debug" ]; then
1313
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
1414
entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
1515

0 commit comments

Comments
 (0)