|
| 1 | +FROM nginx:%%NGINX_VERSION%% |
| 2 | + |
| 3 | +RUN set -x \ |
| 4 | + && apt-get update \ |
| 5 | + && apt-get install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates \ |
| 6 | + && \ |
| 7 | + NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \ |
| 8 | + found=''; \ |
| 9 | + for server in \ |
| 10 | + hkp://keyserver.ubuntu.com:80 \ |
| 11 | + pgp.mit.edu \ |
| 12 | + ; do \ |
| 13 | + echo "Fetching GPG key $NGINX_GPGKEY from $server"; \ |
| 14 | + apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \ |
| 15 | + done; \ |
| 16 | + test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \ |
| 17 | + apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \ |
| 18 | + && dpkgArch="$(dpkg --print-architecture)" \ |
| 19 | + && nginxPackages="%%PACKAGES%% |
| 20 | + " \ |
| 21 | + && case "$dpkgArch" in \ |
| 22 | + amd64|arm64) \ |
| 23 | +# arches officialy built by upstream |
| 24 | + echo "deb %%PACKAGEREPO%% %%DEBIAN_VERSION%% nginx" >> /etc/apt/sources.list.d/nginx.list \ |
| 25 | + && apt-get update \ |
| 26 | + ;; \ |
| 27 | + *) \ |
| 28 | +# we're on an architecture upstream doesn't officially build for |
| 29 | +# let's build binaries from the published source packages |
| 30 | + echo "deb-src %%PACKAGEREPO%% %%DEBIAN_VERSION%% nginx" >> /etc/apt/sources.list.d/nginx.list \ |
| 31 | + \ |
| 32 | +# new directory for storing sources and .deb files |
| 33 | + && tempDir="$(mktemp -d)" \ |
| 34 | + && chmod 777 "$tempDir" \ |
| 35 | +# (777 to ensure APT's "_apt" user can access it too) |
| 36 | + \ |
| 37 | +# save list of currently-installed packages so build dependencies can be cleanly removed later |
| 38 | + && savedAptMark="$(apt-mark showmanual)" \ |
| 39 | + \ |
| 40 | +# build .deb files from upstream's source packages (which are verified by apt-get) |
| 41 | + && apt-get update \ |
| 42 | + && apt-get build-dep -y %%BUILDTARGET%% \ |
| 43 | + && ( \ |
| 44 | + cd "$tempDir" \ |
| 45 | + && DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \ |
| 46 | + apt-get source --compile %%BUILDTARGET%% \ |
| 47 | + ) \ |
| 48 | +# we don't remove APT lists here because they get re-downloaded and removed later |
| 49 | + \ |
| 50 | +# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies |
| 51 | +# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies) |
| 52 | + && apt-mark showmanual | xargs apt-mark auto > /dev/null \ |
| 53 | + && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \ |
| 54 | + \ |
| 55 | +# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be) |
| 56 | + && ls -lAFh "$tempDir" \ |
| 57 | + && ( cd "$tempDir" && dpkg-scanpackages . > Packages ) \ |
| 58 | + && grep '^Package: ' "$tempDir/Packages" \ |
| 59 | + && echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list \ |
| 60 | +# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes") |
| 61 | +# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied) |
| 62 | +# ... |
| 63 | +# 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) |
| 64 | + && apt-get -o Acquire::GzipIndexes=false update \ |
| 65 | + ;; \ |
| 66 | + esac \ |
| 67 | + \ |
| 68 | + && apt-get install --no-install-recommends --no-install-suggests -y \ |
| 69 | + $nginxPackages \ |
| 70 | + gettext-base \ |
| 71 | + curl \ |
| 72 | + && apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \ |
| 73 | + \ |
| 74 | +# if we have leftovers from building, let's purge them (including extra, unnecessary build deps) |
| 75 | + && if [ -n "$tempDir" ]; then \ |
| 76 | + apt-get purge -y --auto-remove \ |
| 77 | + && rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \ |
| 78 | + fi |
0 commit comments