kubedocker commited on
Commit
6814ee7
1 Parent(s): 1a8b17e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +133 -0
Dockerfile CHANGED
@@ -17,6 +17,139 @@ USER user
17
  ENV HOME=/home/user \
18
  PATH=/home/user/.local/bin:$PATH
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  # Set the working directory to the user's home directory
21
  WORKDIR $HOME/app
22
 
 
17
  ENV HOME=/home/user \
18
  PATH=/home/user/.local/bin:$PATH
19
 
20
+ ############### NGINX Unprivileged ###############
21
+
22
+
23
+ ENV NGINX_VERSION 1.26.0
24
+ ENV NJS_VERSION 0.8.4
25
+ ENV NJS_RELEASE 1~bookworm
26
+ ENV PKG_RELEASE 1~bookworm
27
+
28
+ ARG UID=101
29
+ ARG GID=101
30
+
31
+ RUN set -x \
32
+ # create nginx user/group first, to be consistent throughout docker variants
33
+ && groupadd --system --gid $GID nginx || true \
34
+ && useradd --system --gid nginx --no-create-home --home /nonexistent --comment "nginx user" --shell /bin/false --uid $UID nginx || true \
35
+ && apt-get update \
36
+ && apt-get install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates \
37
+ && \
38
+ NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \
39
+ NGINX_GPGKEY_PATH=/etc/apt/keyrings/nginx-archive-keyring.gpg; \
40
+ export GNUPGHOME="$(mktemp -d)"; \
41
+ found=''; \
42
+ for server in \
43
+ hkp://keyserver.ubuntu.com:80 \
44
+ pgp.mit.edu \
45
+ ; do \
46
+ echo "Fetching GPG key $NGINX_GPGKEY from $server"; \
47
+ gpg1 --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \
48
+ done; \
49
+ test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \
50
+ gpg1 --export "$NGINX_GPGKEY" > "$NGINX_GPGKEY_PATH" ; \
51
+ rm -rf "$GNUPGHOME"; \
52
+ apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \
53
+ && dpkgArch="$(dpkg --print-architecture)" \
54
+ && nginxPackages=" \
55
+ nginx=${NGINX_VERSION}-${PKG_RELEASE} \
56
+ nginx-module-xslt=${NGINX_VERSION}-${PKG_RELEASE} \
57
+ nginx-module-geoip=${NGINX_VERSION}-${PKG_RELEASE} \
58
+ nginx-module-image-filter=${NGINX_VERSION}-${PKG_RELEASE} \
59
+ nginx-module-njs=${NGINX_VERSION}+${NJS_VERSION}-${NJS_RELEASE} \
60
+ " \
61
+ && case "$dpkgArch" in \
62
+ amd64|arm64) \
63
+ # arches officialy built by upstream
64
+ echo "deb [signed-by=$NGINX_GPGKEY_PATH] https://nginx.org/packages/debian/ bookworm nginx" >> /etc/apt/sources.list.d/nginx.list \
65
+ && apt-get update \
66
+ ;; \
67
+ *) \
68
+ # we're on an architecture upstream doesn't officially build for
69
+ # let's build binaries from the published source packages
70
+ echo "deb-src [signed-by=$NGINX_GPGKEY_PATH] https://nginx.org/packages/debian/ bookworm nginx" >> /etc/apt/sources.list.d/nginx.list \
71
+ \
72
+ # new directory for storing sources and .deb files
73
+ && tempDir="$(mktemp -d)" \
74
+ && chmod 777 "$tempDir" \
75
+ # (777 to ensure APT's "_apt" user can access it too)
76
+ \
77
+ # save list of currently-installed packages so build dependencies can be cleanly removed later
78
+ && savedAptMark="$(apt-mark showmanual)" \
79
+ \
80
+ # build .deb files from upstream's source packages (which are verified by apt-get)
81
+ && apt-get update \
82
+ && apt-get build-dep -y $nginxPackages \
83
+ && ( \
84
+ cd "$tempDir" \
85
+ && DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \
86
+ apt-get source --compile $nginxPackages \
87
+ ) \
88
+ # we don't remove APT lists here because they get re-downloaded and removed later
89
+ \
90
+ # reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
91
+ # (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
92
+ && apt-mark showmanual | xargs apt-mark auto > /dev/null \
93
+ && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
94
+ \
95
+ # create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
96
+ && ls -lAFh "$tempDir" \
97
+ && ( cd "$tempDir" && dpkg-scanpackages . > Packages ) \
98
+ && grep '^Package: ' "$tempDir/Packages" \
99
+ && echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list \
100
+ # work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
101
+ # Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
102
+ # ...
103
+ # 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)
104
+ && apt-get -o Acquire::GzipIndexes=false update \
105
+ ;; \
106
+ esac \
107
+ \
108
+ && apt-get install --no-install-recommends --no-install-suggests -y \
109
+ $nginxPackages \
110
+ gettext-base \
111
+ curl \
112
+ && apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \
113
+ \
114
+ # if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
115
+ && if [ -n "$tempDir" ]; then \
116
+ apt-get purge -y --auto-remove \
117
+ && rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
118
+ fi \
119
+ # forward request and error logs to docker log collector
120
+ && ln -sf /dev/stdout /var/log/nginx/access.log \
121
+ && ln -sf /dev/stderr /var/log/nginx/error.log \
122
+ # create a docker-entrypoint.d directory
123
+ && mkdir /docker-entrypoint.d
124
+
125
+ # implement changes required to run NGINX as an unprivileged user
126
+ RUN sed -i 's,listen 80;,listen 8080;,' /etc/nginx/conf.d/default.conf \
127
+ && sed -i '/user nginx;/d' /etc/nginx/nginx.conf \
128
+ && sed -i 's,/var/run/nginx.pid,/tmp/nginx.pid,' /etc/nginx/nginx.conf \
129
+ && sed -i "/^http {/a \ proxy_temp_path /tmp/proxy_temp;\n client_body_temp_path /tmp/client_temp;\n fastcgi_temp_path /tmp/fastcgi_temp;\n uwsgi_temp_path /tmp/uwsgi_temp;\n scgi_temp_path /tmp/scgi_temp;\n" /etc/nginx/nginx.conf \
130
+ # nginx user must own the cache and etc directory to write cache and tweak the nginx config
131
+ && chown -R $UID:0 /var/cache/nginx \
132
+ && chmod -R g+w /var/cache/nginx \
133
+ && chown -R $UID:0 /etc/nginx \
134
+ && chmod -R g+w /etc/nginx
135
+
136
+ COPY docker-entrypoint.sh /
137
+ COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
138
+ COPY 15-local-resolvers.envsh /docker-entrypoint.d
139
+ COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
140
+ COPY 30-tune-worker-processes.sh /docker-entrypoint.d
141
+ ENTRYPOINT ["/docker-entrypoint.sh"]
142
+
143
+ EXPOSE 8080
144
+
145
+ STOPSIGNAL SIGQUIT
146
+
147
+ USER $UID
148
+
149
+ CMD ["nginx", "-g", "daemon off;"]
150
+
151
+ ############### NGINX Unprivileged ###############
152
+
153
  # Set the working directory to the user's home directory
154
  WORKDIR $HOME/app
155