-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathDockerfile
190 lines (138 loc) · 5.95 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# syntax=docker/dockerfile:1.12@sha256:93bfd3b68c109427185cd78b4779fc82b484b0b7618e36d0f104d4d801e66d25
FROM alpine:3.21.2@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099 AS build-base
ARG TARGETARCH
# hadolint ignore=DL3018
RUN --mount=type=cache,id=apk-cache-${TARGETARCH},target=/var/cache/apk \
apk add --update --cache-dir=/var/cache/apk \
binutils \
bind-tools \
build-base \
ca-certificates-bundle \
libevent-dev \
libsodium-dev \
nghttp2-dev \
openssl-dev \
hiredis-dev \
expat-dev
RUN find / -name "libcrypto.so*" -exec ls -al {} \;
ARG UNBOUND_UID=101
ARG UNBOUND_GID=102
RUN addgroup -S -g ${UNBOUND_GID} unbound \
&& adduser -S -g unbound -h /var/unbound -u ${UNBOUND_UID} -D -H -G unbound unbound
####################################################################################################
FROM build-base AS ldns
WORKDIR /src
ARG LDNS_VERSION=1.8.4
# https://nlnetlabs.nl/downloads/ldns/ldns-1.8.4.tar.gz.sha256
ARG LDNS_SHA256="838b907594baaff1cd767e95466a7745998ae64bc74be038dccc62e2de2e4247"
ADD https://nlnetlabs.nl/downloads/ldns/ldns-${LDNS_VERSION}.tar.gz ldns.tar.gz
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
RUN echo "${LDNS_SHA256} ldns.tar.gz" | sha256sum -c - \
&& tar -xzf ldns.tar.gz --strip-components=1
RUN ./configure \
--prefix=/opt/usr \
--with-drill \
--localstatedir=/var \
--with-ssl \
--disable-rpath \
--disable-shared \
--disable-static \
--disable-ldns-config
RUN make -j"$(nproc)" && \
make install && \
strip /opt/usr/bin/drill && \
ln -s drill /opt/usr/bin/dig
####################################################################################################
FROM build-base AS unbound
WORKDIR /src
ARG UNBOUND_VERSION=1.22.0
# https://nlnetlabs.nl/downloads/unbound/unbound-1.22.0.tar.gz.sha256
ARG UNBOUND_SHA256="c5dd1bdef5d5685b2cedb749158dd152c52d44f65529a34ac15cd88d4b1b3d43"
ADD https://nlnetlabs.nl/downloads/unbound/unbound-${UNBOUND_VERSION}.tar.gz unbound.tar.gz
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
RUN echo "${UNBOUND_SHA256} unbound.tar.gz" | sha256sum -c - \
&& tar -xzf unbound.tar.gz --strip-components=1
# https://unbound.docs.nlnetlabs.nl/en/latest/getting-started/installation.html#building-from-source-compiling
RUN ./configure \
--prefix=/opt/usr \
--with-conf-file=/etc/unbound/unbound.conf \
--with-run-dir=/var/unbound \
--with-chroot-dir=/var/unbound \
--with-pidfile=/var/unbound/unbound.pid \
--with-rootkey-file=/var/unbound/root.key \
--disable-static \
--disable-shared \
--disable-rpath \
--enable-dnscrypt \
--enable-subnet \
--enable-cachedb \
--enable-tfo-server \
--enable-tfo-client \
--with-pthreads \
--with-libevent \
--with-libhiredis \
--with-libnghttp2 \
--with-ssl \
--with-username=unbound
RUN make -j"$(nproc)" && \
make install && \
strip /opt/usr/sbin/unbound \
/opt/usr/sbin/unbound-anchor \
/opt/usr/sbin/unbound-checkconf \
/opt/usr/sbin/unbound-control \
/opt/usr/sbin/unbound-host
WORKDIR /var/unbound
####################################################################################################
FROM scratch AS conf-example
# docker build . --target conf-example --output rootfs_overlay/etc/unbound/
COPY --from=unbound /etc/unbound/unbound.conf /unbound.conf.example
####################################################################################################
FROM build-base AS root-hints
# https://unbound.docs.nlnetlabs.nl/en/latest/manpages/unbound-anchor.html
RUN wget -q https://www.internic.net/domain/named.root -O /root.hints
####################################################################################################
FROM unbound AS root-key
WORKDIR /var/unbound
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
COPY --from=root-hints /root.hints .
# Generate initial root key with the provided root hints.
# https://unbound.docs.nlnetlabs.nl/en/latest/manpages/unbound-anchor.html
# This tool exits with value 1 if the root anchor was updated using the certificate or
# if the builtin root-anchor was used. It exits with code 0 if no update was necessary,
# if the update was possible with RFC 5011 tracking, or if an error occurred.
RUN { /opt/usr/sbin/unbound-anchor -v -r root.hints -a root.key || true ; } | tee -a /dev/stderr | grep -q "success: the anchor is ok"
####################################################################################################
# This is a minimal C wrapper for drill to avoid the need for a shell
# and reduce the exit code to 0 or 1.
# Dockerfile reference says that health checks should always return 0 or 1.
# Any other status code is reserved.
# See https://docs.docker.com/reference/dockerfile/#healthcheck
FROM build-base AS drill-hc
# Set the working directory
WORKDIR /src
# Copy the source file
COPY drill-hc/main.c .
# Compile the program statically
RUN gcc -Wall -Wextra -pedantic -std=c2x -static -O3 -o drill-hc main.c
####################################################################################################
FROM scratch AS final
COPY --from=build-base /lib/ld-musl*.so.1 /lib/
COPY --from=build-base /usr/lib/libgcc_s.so.1 /usr/lib/
COPY --from=build-base /usr/lib/libcrypto.so.3 /usr/lib/libssl.so.3 /usr/lib/
COPY --from=build-base /usr/lib/libsodium.so.* /usr/lib/libevent-2.1.so.* /usr/lib/libexpat.so.* /usr/lib/libhiredis.so.* /usr/lib/libnghttp2.so.* /usr/lib/
COPY --from=build-base /etc/ssl/ /etc/ssl/
COPY --from=build-base /etc/passwd /etc/group /etc/
COPY --from=unbound /opt/usr/sbin/ /usr/sbin/
COPY --from=ldns /opt/usr/bin/ /usr/bin/
COPY --from=drill-hc /src/drill-hc /usr/bin/drill-hc
COPY --chown=unbound:unbound rootfs_overlay/etc/unbound/ /etc/unbound/
COPY --from=root-key --chown=unbound:unbound /var/unbound/root.hints /var/unbound/root.hints
COPY --from=root-key --chown=unbound:unbound /var/unbound/root.key /var/unbound/root.key
RUN [ "unbound", "-V" ]
# hadolint ignore=DL3059
RUN [ "unbound-checkconf" ]
# hadolint ignore=DL3059
RUN [ "drill", "-v" ]
# hadolint ignore=DL3059
RUN [ "dig", "-v" ]
ENTRYPOINT [ "unbound" ]