Skip to content

Commit 7f47582

Browse files
committed
feat: Add Dockerfile for OTEL enabled container images
1 parent 0db8e3b commit 7f47582

File tree

7 files changed

+591
-8
lines changed

7 files changed

+591
-8
lines changed

Dockerfile-alpine-otel.template

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
ARG IMAGE=nginxinc/nginx-unprivileged:%%NGINX_VERSION%%-alpine
2+
FROM $IMAGE
3+
4+
ARG UID=101
5+
ARG GID=101
6+
7+
USER root
8+
9+
ENV OTEL_VERSION=%%OTEL_VERSION%%
10+
11+
RUN set -x \
12+
&& apkArch="$(cat /etc/apk/arch)" \
13+
&& nginxPackages="%%PACKAGES%%
14+
" \
15+
# install prerequisites for public key and pkg-oss checks
16+
&& apk add --no-cache --virtual .checksum-deps \
17+
openssl \
18+
&& case "$apkArch" in \
19+
x86_64|aarch64) \
20+
# arches officially built by upstream
21+
apk add -X "%%PACKAGEREPO%%v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" --no-cache $nginxPackages \
22+
;; \
23+
*) \
24+
# we're on an architecture upstream doesn't officially build for
25+
# let's build binaries from the published packaging sources
26+
set -x \
27+
&& tempDir="$(mktemp -d)" \
28+
&& chown nobody:nobody $tempDir \
29+
&& apk add --no-cache --virtual .build-deps \
30+
gcc \
31+
libc-dev \
32+
make \
33+
openssl-dev \
34+
pcre2-dev \
35+
zlib-dev \
36+
linux-headers \
37+
cmake \
38+
bash \
39+
alpine-sdk \
40+
findutils \
41+
curl \
42+
xz \
43+
protobuf-dev \
44+
grpc-dev \
45+
&& su nobody -s /bin/sh -c " \
46+
export HOME=${tempDir} \
47+
&& cd ${tempDir} \
48+
&& curl -f -L -O https://github.com/nginx/pkg-oss/archive/%%REVISION%%.tar.gz \
49+
&& PKGOSSCHECKSUM=\"%%PKGOSSCHECKSUM%% *%%REVISION%%.tar.gz\" \
50+
&& if [ \"\$(openssl sha512 -r %%REVISION%%.tar.gz)\" = \"\$PKGOSSCHECKSUM\" ]; then \
51+
echo \"pkg-oss tarball checksum verification succeeded!\"; \
52+
else \
53+
echo \"pkg-oss tarball checksum verification failed!\"; \
54+
exit 1; \
55+
fi \
56+
&& tar xzvf %%REVISION%%.tar.gz \
57+
&& cd pkg-oss-%%REVISION%% \
58+
&& cd alpine \
59+
&& make %%BUILDTARGET%% \
60+
&& apk index --allow-untrusted -o ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz ${tempDir}/packages/alpine/${apkArch}/*.apk \
61+
&& abuild-sign -k ${tempDir}/.abuild/abuild-key.rsa ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz \
62+
" \
63+
&& cp ${tempDir}/.abuild/abuild-key.rsa.pub /etc/apk/keys/ \
64+
&& apk del --no-network .build-deps \
65+
&& apk add -X ${tempDir}/packages/alpine/ --no-cache $nginxPackages \
66+
;; \
67+
esac \
68+
# remove checksum deps
69+
&& apk del --no-network .checksum-deps \
70+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
71+
&& if [ -n "$tempDir" ]; then rm -rf "$tempDir"; fi \
72+
&& if [ -f "/etc/apk/keys/abuild-key.rsa.pub" ]; then rm -f /etc/apk/keys/abuild-key.rsa.pub; fi
73+
74+
USER $UID

Dockerfile-debian-otel.template

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
ARG IMAGE=nginxinc/nginx-unprivileged:%%NGINX_VERSION%%
2+
FROM $IMAGE
3+
4+
ARG UID=101
5+
ARG GID=101
6+
7+
USER root
8+
9+
ENV OTEL_VERSION=%%OTEL_VERSION%%
10+
11+
RUN set -x; \
12+
NGINX_GPGKEY_PATH=/etc/apt/keyrings/nginx-archive-keyring.gpg; \
13+
dpkgArch="$(dpkg --print-architecture)" \
14+
&& nginxPackages="%%PACKAGES%%
15+
" \
16+
&& case "$dpkgArch" in \
17+
amd64|arm64) \
18+
# arches officialy built by upstream
19+
echo "deb [signed-by=$NGINX_GPGKEY_PATH] %%PACKAGEREPO%% %%DEBIAN_VERSION%% nginx" >> /etc/apt/sources.list.d/nginx.list \
20+
&& apt-get update \
21+
;; \
22+
*) \
23+
# we're on an architecture upstream doesn't officially build for
24+
# let's build binaries from the published packaging sources
25+
# new directory for storing sources and .deb files
26+
tempDir="$(mktemp -d)" \
27+
&& chmod 777 "$tempDir" \
28+
# (777 to ensure APT's "_apt" user can access it too)
29+
\
30+
# save list of currently-installed packages so build dependencies can be cleanly removed later
31+
&& savedAptMark="$(apt-mark showmanual)" \
32+
\
33+
# build .deb files from upstream's packaging sources
34+
&& apt-get update \
35+
&& apt-get install --no-install-recommends --no-install-suggests -y \
36+
curl \
37+
devscripts \
38+
equivs \
39+
git \
40+
libxml2-utils \
41+
lsb-release \
42+
xsltproc \
43+
&& ( \
44+
cd "$tempDir" \
45+
&& REVISION="%%REVISION%%" \
46+
&& REVISION=${REVISION%~*} \
47+
&& curl -f -L -O https://github.com/nginx/pkg-oss/archive/${REVISION}.tar.gz \
48+
&& PKGOSSCHECKSUM="%%PKGOSSCHECKSUM%% *${REVISION}.tar.gz" \
49+
&& if [ "$(openssl sha512 -r ${REVISION}.tar.gz)" = "$PKGOSSCHECKSUM" ]; then \
50+
echo "pkg-oss tarball checksum verification succeeded!"; \
51+
else \
52+
echo "pkg-oss tarball checksum verification failed!"; \
53+
exit 1; \
54+
fi \
55+
&& tar xzvf ${REVISION}.tar.gz \
56+
&& cd pkg-oss-${REVISION} \
57+
&& cd debian \
58+
&& for target in %%BUILDTARGET%%; do \
59+
make rules-$target; \
60+
mk-build-deps --install --tool="apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes" \
61+
debuild-$target/nginx-$NGINX_VERSION/debian/control; \
62+
done \
63+
&& make %%BUILDTARGET%% \
64+
) \
65+
# we don't remove APT lists here because they get re-downloaded and removed later
66+
\
67+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
68+
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
69+
&& apt-mark showmanual | xargs apt-mark auto > /dev/null \
70+
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
71+
\
72+
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
73+
&& ls -lAFh "$tempDir" \
74+
&& ( cd "$tempDir" && dpkg-scanpackages . > Packages ) \
75+
&& grep '^Package: ' "$tempDir/Packages" \
76+
&& echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list \
77+
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
78+
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
79+
# ...
80+
# 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)
81+
&& apt-get -o Acquire::GzipIndexes=false update \
82+
;; \
83+
esac \
84+
\
85+
&& apt-get install --no-install-recommends --no-install-suggests -y \
86+
$nginxPackages \
87+
gettext-base \
88+
curl \
89+
&& apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \
90+
\
91+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
92+
&& if [ -n "$tempDir" ]; then \
93+
apt-get purge -y --auto-remove \
94+
&& rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
95+
fi
96+
97+
USER $UID

mainline/alpine-otel/Dockerfile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#
2+
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
3+
#
4+
# PLEASE DO NOT EDIT IT DIRECTLY.
5+
#
6+
ARG IMAGE=nginxinc/nginx-unprivileged:1.27.5-alpine
7+
FROM $IMAGE
8+
9+
ARG UID=101
10+
ARG GID=101
11+
12+
USER root
13+
14+
ENV OTEL_VERSION=0.1.2
15+
16+
RUN set -x \
17+
&& apkArch="$(cat /etc/apk/arch)" \
18+
&& nginxPackages=" \
19+
nginx=${NGINX_VERSION}-r${PKG_RELEASE} \
20+
nginx-module-xslt=${NGINX_VERSION}-r${DYNPKG_RELEASE} \
21+
nginx-module-geoip=${NGINX_VERSION}-r${DYNPKG_RELEASE} \
22+
nginx-module-image-filter=${NGINX_VERSION}-r${DYNPKG_RELEASE} \
23+
nginx-module-njs=${NGINX_VERSION}.${NJS_VERSION}-r${NJS_RELEASE} \
24+
nginx-module-otel=${NGINX_VERSION}.${OTEL_VERSION}-r${PKG_RELEASE} \
25+
" \
26+
# install prerequisites for public key and pkg-oss checks
27+
&& apk add --no-cache --virtual .checksum-deps \
28+
openssl \
29+
&& case "$apkArch" in \
30+
x86_64|aarch64) \
31+
# arches officially built by upstream
32+
apk add -X "https://nginx.org/packages/mainline/alpine/v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" --no-cache $nginxPackages \
33+
;; \
34+
*) \
35+
# we're on an architecture upstream doesn't officially build for
36+
# let's build binaries from the published packaging sources
37+
set -x \
38+
&& tempDir="$(mktemp -d)" \
39+
&& chown nobody:nobody $tempDir \
40+
&& apk add --no-cache --virtual .build-deps \
41+
gcc \
42+
libc-dev \
43+
make \
44+
openssl-dev \
45+
pcre2-dev \
46+
zlib-dev \
47+
linux-headers \
48+
cmake \
49+
bash \
50+
alpine-sdk \
51+
findutils \
52+
curl \
53+
xz \
54+
protobuf-dev \
55+
grpc-dev \
56+
&& su nobody -s /bin/sh -c " \
57+
export HOME=${tempDir} \
58+
&& cd ${tempDir} \
59+
&& curl -f -L -O https://github.com/nginx/pkg-oss/archive/${NGINX_VERSION}-${PKG_RELEASE}.tar.gz \
60+
&& PKGOSSCHECKSUM=\"c773d98b567bd585c17f55702bf3e4c7d82b676bfbde395270e90a704dca3c758dfe0380b3f01770542b4fd9bed1f1149af4ce28bfc54a27a96df6b700ac1745 *${NGINX_VERSION}-${PKG_RELEASE}.tar.gz\" \
61+
&& if [ \"\$(openssl sha512 -r ${NGINX_VERSION}-${PKG_RELEASE}.tar.gz)\" = \"\$PKGOSSCHECKSUM\" ]; then \
62+
echo \"pkg-oss tarball checksum verification succeeded!\"; \
63+
else \
64+
echo \"pkg-oss tarball checksum verification failed!\"; \
65+
exit 1; \
66+
fi \
67+
&& tar xzvf ${NGINX_VERSION}-${PKG_RELEASE}.tar.gz \
68+
&& cd pkg-oss-${NGINX_VERSION}-${PKG_RELEASE} \
69+
&& cd alpine \
70+
&& make module-otel \
71+
&& apk index --allow-untrusted -o ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz ${tempDir}/packages/alpine/${apkArch}/*.apk \
72+
&& abuild-sign -k ${tempDir}/.abuild/abuild-key.rsa ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz \
73+
" \
74+
&& cp ${tempDir}/.abuild/abuild-key.rsa.pub /etc/apk/keys/ \
75+
&& apk del --no-network .build-deps \
76+
&& apk add -X ${tempDir}/packages/alpine/ --no-cache $nginxPackages \
77+
;; \
78+
esac \
79+
# remove checksum deps
80+
&& apk del --no-network .checksum-deps \
81+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
82+
&& if [ -n "$tempDir" ]; then rm -rf "$tempDir"; fi \
83+
&& if [ -f "/etc/apk/keys/abuild-key.rsa.pub" ]; then rm -f /etc/apk/keys/abuild-key.rsa.pub; fi
84+
85+
USER $UID

mainline/debian-otel/Dockerfile

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#
2+
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
3+
#
4+
# PLEASE DO NOT EDIT IT DIRECTLY.
5+
#
6+
ARG IMAGE=nginxinc/nginx-unprivileged:1.27.5
7+
FROM $IMAGE
8+
9+
ARG UID=101
10+
ARG GID=101
11+
12+
USER root
13+
14+
ENV OTEL_VERSION=0.1.2
15+
16+
RUN set -x; \
17+
NGINX_GPGKEY_PATH=/etc/apt/keyrings/nginx-archive-keyring.gpg; \
18+
dpkgArch="$(dpkg --print-architecture)" \
19+
&& nginxPackages=" \
20+
nginx=${NGINX_VERSION}-${PKG_RELEASE} \
21+
nginx-module-xslt=${NGINX_VERSION}-${DYNPKG_RELEASE} \
22+
nginx-module-geoip=${NGINX_VERSION}-${DYNPKG_RELEASE} \
23+
nginx-module-image-filter=${NGINX_VERSION}-${DYNPKG_RELEASE} \
24+
nginx-module-njs=${NGINX_VERSION}+${NJS_VERSION}-${NJS_RELEASE} \
25+
nginx-module-otel=${NGINX_VERSION}+${OTEL_VERSION}-${PKG_RELEASE} \
26+
" \
27+
&& case "$dpkgArch" in \
28+
amd64|arm64) \
29+
# arches officialy built by upstream
30+
echo "deb [signed-by=$NGINX_GPGKEY_PATH] https://nginx.org/packages/mainline/debian/ bookworm nginx" >> /etc/apt/sources.list.d/nginx.list \
31+
&& apt-get update \
32+
;; \
33+
*) \
34+
# we're on an architecture upstream doesn't officially build for
35+
# let's build binaries from the published packaging sources
36+
# new directory for storing sources and .deb files
37+
tempDir="$(mktemp -d)" \
38+
&& chmod 777 "$tempDir" \
39+
# (777 to ensure APT's "_apt" user can access it too)
40+
\
41+
# save list of currently-installed packages so build dependencies can be cleanly removed later
42+
&& savedAptMark="$(apt-mark showmanual)" \
43+
\
44+
# build .deb files from upstream's packaging sources
45+
&& apt-get update \
46+
&& apt-get install --no-install-recommends --no-install-suggests -y \
47+
curl \
48+
devscripts \
49+
equivs \
50+
git \
51+
libxml2-utils \
52+
lsb-release \
53+
xsltproc \
54+
&& ( \
55+
cd "$tempDir" \
56+
&& REVISION="${NGINX_VERSION}-${PKG_RELEASE}" \
57+
&& REVISION=${REVISION%~*} \
58+
&& curl -f -L -O https://github.com/nginx/pkg-oss/archive/${REVISION}.tar.gz \
59+
&& PKGOSSCHECKSUM="c773d98b567bd585c17f55702bf3e4c7d82b676bfbde395270e90a704dca3c758dfe0380b3f01770542b4fd9bed1f1149af4ce28bfc54a27a96df6b700ac1745 *${REVISION}.tar.gz" \
60+
&& if [ "$(openssl sha512 -r ${REVISION}.tar.gz)" = "$PKGOSSCHECKSUM" ]; then \
61+
echo "pkg-oss tarball checksum verification succeeded!"; \
62+
else \
63+
echo "pkg-oss tarball checksum verification failed!"; \
64+
exit 1; \
65+
fi \
66+
&& tar xzvf ${REVISION}.tar.gz \
67+
&& cd pkg-oss-${REVISION} \
68+
&& cd debian \
69+
&& for target in module-otel; do \
70+
make rules-$target; \
71+
mk-build-deps --install --tool="apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes" \
72+
debuild-$target/nginx-$NGINX_VERSION/debian/control; \
73+
done \
74+
&& make module-otel \
75+
) \
76+
# we don't remove APT lists here because they get re-downloaded and removed later
77+
\
78+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
79+
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
80+
&& apt-mark showmanual | xargs apt-mark auto > /dev/null \
81+
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
82+
\
83+
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
84+
&& ls -lAFh "$tempDir" \
85+
&& ( cd "$tempDir" && dpkg-scanpackages . > Packages ) \
86+
&& grep '^Package: ' "$tempDir/Packages" \
87+
&& echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list \
88+
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
89+
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
90+
# ...
91+
# 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)
92+
&& apt-get -o Acquire::GzipIndexes=false update \
93+
;; \
94+
esac \
95+
\
96+
&& apt-get install --no-install-recommends --no-install-suggests -y \
97+
$nginxPackages \
98+
gettext-base \
99+
curl \
100+
&& apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \
101+
\
102+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
103+
&& if [ -n "$tempDir" ]; then \
104+
apt-get purge -y --auto-remove \
105+
&& rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
106+
fi
107+
108+
USER $UID

0 commit comments

Comments
 (0)