Skip to content

Commit a6c8a1e

Browse files
committed
refactor: simplify docker build process
This change does the following: * Migrates to using the official NGINX Plus Docker images as base images * Removes the distinction between BuildKit and non-BuildKit builds for Plus images (OSS never had this) * Adds support for license validation for Plus images * Introduces a multi-stage build for Plus images Signed-off-by: Elijah Zupancic <[email protected]>
1 parent a9847e5 commit a6c8a1e

File tree

11 files changed

+121
-414
lines changed

11 files changed

+121
-414
lines changed

Dockerfile.buildkit.plus

Lines changed: 0 additions & 104 deletions
This file was deleted.

Dockerfile.oss

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
FROM nginx:1.29.0@sha256:f5c017fb33c6db484545793ffb67db51cdd7daebee472104612f73a85063f889
2-
3-
# NJS env vars
4-
ENV NJS_VERSION=0.9.0
5-
ENV NJS_RELEASE=1~bookworm
1+
FROM nginx:1.29.1@sha256:d5f28ef21aabddd098f3dbc21fe5b7a7d7a184720bc07da0b6c9b9820e97f25e
62

73
# Proxy cache env vars
84
ENV PROXY_CACHE_MAX_SIZE=10g
@@ -27,20 +23,20 @@ ENV PREFIX_LEADING_DIRECTORY_PATH=""
2723
# 3. Adding a directory for proxied objects to be stored.
2824
# 4. Replacing the entrypoint script with a modified version that explicitly sets resolvers.
2925

