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