Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new nginx version and update module build process #2

Open
wants to merge 114 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
3b108b5
Updated mainline nginx to 1.15.3 and njs to 0.2.3.
thresheek Aug 28, 2018
f3fc4d5
downgrade to gnupg1
Sep 14, 2018
866b071
Updated mainline nginx to 1.15.4 and njs to 0.2.4.
thresheek Sep 25, 2018
3c446ad
Update Alpine to 3.8.
thresheek Sep 25, 2018
a22b9f4
Updated mainline nginx to 1.15.5.
thresheek Oct 2, 2018
f4d3014
Updated mainline nginx to 1.15.6, stable to 1.14.1 and njs to 0.2.5.
thresheek Nov 6, 2018
1fe92b8
Updated mainline nginx to 1.15.7 and njs to 0.2.6.
thresheek Nov 27, 2018
b71469a
Updated stable nginx to 1.14.2 and njs to 0.2.6.
thresheek Dec 5, 2018
baa050d
Updated mainline nginx to 1.15.8 and njs to 0.2.7.
thresheek Dec 25, 2018
2364fdc
Update to Alpine 3.9
J0WI Jan 29, 2019
7890fc2
Updated mainline nginx to 1.15.9 and njs to 0.2.8
thresheek Feb 27, 2019
97b6511
Updated mainline nginx to 1.15.10 and njs to 0.3.0
thresheek Mar 26, 2019
7d7c67f
Updated mainline nginx to 1.15.11
thresheek Apr 9, 2019
e5123ee
Updated mainline nginx to 1.15.12 and njs to 0.3.1
thresheek Apr 16, 2019
0501f0b
alpine: use nginx.org-provided packages.
thresheek Mar 11, 2019
42b9a87
mainline: get rid of duplication in variables versions
thresheek Apr 23, 2019
9a052e0
Updated stable nginx to 1.16.0
thresheek Apr 23, 2019
61973ac
Updated generate-stackbrew-library.sh
thresheek Apr 23, 2019
6f41f97
Updated generate-stackbrew-library.sh to use new versioning scheme
thresheek Apr 23, 2019
9674d10
Updated mainline nginx to 1.17.0 and njs to 0.3.2
thresheek May 21, 2019
c308ce3
Updated njs for stable images to 0.3.2
thresheek May 21, 2019
b749353
Made the UID/GID consistent throughout the variants.
thresheek Jun 4, 2019
0e47be3
Remove dash from su command
alessfg Jun 6, 2019
c10dfd0
Change tabs to spaces
alessfg Jun 6, 2019
1ebbaf6
stable alpine: ping to revision 417 of http://hg.nginx.org/pkg-oss.
thresheek Jun 7, 2019
011ca42
Fetch Alpine package over https
J0WI Jun 20, 2019
17c4abd
Fix typo in README.md
surjikal Jun 30, 2019
976f38e
Remove curl dependency from Alpine varaint
J0WI Jun 24, 2019
f9fbfcb
Updated nginx to 1.17.1 and njs to 0.3.3
thresheek Jul 1, 2019
5abbd4a
Update Alpine to 3.10
J0WI Jun 20, 2019
7956a3f
Upgrade to Debian Buster
J0WI Jul 10, 2019
c817e28
Updated mainline nginx to 1.17.2
thresheek Jul 23, 2019
952de68
Updated nginx to 1.17.3 and njs to 0.3.4
defanator Aug 15, 2019
f5a5bc9
Updated stable nginx to 1.16.1 and njs to 0.3.4
bdossantos Aug 15, 2019
e3bbc11
Updated njs to 0.3.5
defanator Aug 15, 2019
0ad6faa
alpine: bump pkg-oss revision to fetch njs 0.3.5 sources
thresheek Aug 27, 2019
23a9904
Updated mainline nginx to 1.17.4
thresheek Sep 24, 2019
fe97d69
Updated nginx to 1.17.5 and njs to 0.3.6
defanator Oct 22, 2019
7413661
alpine: forced installing nginx packages from our repos
thresheek Nov 13, 2019
a973c22
Updated nginx to 1.17.6 and njs to 0.3.7
thresheek Nov 19, 2019
0f2f331
Updated mainline nginx to 1.17.7
thresheek Jan 9, 2020
5971de3
Updated nginx to 1.17.8 and njs to 0.3.8
thresheek Jan 21, 2020
f7738ed
Updated njs to 0.3.8 in stable nginx
thresheek Jan 21, 2020
5c15613
Updated nginx to 1.17.9 and njs to 0.3.9
thresheek Mar 4, 2020
594ce7a
Update nginx to 1.17.10 and Alpine to 3.11
J0WI Apr 14, 2020
cab4f85
Updated stable nginx to 1.18.0
choyri Apr 22, 2020
b6120b1
Updated generate-stackbrew-library.sh
choyri Apr 22, 2020
abef566
Listen on ipv6 by default
thresheek Apr 21, 2020
87f9340
Provide curl inside images to simplify service discovery registration
thresheek Apr 21, 2020
70e4486
Updated njs to 0.4.0
thresheek Apr 23, 2020
8ec60b8
Update supported architectures (fix #405)
J0WI Apr 30, 2020
1acd7f6
Reduced the number of layers in debian-based images
thresheek May 25, 2020
e36b4f5
Introduced entrypoint
thresheek May 26, 2020
47f11ab
Enable ipv6 listens on the containers where ipv6 is detected
thresheek May 26, 2020
cd98e75
Run envsubst on container start to make templating easier
thresheek May 26, 2020
6c7dde5
Updated mainline nginx to 1.19.0 and njs to 0.4.1
thresheek May 26, 2020
41e6b2c
ipv6-listen: deal with edge cases and fixes
thresheek May 28, 2020
383bbaa
20-env-subst: guard against whitespaces in file/folder names
thresheek May 29, 2020
0b607f3
docker-entrypoint: multiple changes
thresheek Jun 1, 2020
2ef3fa6
ipv6-listen: detect if default.conf is writable
thresheek Jun 2, 2020
d8cbd8e
Use /bin/sh in shebang instead of /usr/bin/env
TimWolla Jun 12, 2020
a86ccdc
Add NGINX_ENTRYPOINT_QUIET_LOGS environment variable
alexandresalome Jun 8, 2020
172571e
ipv6 listen: put r/o filesystem alert to stderr
thresheek Jun 17, 2020
6086122
Reworded entrypoint scripts error messages to avoid confusion
thresheek Jun 17, 2020
3dcf654
Fixed typo introduced in 172571e53c1c6dacc86bcef2b09abf91c451bd69
thresheek Jun 18, 2020
ea63c8e
Updated mainline nginx to 1.19.1 and njs to 0.4.2
thresheek Jul 10, 2020
a88587d
Updated njs to 0.4.2 for stable images
thresheek Jul 10, 2020
793319d
Made all entrypoint scripts honour NGINX_ENTRYPOINT_QUIET_LOGS in full
thresheek Jul 10, 2020
9774b52
Update nginx to 1.19.2 and njs to 0.4.3 on mainline images
thresheek Aug 13, 2020
dded647
Updated njs to 0.4.3 on stable images
thresheek Aug 13, 2020
aa41dde
Moved mainline alpine images to 3.12
thresheek Aug 13, 2020
0dc809f
Update nginx version to 1.19.3
Oct 5, 2020
5488180
Updated njs to 0.4.4 on stable images
thresheek Oct 5, 2020
a4208f8
Fix typo in 10-listen-on-ipv6-by-default.sh
gurdiga Aug 31, 2020
aebdace
Update nginx to 1.19.4
J0WI Nov 3, 2020
deff8fb
Fixed njs package versioning
thresheek Nov 5, 2020
d5f4d23
Bump 1.18.0 PKG_RELEASE from 1 to 2
paskal Nov 10, 2020
c84a1a2
Lower the severity of logging messages on ipv6-enabling script.
thresheek Nov 11, 2020
4a6623a
Fixed stable alpine builds on non-amd64
thresheek Nov 12, 2020
56a20ba
Added update script and template to make changes management easier
thresheek Nov 18, 2020
4370fa1
Renegerated targets via update.sh
thresheek Nov 18, 2020
f836ba8
Updated generate-stackbrew-library.sh to pick up naming changes
thresheek Nov 18, 2020
08d37de
debian: don't build arm64 packages since nginx.org provides them now
thresheek Nov 18, 2020
3fb70dd
Use SIGQUIT instead of SIGTERM for graceful shutdown of nginx
pscheid92 Nov 24, 2020
c411fde
Updated mainline nginx to 1.19.5
thresheek Nov 24, 2020
3d618e3
Added a script to simplify images mirroring to AWS ECR
thresheek Dec 4, 2020
14e7394
10-liste-on-ipv6-by-default: use "info" instead of error
thresheek Dec 15, 2020
41156d8
Updated mainline nginx to 1.19.6 and njs to 0.5.0
thresheek Dec 15, 2020
fc5d895
Provided a way to install third-party modules in a sane manner
thresheek Nov 2, 2020
734e1de
Alpine 3.13
J0WI Jan 29, 2021
5c93520
docker-entrypoint: use natural sort for scripts to launch
thresheek Feb 1, 2021
2f28591
README: mentioned nginx.org changelog
thresheek Feb 1, 2021
2b06409
Introduced an entrypoint script to autotune the number of worker proc…
thresheek Nov 25, 2020
fa2213a
Updated nginx to 1.19.7 and njs to 0.5.1 for mainline
thresheek Feb 16, 2021
e559b4d
modules: Added a hack to make build system fetch a requested nginx ve…
thresheek Feb 17, 2021
636b7e3
Updated and improved third-party modules documentation
thresheek Mar 2, 2021
dcaaf66
Updated mainline nginx to 1.19.8 and njs to 0.5.2
thresheek Mar 9, 2021
d1ed2dd
Made 30-tune-worker-processes.sh more robust and error-prone.
thresheek Mar 11, 2021
e7bab21
modules: use the same workaround for Alpine as we had for Debian
thresheek Mar 12, 2021
511c0fe
modules: check out an explicit pkg-oss tag.
thresheek Mar 30, 2021
0f300ed
Updated mainline nginx to 1.19.9 and njs to 0.5.3
thresheek Mar 30, 2021
e129306
modules: strip debian version from PKG_RELEASE
thresheek Apr 7, 2021
464886a
Updated mainline nginx to 1.19.10
thresheek Apr 13, 2021
010bcbf
Alpine template: nginx.org now provides aarch64 packages.
thresheek Apr 20, 2021
ab8516e
Updated stable nginx to 1.20.0
thresheek Apr 20, 2021
1612733
generate-stackbrew-library.sh: bump stable to 1.20
thresheek Apr 21, 2021
be61420
sync-awsecr.sh: bump stable to 1.20
thresheek May 11, 2021
f3fe494
Updated nginx to 1.20.1 and 1.21.0
thresheek May 25, 2021
fe33fad
modules/Dockerfile.alpine: added coreutils to use proper tr
thresheek Jun 2, 2021
6a9fffa
third party: fixed builds with non-alphanumeric characters in module …
thresheek Jun 2, 2021
1c123ec
modules: updated the list of supported modules
thresheek Jun 2, 2021
4fb9623
modules: Dockerfile.alpine: set SETFATTR=true to skip setfattr.
thresheek Jul 2, 2021
f958fba
Updated nginx to 1.21.1 and njs to 0.6.1 on mainline builds.
thresheek Jul 6, 2021
6335484
Merge remote-tracking branch 'origin-nginx/master' into feature/remot…
dima11051994 Aug 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions Dockerfile-alpine.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
FROM alpine:%%ALPINE_VERSION%%

LABEL maintainer="NGINX Docker Maintainers <[email protected]>"

ENV NGINX_VERSION %%NGINX_VERSION%%
ENV NJS_VERSION %%NJS_VERSION%%
ENV PKG_RELEASE %%PKG_RELEASE%%

RUN set -x \
# create nginx user/group first, to be consistent throughout docker variants
&& addgroup -g 101 -S nginx \
&& adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx \
&& apkArch="$(cat /etc/apk/arch)" \
&& nginxPackages="%%PACKAGES%%
" \
&& case "$apkArch" in \
x86_64|aarch64) \
# arches officially built by upstream
set -x \
&& KEY_SHA512="e7fa8303923d9b95db37a77ad46c68fd4755ff935d0a534d26eba83de193c76166c68bfe7f65471bf8881004ef4aa6df3e34689c305662750c0172fca5d8552a *stdin" \
&& apk add --no-cache --virtual .cert-deps \
openssl \
&& wget -O /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub \
&& if [ "$(openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout | openssl sha512 -r)" = "$KEY_SHA512" ]; then \
echo "key verification succeeded!"; \
mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/; \
else \
echo "key verification failed!"; \
exit 1; \
fi \
&& apk del .cert-deps \
&& apk add -X "%%PACKAGEREPO%%v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" --no-cache $nginxPackages \
;; \
*) \
# we're on an architecture upstream doesn't officially build for
# let's build binaries from the published packaging sources
set -x \
&& tempDir="$(mktemp -d)" \
&& chown nobody:nobody $tempDir \
&& apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
make \
openssl-dev \
pcre-dev \
zlib-dev \
linux-headers \
libxslt-dev \
gd-dev \
geoip-dev \
perl-dev \
libedit-dev \
mercurial \
bash \
alpine-sdk \
findutils \
&& su nobody -s /bin/sh -c " \
export HOME=${tempDir} \
&& cd ${tempDir} \
&& hg clone https://hg.nginx.org/pkg-oss \
&& cd pkg-oss \
&& hg up %%REVISION%% \
&& cd alpine \
&& make all \
&& apk index -o ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz ${tempDir}/packages/alpine/${apkArch}/*.apk \
&& abuild-sign -k ${tempDir}/.abuild/abuild-key.rsa ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz \
" \
&& cp ${tempDir}/.abuild/abuild-key.rsa.pub /etc/apk/keys/ \
&& apk del .build-deps \
&& apk add -X ${tempDir}/packages/alpine/ --no-cache $nginxPackages \
;; \
esac \
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
&& if [ -n "$tempDir" ]; then rm -rf "$tempDir"; fi \
&& if [ -n "/etc/apk/keys/abuild-key.rsa.pub" ]; then rm -f /etc/apk/keys/abuild-key.rsa.pub; fi \
&& if [ -n "/etc/apk/keys/nginx_signing.rsa.pub" ]; then rm -f /etc/apk/keys/nginx_signing.rsa.pub; fi \
# Bring in gettext so we can get `envsubst`, then throw
# the rest away. To do this, we need to install `gettext`
# then move `envsubst` out of the way so `gettext` can
# be deleted completely, then move `envsubst` back.
&& apk add --no-cache --virtual .gettext gettext \
&& mv /usr/bin/envsubst /tmp/ \
\
&& runDeps="$( \
scanelf --needed --nobanner /tmp/envsubst \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --no-cache $runDeps \
&& apk del .gettext \
&& mv /tmp/envsubst /usr/local/bin/ \
# Bring in tzdata so users could set the timezones through the environment
# variables
&& apk add --no-cache tzdata \
# Bring in curl and ca-certificates to make registering on DNS SD easier
&& apk add --no-cache curl ca-certificates \
# forward request and error logs to docker log collector
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
# create a docker-entrypoint.d directory
&& mkdir /docker-entrypoint.d