26+
# Note: the PKG_RELEASE environment variable is inherited
27+
3028
RUN set -x \
31-
&& echo "deb [signed-by=/etc/apt/keyrings/nginx-archive-keyring.gpg] https://nginx.org/packages/mainline/debian/ $(echo $PKG_RELEASE | cut -f2 -d~) nginx" >> /etc/apt/sources.list.d/nginx.list; \
32-
apt-get update \
29+
&& echo "deb [signed-by=/etc/apt/keyrings/nginx-archive-keyring.gpg] https://nginx.org/packages/mainline/debian/ $(echo $PKG_RELEASE | cut -f2 -d~) nginx" >> /etc/apt/sources.list.d/nginx.list \
30+
&& apt-get update \
3331
&& apt-get install --no-install-recommends --no-install-suggests -y \
34-
libedit2 \
35-
nginx-module-njs=${NGINX_VERSION}+${NJS_VERSION}-${NJS_RELEASE} \
36-
&& apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list
32+
libedit2 nginx-module-njs nginx-module-xslt \
33+
&& apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/*
3734

38-
COPY oss/etc /etc
35+
COPY oss/etc/nginx /etc/nginx
3936
COPY common/etc /etc
40-
COPY common/docker-entrypoint.sh /docker-entrypoint.sh
4137
COPY common/docker-entrypoint.d /docker-entrypoint.d/
4238

4339
RUN set -x \
4440
&& mkdir -p /var/cache/nginx/s3_proxy \
4541
&& chown nginx:nginx /var/cache/nginx/s3_proxy \
46-
&& chmod -R -v +x /docker-entrypoint.sh /docker-entrypoint.d/*.sh;
42+
&& find /docker-entrypoint.d -type f \( -name '*.sh' -or -name '*.envsh' \) -exec chmod -v +x {} \;

Dockerfile.plus

Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
FROM debian:bookworm-slim@sha256:b1211f6d19afd012477bd34fdcabb6b663d680e0f4b0537da6e6b0fd057a3ec3
1+
# Pull from NGINX image that provides the XSLT module and supporting libraries
2+
FROM private-registry.nginx.com/nginx-plus/modules:r35-xslt-debian@sha256:3eaa85dca47e31b9a6648bcaf6034f076cd59be9b1510b25fd1bbe1144f0bb48 AS xslt
23

3-
# Create RELEASE argument
4-
ARG RELEASE=bookworm
5-
6-
# NJS env vars
7-
ENV NGINX_VERSION=34
8-
ENV NGINX_PKG_RELEASE=1~${RELEASE}
9-
ENV NJS_VERSION=0.9.0
10-
ENV NJS_PKG_RELEASE=1~${RELEASE}
4+
FROM private-registry.nginx.com/nginx-plus/base:r35-debian-bookworm@sha256:9a82ad3f96d58be861257efd621f215d599e226ebedd24d9f3211bdd743c3c27
115

126
# Proxy cache env vars
137
ENV PROXY_CACHE_MAX_SIZE=10g
@@ -26,76 +20,25 @@ ENV DIRECTORY_LISTING_PATH_PREFIX=""
2620
ENV STRIP_LEADING_DIRECTORY_PATH=""
2721
ENV PREFIX_LEADING_DIRECTORY_PATH=""
2822

29-
# We create an NGINX Plus image based on the official NGINX Plus Dockerfiles (https://gist.github.com/nginx-gists/36e97fc87efb5cf0039978c8e41a34b5) and modify it by:
30-
# 1. Explicitly installing the version of njs coded in the environment variable above.
31-
# 2. Adding configuration files needed for proxying private S3 buckets.
32-
# 3. Adding a directory for proxied objects to be stored.
33-
# 4. Adding the entrypoint scripts found in the base NGINX OSS Docker image with a modified version that explicitly sets resolvers.
34-
35-
# Download your NGINX license certificate and key from the F5 customer portal (https://account.f5.com) and copy it to the build context
36-
COPY plus/etc/ssl /etc/ssl
37-
38-
RUN set -x \
39-
# Create nginx user/group first, to be consistent throughout Docker variants
40-
&& groupadd --system --gid 101 nginx \
41-
&& useradd --system --gid nginx --no-create-home --home /nonexistent --comment "nginx user" --shell /bin/false --uid 101 nginx \
42-
&& apt-get update \
43-
&& apt-get install --no-install-recommends --no-install-suggests -y ca-certificates gnupg1 lsb-release \
44-
&& \
45-
NGINX_GPGKEYS="573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 8540A6F18833A80E9C1653A42FD21310B49F6B46 9E9BE90EACBCDE69FE9B204CBCDCD8A38D88A2B3"; \
46-
NGINX_GPGKEY_PATH=/etc/apt/keyrings/nginx-archive-keyring.gpg; \
47-
export GNUPGHOME="$(mktemp -d)"; \
48-
found=''; \
49-
for NGINX_GPGKEY in $NGINX_GPGKEYS; do \
50-
for server in \
51-
hkp://keyserver.ubuntu.com:80 \
52-
pgp.mit.edu \
53-
; do \
54-
echo "Fetching GPG key $NGINX_GPGKEY from $server"; \
55-
gpg1 --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \
56-
done; \
57-
test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \
58-
done; \
59-
gpg1 --export $NGINX_GPGKEYS > "$NGINX_GPGKEY_PATH" ; \
60-
rm -rf "$GNUPGHOME"; \
61-
apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \
62-
# Install the latest release of NGINX Plus and/or NGINX Plus modules (written and maintained by F5)
63-
&& nginxPackages=" \
64-
nginx-plus=${NGINX_VERSION}-${NGINX_PKG_RELEASE} \
65-
nginx-plus-module-njs=${NGINX_VERSION}+${NJS_VERSION}-${NJS_PKG_RELEASE} \
66-
nginx-plus-module-xslt=${NGINX_VERSION}-${NGINX_PKG_RELEASE} \
67-
" \
68-
&& echo "Acquire::https::pkgs.nginx.com::Verify-Peer \"true\";" > /etc/apt/apt.conf.d/90nginx \
69-
&& echo "Acquire::https::pkgs.nginx.com::Verify-Host \"true\";" >> /etc/apt/apt.conf.d/90nginx \
70-
&& echo "Acquire::https::pkgs.nginx.com::SslCert \"/etc/ssl/nginx/nginx-repo.crt\";" >> /etc/apt/apt.conf.d/90nginx \
71-
&& echo "Acquire::https::pkgs.nginx.com::SslKey \"/etc/ssl/nginx/nginx-repo.key\";" >> /etc/apt/apt.conf.d/90nginx \
72-
&& echo "deb [signed-by=$NGINX_GPGKEY_PATH] https://pkgs.nginx.com/plus/debian `lsb_release -cs` nginx-plus\n" > /etc/apt/sources.list.d/nginx-plus.list \
73-
&& apt-get update \
74-
&& apt-get install --no-install-recommends --no-install-suggests -y $nginxPackages curl gettext-base \
75-
&& apt-get remove --purge -y lsb-release \
76-
&& apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx-plus.list \
77-
&& rm -rf /etc/apt/apt.conf.d/90nginx /etc/ssl/nginx \
78-
# Forward request logs to Docker log collector
79-
&& ln -sf /dev/stdout /var/log/nginx/access.log \
80-
&& ln -sf /dev/stderr /var/log/nginx/error.log
81-
82-
EXPOSE 80
83-
84-
STOPSIGNAL SIGTERM
85-
86-
CMD ["nginx", "-g", "daemon off;"]
87-
8823
# Copy files from the OSS NGINX Docker container such that the container
8924
# startup is the same.
25+
COPY --from=xslt /usr/lib/nginx/ /usr/lib/nginx/
26+
9027
COPY plus/etc/nginx /etc/nginx
9128
COPY common/etc /etc
92-
COPY common/docker-entrypoint.sh /docker-entrypoint.sh
9329
COPY common/docker-entrypoint.d /docker-entrypoint.d/
94-
COPY plus/docker-entrypoint.d /docker-entrypoint.d/
95-
96-
RUN set -x \
97-
&& mkdir -p /var/cache/nginx/s3_proxy \
98-
&& chown nginx:nginx /var/cache/nginx/s3_proxy \
99-
&& chmod -R -v +x /docker-entrypoint.sh /docker-entrypoint.d/*.sh;
10030

101-
ENTRYPOINT ["/docker-entrypoint.sh"]
31+
RUN <<EOF
32+
set -eux
33+
apt-get update -qq
34+
apt-get install --no-install-recommends --no-install-suggests -y \
35+
gettext-base libxml2 libxslt1.1
36+
apt-get remove --purge --auto-remove -y
37+
rm -rf /usr/share/doc/ /usr/share/lintian /var/lib/apt/lists
38+
39+
cat /etc/nginx/nginx-license.conf >> /etc/nginx/nginx.conf; \
40+
rm /etc/nginx/nginx-license.conf; \
41+
mkdir -p /var/cache/nginx/s3_proxy; \
42+
chown nginx:nginx /var/cache/nginx/s3_proxy; \
43+
find /docker-entrypoint.d -type f \( -name '*.sh' -or -name '*.envsh' \) -exec chmod -v +x {} \;
44+
EOF

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,3 @@ fi
130130
if [ $failed -gt 0 ]; then
131131
exit 1
132132
fi
133-
134-
echo "S3 Backend Environment"
135-
echo "Service: ${S3_SERVICE:-s3}"
136-
echo "Access Key ID: ${AWS_ACCESS_KEY_ID}"
137-
echo "Origin: ${S3_SERVER_PROTO}://${S3_BUCKET_NAME}.${S3_SERVER}:${S3_SERVER_PORT}"
138-
echo "Region: ${S3_REGION}"
139-
echo "Addressing Style: ${S3_STYLE}"
140-
echo "AWS Signatures Version: v${AWS_SIGS_VERSION}"
141-
echo "DNS Resolvers: ${DNS_RESOLVERS}"
142-
echo "Directory Listing Enabled: ${ALLOW_DIRECTORY_LIST}"
143-
echo "Directory Listing Path Prefix: ${DIRECTORY_LISTING_PATH_PREFIX}"
144-
echo "Provide Index Pages Enabled: ${PROVIDE_INDEX_PAGE}"
145-
echo "Append slash for directory enabled: ${APPEND_SLASH_FOR_POSSIBLE_DIRECTORY}"
146-
echo "Stripping the following headers from responses: x-amz-;${HEADER_PREFIXES_TO_STRIP}"
147-
echo "Allow the following headers from responses (these take precedence over the above): ${HEADER_PREFIXES_ALLOWED}"
148-
echo "CORS Enabled: ${CORS_ENABLED}"
149-
echo "CORS Allow Private Network Access: ${CORS_ALLOW_PRIVATE_NETWORK_ACCESS}"
150-
echo "Proxy cache using stale setting: ${PROXY_CACHE_USE_STALE}"
Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/bash
1+
#!/bin/sh
22
#
33
# Copyright 2020 F5 Networks
44
#
@@ -15,9 +15,7 @@
1515
# limitations under the License.
1616
#
1717

18-
# vim:sw=4:ts=4:et
19-
20-
set -e
18+
set -eu
2119

2220
parseBoolean() {
2321
case "$1" in
@@ -31,7 +29,7 @@ parseBoolean() {
3129
}
3230

3331
# This line is an addition to the NGINX Docker image's entrypoint script.
34-
if [ -z ${DNS_RESOLVERS+x} ]; then
32+
if [ "${DNS_RESOLVERS+x}" = "" ]; then
3533
resolvers=""
3634

3735
# This method of pulling individual nameservers from
@@ -46,31 +44,33 @@ if [ -z ${DNS_RESOLVERS+x} ]; then
4644
resolvers="$resolvers $ip"
4745
fi
4846
done
49-
export DNS_RESOLVERS="${resolvers}"
47+
DNS_RESOLVERS="${resolvers}"
48+
export DNS_RESOLVERS
5049
fi
5150

5251
# Normalize the CORS_ENABLED environment variable to a numeric value
5352
# so that it can be easily parsed in the nginx configuration.
54-
export CORS_ENABLED="$(parseBoolean "${CORS_ENABLED}")"
53+
CORS_ENABLED="$(parseBoolean "${CORS_ENABLED}")"
54+
export CORS_ENABLED
5555

5656
# By enabling CORS, we also need to enable the OPTIONS method which
5757
# is not normally used as part of the gateway. The following variable
5858
# defines the set of acceptable headers.
59-
if [ "${CORS_ENABLED}" == "1" ]; then
59+
if [ "${CORS_ENABLED}" = "1" ]; then
6060
export LIMIT_METHODS_TO="GET HEAD OPTIONS"
6161
export LIMIT_METHODS_TO_CSV="GET, HEAD, OPTIONS"
6262
else
6363
export LIMIT_METHODS_TO="GET HEAD"
6464
export LIMIT_METHODS_TO_CSV="GET, HEAD"
6565
fi
6666

67-
if [ -z "${CORS_ALLOWED_ORIGIN+x}" ]; then
67+
if [ "${CORS_ALLOWED_ORIGIN+x}" = "" ]; then
6868
export CORS_ALLOWED_ORIGIN="*"
6969
fi
7070

7171
# See documentation for this feature. We do not parse this as a boolean
7272
# since "true" and "false" are the required values of the header this populates
73-
if [ "${CORS_ALLOW_PRIVATE_NETWORK_ACCESS}" != "true" ] && [ "${CORS_ALLOW_PRIVATE_NETWORK_ACCESS}" != "false" ]; then
73+
if [ "${CORS_ALLOW_PRIVATE_NETWORK_ACCESS+x}" != "true" ] && [ "${CORS_ALLOW_PRIVATE_NETWORK_ACCESS+x}" != "false" ]; then
7474
export CORS_ALLOW_PRIVATE_NETWORK_ACCESS=""
7575
fi
7676

@@ -83,10 +83,10 @@ fi
8383

8484
# S3_UPSTREAM needs the port specified. The port must
8585
# correspond to https/http in the proxy_pass directive.
86-
if [ "${S3_STYLE}" == "virtual-v2" ]; then
86+
if [ "${S3_STYLE}" = "virtual-v2" ]; then
8787
export S3_UPSTREAM="${S3_BUCKET_NAME}.${S3_SERVER}:${S3_SERVER_PORT}"
8888
export S3_HOST_HEADER="${S3_BUCKET_NAME}.${S3_SERVER}:${S3_SERVER_PORT}"
89-
elif [ "${S3_STYLE}" == "path" ]; then
89+
elif [ "${S3_STYLE}" = "path" ]; then
9090
export S3_UPSTREAM="${S3_SERVER}:${S3_SERVER_PORT}"
9191
export S3_HOST_HEADER="${S3_SERVER}:${S3_SERVER_PORT}"
9292
else
@@ -95,42 +95,6 @@ else
9595
fi
9696

9797
# Use default proxy_cache_use_stale settings if the variable is not defined
98-
if [[ ! -v PROXY_CACHE_USE_STALE ]]; then
98+
if [ "${PROXY_CACHE_USE_STALE+x}" = "" ]; then
9999
export PROXY_CACHE_USE_STALE="error timeout http_500 http_502 http_503 http_504"
100100
fi
101-
102-
# Nothing is modified under this line
103-
104-
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
105-
exec 3>&1
106-
else
107-
exec 3>/dev/null
108-
fi
109-
110-
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
111-
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
112-
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
113-
114-
echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
115-
find "/docker-entrypoint.d/" -follow -type f -print | sort -n | while read -r f; do
116-
case "$f" in
117-
*.sh)
118-
if [ -x "$f" ]; then
119-
echo >&3 "$0: Launching $f";
120-
"$f"
121-
else
122-
# warn on shell scripts without exec bit
123-
echo >&3 "$0: Ignoring $f, not executable";
124-
fi
125-
;;
126-
*) echo >&3 "$0: Ignoring $f";;
127-
esac
128-
done
129-
130-
echo >&3 "$0: Configuration complete; ready for start up"
131-
else
132-
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
133-
fi
134-
fi
135-
136-
exec "$@"

0 commit comments

Comments
 (0)