Skip to content

Commit e9f5912

Browse files
committed
Fixes #2
DNS resolvers can now be set explicitly with the DNS_RESOLVERS environment variable. If not explicitly set, the instance will be configured to use the resolvers in `/etc/resolve.conf`.
1 parent c347fe7 commit e9f5912

File tree

7 files changed

+21
-9
lines changed

7 files changed

+21
-9
lines changed

Dockerfile.oss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ ENV HEADERS_MORE_VERSION "v0.33"
77
# 1. Installing the headers-more module
88
# 2. Adding configuration files needed for proxying private S3 buckets
99
# 3. Adding a directory for proxied objects to be stored
10+
# 4. Replacing the entrypoint script with a modified version that explicitly
11+
# sets resolvers.
1012

1113
RUN set -eux \
1214
export DEBIAN_FRONTEND=noninteractive; \
@@ -43,11 +45,12 @@ RUN set -eux \
4345
rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/*
4446

4547
COPY common/etc /etc
48+
COPY common/docker-entrypoint.sh /docker-entrypoint.sh
4649
COPY common/docker-entrypoint.d/00-check-for-required-env.sh /docker-entrypoint.d/00-check-for-required-env.sh
4750
COPY oss/etc /etc
4851

4952
RUN set -eux \
5053
export DEBIAN_FRONTEND=noninteractive; \
5154
mkdir -p /var/cache/nginx/s3_proxy; \
5255
chown nginx:nginx /var/cache/nginx/s3_proxy; \
53-
chmod -R +x /docker-entrypoint.d/*
56+
chmod -R -v +x /docker-entrypoint.sh /docker-entrypoint.d/*.sh

Dockerfile.plus

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ COPY plus/usr /usr
1414
# Copy files from the OSS NGINX Docker container such that the container
1515
# startup is the same.
1616
# Source: https://github.com/nginxinc/docker-nginx/tree/1.19.2/stable/buster
17-
COPY plus/docker-entrypoint.sh /docker-entrypoint.sh
17+
COPY common/docker-entrypoint.sh /docker-entrypoint.sh
1818
COPY plus/docker-entrypoint.d /docker-entrypoint.d
1919

2020
RUN set -eux \

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ docker build -f Dockerfile.plus -t nginx-plus-s3-gateway --build-arg NGINX_GPGKE
5252

5353
Environment variables are used to configure this project.
5454

55-
* `AWS_SIGS_VERSION` - AWS Signatures API version - either 2 or 4 (4 is default)
55+
* `AWS_SIGS_VERSION` - AWS Signatures API version - either 2 or 4 (4 is default)
56+
* `DNS_RESOLVERS` - (optional) DNS resolvers (separated by single spaces) to configure NGINX with
5657
* `S3_ACCESS_KEY_ID` - Access key
5758
* `S3_BUCKET_NAME` - Name of S3 bucket to proxy requests to
5859
* `S3_DEBUG` - Flag (true/false) enabling AWS signatures debug output (default: false)

common/docker-entrypoint.d/00-check-for-required-env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,4 @@ echo "Access Key ID: ${S3_ACCESS_KEY_ID}"
8181
echo "Origin: ${S3_SERVER_PROTO}://${S3_BUCKET_NAME}.${S3_SERVER}:${S3_SERVER_PORT}"
8282
echo "Region: ${S3_REGION}"
8383
echo "AWS Signatures Version: v${AWS_SIGS_VERSION}"
84+
echo "DNS Resolvers: ${DNS_RESOLVERS}"

plus/docker-entrypoint.sh renamed to common/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919

2020
set -e
2121

22+
# This line is an addition to the NGINX Docker image's entrypoint script.
23+
if [ -z ${DNS_RESOLVERS+x} ]; then
24+
export DNS_RESOLVERS="$(cat /etc/resolv.conf | grep nameserver | cut -d' ' -f2 | xargs)"
25+
fi
26+
27+
# Nothing is modified under this line
28+
2229
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
2330
exec 3>&1
2431
else

oss/etc/nginx/templates/upstreams.conf.template

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# Use NGINX's non-blocking DNS resolution
2+
resolver ${DNS_RESOLVERS};
3+
14
upstream storage_urls {
2-
# Upstreams are not refrshed until NGINX configuration is reloaded.
5+
# Upstreams are not refreshed until NGINX configuration is reloaded.
36
# NGINX Plus will dynamically reload upstreams when DNS records are changed.
47

58
# Be sure to specify the port in the S3_SERVER and be sure that port

plus/etc/nginx/templates/upstreams.conf.template

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# This configuration with NGINX Plus should dynamically reload S3 backends
22
# as they change in DNS.
33

4-
# Docker DNS server IP
5-
resolver 127.0.0.11;
6-
7-
# Public DNS
8-
#resolver 1.1.1.1 8.8.8.8;
4+
# Use NGINX's non-blocking DNS resolution
5+
resolver ${DNS_RESOLVERS};
96

107
upstream storage_urls {
118
zone s3_backends 64k;

0 commit comments

Comments
 (0)