COPY docker-entrypoint.sh /
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
COPY 30-tune-worker-processes.sh /docker-entrypoint.d
ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 80

STOPSIGNAL SIGQUIT

CMD ["nginx", "-g", "daemon off;"]
106 changes: 106 additions & 0 deletions Dockerfile-debian.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
FROM debian:%%DEBIAN_VERSION%%-slim

LABEL maintainer="NGINX Docker Maintainers <[email protected]>"

ENV NGINX_VERSION %%NGINX_VERSION%%
ENV NJS_VERSION %%NJS_VERSION%%
ENV PKG_RELEASE %%PKG_RELEASE%%

RUN set -x \
# create nginx user/group first, to be consistent throughout docker variants
&& addgroup --system --gid 101 nginx \
&& adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx \
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates \
&& \
NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \
found=''; \
for server in \
ha.pool.sks-keyservers.net \
hkp://keyserver.ubuntu.com:80 \
hkp://p80.pool.sks-keyservers.net:80 \
pgp.mit.edu \
; do \
echo "Fetching GPG key $NGINX_GPGKEY from $server"; \
apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \
done; \
test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \
apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \
&& dpkgArch="$(dpkg --print-architecture)" \
&& nginxPackages="%%PACKAGES%%
" \
&& case "$dpkgArch" in \
amd64|i386|arm64) \
# arches officialy built by upstream
echo "deb %%PACKAGEREPO%% %%DEBIAN_VERSION%% nginx" >> /etc/apt/sources.list.d/nginx.list \
&& apt-get update \
;; \
*) \
# we're on an architecture upstream doesn't officially build for
# let's build binaries from the published source packages
echo "deb-src %%PACKAGEREPO%% %%DEBIAN_VERSION%% nginx" >> /etc/apt/sources.list.d/nginx.list \
\
# new directory for storing sources and .deb files
&& tempDir="$(mktemp -d)" \
&& chmod 777 "$tempDir" \
# (777 to ensure APT's "_apt" user can access it too)
\
# save list of currently-installed packages so build dependencies can be cleanly removed later
&& savedAptMark="$(apt-mark showmanual)" \
\
# build .deb files from upstream's source packages (which are verified by apt-get)
&& apt-get update \
&& apt-get build-dep -y $nginxPackages \
&& ( \
cd "$tempDir" \
&& DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \
apt-get source --compile $nginxPackages \
) \
# we don't remove APT lists here because they get re-downloaded and removed later
\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
&& apt-mark showmanual | xargs apt-mark auto > /dev/null \
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
\
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
&& ls -lAFh "$tempDir" \
&& ( cd "$tempDir" && dpkg-scanpackages . > Packages ) \
&& grep '^Package: ' "$tempDir/Packages" \
&& echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list \
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
# ...
# E: Failed to fetch store:/var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
&& apt-get -o Acquire::GzipIndexes=false update \
;; \
esac \
\
&& apt-get install --no-install-recommends --no-install-suggests -y \
$nginxPackages \
gettext-base \
curl \
&& apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \
\
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
&& if [ -n "$tempDir" ]; then \
apt-get purge -y --auto-remove \
&& rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
fi \
# forward request and error logs to docker log collector
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
# create a docker-entrypoint.d directory
&& mkdir /docker-entrypoint.d

