-
Notifications
You must be signed in to change notification settings - Fork 262
/
Dockerfile.template
276 lines (246 loc) · 9.43 KB
/
Dockerfile.template
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#
# NOTE: THIS DOCKERFILE IS GENERATED FROM "Dockerfile.template" VIA
# `./generate_dockerfiles.sh`
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
{{#debian}}
# Python is needed for building libnss.
# Use it as a common base.
FROM python:3.11-slim-bookworm as builder
{{/debian}}
{{#alpine}}
FROM alpine:3.18 as builder
{{/alpine}}
WORKDIR /build
# Common dependencies
{{#debian}}
RUN apt-get update && \
apt-get install -y git ninja-build cmake curl zlib1g-dev
{{/debian}}
{{#alpine}}
RUN apk add git bash build-base make cmake ninja curl zlib-dev patch linux-headers python3 python3-dev
{{/alpine}}
# The following are needed because we are going to change some autoconf scripts,
# both for libnghttp2 and curl.
{{#debian}}
RUN apt-get install -y autoconf automake autotools-dev pkg-config libtool
{{/debian}}
{{#alpine}}
RUN apk add autoconf automake pkgconfig libtool
{{/alpine}}
{{#debian}}
# Dependencies for downloading and building nghttp2
RUN apt-get install -y bzip2
{{/debian}}
{{#debian}}
# Dependencies for downloading and building curl
RUN apt-get install -y xz-utils
{{/debian}}
{{#firefox}}
# Dependencies for building libnss
# See https://firefox-source-docs.mozilla.org/security/nss/build.html#mozilla-projects-nss-building
{{#debian}}
RUN apt-get install -y mercurial python3-pip
{{/debian}}
{{#alpine}}
RUN apk add mercurial py3-pip clang-analyzer
{{/alpine}}
{{#debian}}
# curl tries to load the CA certificates for libnss.
# It loads them from /usr/lib/x86_64-linux-gnu/nss/libnssckbi.so,
# which is supplied by libnss3 on Debian/Ubuntu
RUN apt-get install -y libnss3
{{/debian}}
{{/firefox}}
{{#chrome}}
# Dependencies for downloading and building BoringSSL
{{#debian}}
RUN apt-get install -y g++ golang-go unzip
{{/debian}}
{{#alpine}}
RUN apk add g++ go unzip
{{/alpine}}
{{/chrome}}
# Download and compile libbrotli
ARG BROTLI_VERSION=1.0.9
RUN curl -L https://github.com/google/brotli/archive/refs/tags/v${BROTLI_VERSION}.tar.gz -o brotli-${BROTLI_VERSION}.tar.gz && \
tar xf brotli-${BROTLI_VERSION}.tar.gz
RUN cd brotli-${BROTLI_VERSION} && \
mkdir build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./installed .. && \
cmake --build . --config Release --target install
{{#firefox}}
# Needed for building libnss
RUN pip install gyp-next
ARG NSS_VERSION=nss-3.92
# This tarball is already bundled with nspr, a dependency of libnss.
ARG NSS_URL=https://ftp.mozilla.org/pub/security/nss/releases/NSS_3_92_RTM/src/nss-3.92-with-nspr-4.35.tar.gz
# Download and compile nss.
RUN curl -o ${NSS_VERSION}.tar.gz ${NSS_URL}
RUN tar xf ${NSS_VERSION}.tar.gz && \
cd ${NSS_VERSION}/nss && \
./build.sh -o --disable-tests --static --python=python3
{{/firefox}}
{{#chrome}}
# BoringSSL doesn't have versions. Choose a commit that is used in a stable
# Chromium version.
ARG BORING_SSL_COMMIT=1b7fdbd9101dedc3e0aa3fcf4ff74eacddb34ecc
RUN curl -L https://github.com/google/boringssl/archive/${BORING_SSL_COMMIT}.zip -o boringssl.zip && \
unzip boringssl && \
mv boringssl-${BORING_SSL_COMMIT} boringssl
# Compile BoringSSL.
# See https://boringssl.googlesource.com/boringssl/+/HEAD/BUILDING.md
COPY patches/boringssl-*.patch boringssl/
RUN cd boringssl && \
for p in $(ls boringssl-*.patch); do patch -p1 < $p; done && \
mkdir build && cd build && \
cmake \
-DCMAKE_C_FLAGS="-Wno-error=array-bounds -Wno-error=stringop-overflow" \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=on -GNinja .. && \
ninja
# Fix the directory structure so that curl can compile against it.
# See https://everything.curl.dev/source/build/tls/boringssl
RUN mkdir boringssl/build/lib && \
ln -s ../crypto/libcrypto.a boringssl/build/lib/libcrypto.a && \
ln -s ../ssl/libssl.a boringssl/build/lib/libssl.a && \
cp -R boringssl/include boringssl/build
{{/chrome}}
ARG NGHTTP2_VERSION=nghttp2-1.56.0
ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.56.0/nghttp2-1.56.0.tar.bz2
# Download nghttp2 for HTTP/2.0 support.
RUN curl -o ${NGHTTP2_VERSION}.tar.bz2 -L ${NGHTTP2_URL}
RUN tar xf ${NGHTTP2_VERSION}.tar.bz2
# Compile nghttp2
RUN cd ${NGHTTP2_VERSION} && \
./configure --prefix=/build/${NGHTTP2_VERSION}/installed --with-pic --disable-shared && \
make && make install
# Download curl.
ARG CURL_VERSION=curl-8.1.1
RUN curl -o ${CURL_VERSION}.tar.xz https://curl.se/download/${CURL_VERSION}.tar.xz
RUN tar xf ${CURL_VERSION}.tar.xz
# Patch curl and re-generate the configure script
COPY patches/curl-*.patch ${CURL_VERSION}/
RUN cd ${CURL_VERSION} && \
for p in $(ls curl-*.patch); do patch -p1 < $p; done && \
autoreconf -fi
# Compile curl with nghttp2, libbrotli and nss (firefox) or boringssl (chrome).
# Enable keylogfile for debugging of TLS traffic.
RUN cd ${CURL_VERSION} && \
./configure --prefix=/build/install \
--enable-static \
--disable-shared \
--enable-websockets \
--with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
--with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
{{#firefox}}
--with-nss=/build/${NSS_VERSION}/dist/Release \
--with-nss-deprecated \
CFLAGS="-I/build/${NSS_VERSION}/dist/public/nss -I/build/${NSS_VERSION}/dist/Release/include/nspr" \
{{/firefox}}
{{#chrome}}
--with-openssl=/build/boringssl/build \
LIBS="-pthread" \
CFLAGS="-I/build/boringssl/build" \
{{/chrome}}
USE_CURL_SSLKEYLOGFILE=true && \
make && make install
RUN mkdir out && \
{{#firefox}}
cp /build/install/bin/curl-impersonate-ff out/ && \
ln -s curl-impersonate-ff out/curl-impersonate && \
{{/firefox}}
{{#chrome}}
cp /build/install/bin/curl-impersonate-chrome out/ && \
ln -s curl-impersonate-chrome out/curl-impersonate && \
{{/chrome}}
strip out/curl-impersonate
# Verify that the resulting 'curl' has all the necessary features.
RUN ./out/curl-impersonate -V | grep -q zlib && \
./out/curl-impersonate -V | grep -q brotli && \
./out/curl-impersonate -V | grep -q nghttp2 && \
./out/curl-impersonate -V | grep -q -e NSS -e BoringSSL && \
./out/curl-impersonate -V | grep -q -e wss
# Verify that the resulting 'curl' is really statically compiled
RUN ! (ldd ./out/curl-impersonate | grep -q -e libcurl -e nghttp2 -e brotli -e ssl -e crypto)
RUN rm -Rf /build/install
# Re-compile libcurl dynamically
RUN cd ${CURL_VERSION} && \
./configure --prefix=/build/install \
--enable-websockets \
--with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
--with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
{{#firefox}}
--with-nss=/build/${NSS_VERSION}/dist/Release \
--with-nss-deprecated \
CFLAGS="-I/build/${NSS_VERSION}/dist/public/nss -I/build/${NSS_VERSION}/dist/Release/include/nspr" \
{{/firefox}}
{{#chrome}}
--with-openssl=/build/boringssl/build \
LIBS="-pthread" \
CFLAGS="-I/build/boringssl/build" \
{{/chrome}}
USE_CURL_SSLKEYLOGFILE=true && \
make clean && make && make install
# Copy libcurl-impersonate and symbolic links
RUN cp -d /build/install/lib/libcurl-impersonate* /build/out
{{#firefox}}
RUN ver=$(readlink -f ${CURL_VERSION}/lib/.libs/libcurl-impersonate-ff.so | sed 's/.*so\.//') && \
major=$(echo -n $ver | cut -d'.' -f1) && \
ln -s "libcurl-impersonate-ff.so.$ver" "out/libcurl-impersonate.so.$ver" && \
{{/firefox}}
{{#chrome}}
RUN ver=$(readlink -f ${CURL_VERSION}/lib/.libs/libcurl-impersonate-chrome.so | sed 's/.*so\.//') && \
major=$(echo -n $ver | cut -d'.' -f1) && \
ln -s "libcurl-impersonate-chrome.so.$ver" "out/libcurl-impersonate.so.$ver" && \
{{/chrome}}
ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \
strip "out/libcurl-impersonate.so.$ver"
# Verify that the resulting 'libcurl' is really statically compiled against its
# dependencies.
RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto)
# Wrapper scripts
{{#firefox}}
COPY curl_ff* out/
{{/firefox}}
{{#chrome}}
COPY curl_chrome* curl_edge* curl_safari* out/
{{/chrome}}
{{#alpine}}
# Replace /usr/bin/env bash with /usr/bin/env ash
RUN sed -i 's@/usr/bin/env bash@/usr/bin/env ash@' out/curl_*
{{/alpine}}
RUN chmod +x out/curl_*
# Create a final, minimal image with the compiled binaries
# only.
{{#alpine}}
FROM alpine:3.18
{{#firefox}}
# curl tries to load the CA certificates for libnss.
# It loads them from /usr/lib/libnssckbi.so,
# which is supplied by 'nss' on alpine.
RUN apk add --no-cache nss
{{/firefox}}
{{/alpine}}
{{#debian}}
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates \
{{#firefox}}
# curl tries to load the CA certificates for libnss.
# It loads them from /usr/lib/libnssckbi.so and /usr/lib/libnsspem.so,
# which are supplied by 'libnss3' and 'nss-plugin-pem' on debian.
libnss3 nss-plugin-pem \
{{/firefox}}
&& rm -rf /var/lib/apt/lists/*
{{/debian}}
# Copy curl-impersonate from the builder image
COPY --from=builder /build/out/curl-impersonate* /usr/local/bin
COPY --from=builder /build/out/libcurl-impersonate* /usr/local/lib
{{#debian}}
# Update the loader's cache
RUN ldconfig
# Copy to /build/out as well for backward compatibility with previous versions.
COPY --from=builder /build/out /build/out
{{/debian}}
# Wrapper scripts
COPY --from=builder /build/out/curl_* /usr/local/bin/