COPY docker-entrypoint.sh /
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
COPY 30-tune-worker-processes.sh /docker-entrypoint.d
ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 80

STOPSIGNAL SIGQUIT

CMD ["nginx", "-g", "daemon off;"]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ Currently Added Modules:


The full readme is generated over in [docker-library/docs](https://github.com/docker-library/docs),
specificially in [docker-library/docs/nginx](https://github.com/docker-library/docs/tree/master/nginx).
specifically in [docker-library/docs/nginx](https://github.com/docker-library/docs/tree/master/nginx).

The changelog for NGINX releases is available at [nginx.org changes page](https://nginx.org/en/CHANGES).
61 changes: 61 additions & 0 deletions entrypoint/10-listen-on-ipv6-by-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh
# vim:sw=4:ts=4:et

set -e

ME=$(basename $0)
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"

# check if we have ipv6 available
if [ ! -f "/proc/net/if_inet6" ]; then
echo >&3 "$ME: info: ipv6 not available"
exit 0
fi

if [ ! -f "/$DEFAULT_CONF_FILE" ]; then
echo >&3 "$ME: info: /$DEFAULT_CONF_FILE is not a file or does not exist"
exit 0
fi

# check if the file can be modified, e.g. not on a r/o filesystem
touch /$DEFAULT_CONF_FILE 2>/dev/null || { echo >&3 "$ME: info: can not modify /$DEFAULT_CONF_FILE (read-only file system?)"; exit 0; }

# check if the file is already modified, e.g. on a container restart
grep -q "listen \[::]\:80;" /$DEFAULT_CONF_FILE && { echo >&3 "$ME: info: IPv6 listen already enabled"; exit 0; }

if [ -f "/etc/os-release" ]; then
. /etc/os-release
else
echo >&3 "$ME: info: can not guess the operating system"
exit 0
fi

echo >&3 "$ME: info: Getting the checksum of /$DEFAULT_CONF_FILE"

case "$ID" in
"debian")
CHECKSUM=$(dpkg-query --show --showformat='${Conffiles}\n' nginx | grep $DEFAULT_CONF_FILE | cut -d' ' -f 3)
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | md5sum -c - >/dev/null 2>&1 || {
echo >&3 "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
exit 0
}
;;
"alpine")
CHECKSUM=$(apk manifest nginx 2>/dev/null| grep $DEFAULT_CONF_FILE | cut -d' ' -f 1 | cut -d ':' -f 2)
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | sha1sum -c - >/dev/null 2>&1 || {
echo >&3 "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
exit 0
}
;;
*)
echo >&3 "$ME: info: Unsupported distribution"
exit 0
;;
esac

# enable ipv6 on default.conf listen sockets
sed -i -E 's,listen 80;,listen 80;\n listen [::]:80;,' /$DEFAULT_CONF_FILE

echo >&3 "$ME: info: Enabled listen on IPv6 in /$DEFAULT_CONF_FILE"

exit 0
32 changes: 32 additions & 0 deletions entrypoint/20-envsubst-on-templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

set -e

ME=$(basename $0)

auto_envsubst() {
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"

local template defined_envs relative_path output_path subdir
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
[ -d "$template_dir" ] || return 0
if [ ! -w "$output_dir" ]; then
echo >&3 "$ME: ERROR: $template_dir exists, but $output_dir is not writable"
return 0
fi
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
relative_path="${template#$template_dir/}"
output_path="$output_dir/${relative_path%$suffix}"
subdir=$(dirname "$relative_path")
# create a subdirectory where the template file exists
mkdir -p "$output_dir/$subdir"
echo >&3 "$ME: Running envsubst on $template to $output_path"
envsubst "$defined_envs" < "$template" > "$output_path"
done
}

auto_envsubst

exit 0
Loading