-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.builder
285 lines (245 loc) · 13.3 KB
/
Dockerfile.builder
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
277
278
279
280
281
282
283
284
285
ARG FROM_REGISTRY=docker.io/dubodubonduponey
ARG FROM_IMAGE_RUNTIME=debian:bookworm-2024-03-01
#######################
# Actual "builder" image
#######################
FROM $FROM_REGISTRY/$FROM_IMAGE_RUNTIME AS builder
# This is used to get the appropriate binaries from previous stages export
ARG TARGETPLATFORM
# Add go to path, and point GOPATH and GOROOT to the right locations
ENV GOPATH=/build/golang-current/source
ENV GOROOT=/build/golang-current/go
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH
# Install:
# - cross-toolchains for all supported architectures
# - basic dev stuff (git, jq, curl, devscripts)
# - additional often used build tools (automake, autoconf, libtool and pkg-config)
# Might not work on same platform as the cross build target...
# XXX WARNING
# Something weird is happening here: for some reason, installing everything in one call breaks apt which complains about "broken packages being held"
# Also, transient qemu core dumps (even with qemu 6), so... here be effing dragons
# hadolint ignore=DL3008
RUN --mount=type=secret,uid=100,id=CA \
--mount=type=secret,uid=100,id=CERTIFICATE \
--mount=type=secret,uid=100,id=KEY \
--mount=type=secret,uid=100,id=GPG.gpg \
--mount=type=secret,id=NETRC \
--mount=type=secret,id=APT_SOURCES \
--mount=type=secret,id=APT_CONFIG \
for architecture in arm64 amd64; do \
dpkg --add-architecture "$architecture"; \
done; \
apt-get update -qq; \
apt-get install -qq --no-install-recommends \
build-essential=12.9 \
autoconf=2.71-3 \
automake=1:1.16.5-1.3 \
libtool=2.4.7-5 \
pkg-config=1.8.1-1 \
jq=1.6-2.1 \
curl=7.88.1-10+deb12u5 \
ca-certificates=20230311 \
git=1:2.39.2-1.1; \
for architecture in arm64 amd64; do \
apt-get install -qq --no-install-recommends \
crossbuild-essential-"$architecture"=12.9 \
musl-dev:"$architecture"=1.2.3-1 \
musl:"$architecture"=1.2.3-1 \
libc6:"$architecture"=2.36-9+deb12u4 \
libc6-dev:"$architecture"=2.36-9+deb12u4; \
done; \
apt-get -qq autoremove; \
apt-get -qq clean; \
rm -rf /var/lib/apt/lists/*; \
rm -rf /tmp/*; \
rm -rf /var/tmp/*
# Prevent git from complaining about detached heads all the time
RUN git config --global advice.detachedHead false
# This used to be necessary because of a bug in qemu/libc
# Now replaced with proper ca-certificates install (which does pull in openssl <- not a problem for build, but keeping the lightweight deviation for runtime)
# ADD ./cache/overlay.tar /
ENV GOLANG_VERSION=1.21.8
ADD ./cache/$TARGETPLATFORM/golang-$GOLANG_VERSION.tar.gz /build/golang-current
# Add metadata
ARG BUILD_CREATED="1976-04-14T17:00:00-07:00"
ARG BUILD_URL="https://github.com/dubo-dubon-duponey/docker-base"
ARG BUILD_DOCUMENTATION="https://github.com/dubo-dubon-duponey/docker-base"
ARG BUILD_SOURCE="https://github.com/dubo-dubon-duponey/docker-base"
ARG BUILD_VERSION="unknown"
ARG BUILD_REVISION="unknown"
ARG BUILD_VENDOR="dubodubonduponey"
ARG BUILD_LICENSES="MIT"
ARG BUILD_REF_NAME="latest"
ARG BUILD_TITLE="A DBDBDP image"
ARG BUILD_DESCRIPTION="So image. Much DBDBDP. Such description."
LABEL org.opencontainers.image.created="$BUILD_CREATED"
LABEL org.opencontainers.image.authors="Dubo Dubon Duponey <dubo-dubon-duponey@farcloser.world>"
LABEL org.opencontainers.image.url="$BUILD_URL"
LABEL org.opencontainers.image.documentation="$BUILD_DOCUMENTATION"
LABEL org.opencontainers.image.source="$BUILD_SOURCE"
LABEL org.opencontainers.image.version="$BUILD_VERSION"
LABEL org.opencontainers.image.revision="$BUILD_REVISION"
LABEL org.opencontainers.image.vendor="$BUILD_VENDOR"
LABEL org.opencontainers.image.licenses="$BUILD_LICENSES"
LABEL org.opencontainers.image.ref.name="$BUILD_REF_NAME"
LABEL org.opencontainers.image.title="$BUILD_TITLE"
LABEL org.opencontainers.image.description="$BUILD_DESCRIPTION"
# Image building from here can use this for buildtime (that is usually set at the time of the last commit to their repo)
ONBUILD ARG BUILD_CREATED="1976-04-14T17:00:00-07:00"
# Helper for our secrets
# Pointing curl home out, allowing for /run/secrets/.curlrc to be seen automatically
ENV CURL_HOME=/run/secrets
# go tools use this to find the netrc file
ENV NETRC=/run/secrets/NETRC
# go tools honor this to find our CA
# XXX this is problematic - rust also uses this - if the file does not exist, at least rust will tits-up
ENV SSL_CERT_FILE=/run/secrets/CA
# Go stuff
# Images inheriting this will get a normal GOPROXY through the ARG (expected to go mod download), further inherits will get OFF (expected to ONLY build with no network)
ENV GOPROXY=off
ONBUILD ARG GOPROXY="https://proxy.golang.org,direct"
# Modules are on by default unless specifically disabled by projects
ENV GO111MODULE=on
# Make sure it's off by default
ENV CGO_ENABLED=0
# C/C++/CGO stuff
# https://news.ycombinator.com/item?id=18874113
# https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
ENV WARNING_OPTIONS="-Werror=implicit-function-declaration -Werror=format-security -Wall"
# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options
ENV OPTIMIZATION_OPTIONS="-O3"
# https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#Debugging-Options
ENV DEBUGGING_OPTIONS="-grecord-gcc-switches -g"
# https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options
ENV PREPROCESSOR_OPTIONS="-Wp,-D_GLIBCXX_ASSERTION -D_FORTIFY_SOURCE=2"
# https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
ENV COMPILER_OPTIONS="-pipe -fexceptions -fstack-protector-strong -fstack-clash-protection"
# AMD64 only
# -mcet -fcf-protection
# https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#Link-Options
ENV LDFLAGS="-Wl,-z,relro -Wl,-z,now -Wl,-z,defs -Wl,-z,noexecstack"
ENV CFLAGS="$WARNING_OPTIONS $OPTIMIZATION_OPTIONS $DEBUGGING_OPTIONS $PREPROCESSOR_OPTIONS $COMPILER_OPTIONS -s"
# Werror=implicit-function-declaration is not allowed for CXX
ENV CXXFLAGS="-Werror=format-security -Wall $OPTIMIZATION_OPTIONS $DEBUGGING_OPTIONS $PREPROCESSOR_OPTIONS $COMPILER_OPTIONS -s"
# Location
WORKDIR /source
#######################
# Actual "builder" image (with node)
#######################
FROM $FROM_REGISTRY/$FROM_IMAGE_RUNTIME AS builder-node
# This is used to get the appropriate binaries from previous stages export
ARG TARGETPLATFORM
# Add node
ENV NODE_VERSION=20.11.1
ENV YARN_VERSION=1.22.22
ADD ./cache/$TARGETPLATFORM/node-$NODE_VERSION.tar.gz /opt
ADD ./cache/$TARGETPLATFORM/yarn-$YARN_VERSION.tar.gz /opt
# Add metadata
ARG BUILD_CREATED="1976-04-14T17:00:00-07:00"
ARG BUILD_URL="https://github.com/dubo-dubon-duponey/docker-base"
ARG BUILD_DOCUMENTATION="https://github.com/dubo-dubon-duponey/docker-base"
ARG BUILD_SOURCE="https://github.com/dubo-dubon-duponey/docker-base"
ARG BUILD_VERSION="unknown"
ARG BUILD_REVISION="unknown"
ARG BUILD_VENDOR="dubodubonduponey"
ARG BUILD_LICENSES="MIT"
ARG BUILD_REF_NAME="latest"
ARG BUILD_TITLE="A DBDBDP image"
ARG BUILD_DESCRIPTION="So image. Much DBDBDP. Such description."
LABEL org.opencontainers.image.created="$BUILD_CREATED"
LABEL org.opencontainers.image.authors="Dubo Dubon Duponey <dubo-dubon-duponey@farcloser.world>"
LABEL org.opencontainers.image.url="$BUILD_URL"
LABEL org.opencontainers.image.documentation="$BUILD_DOCUMENTATION"
LABEL org.opencontainers.image.source="$BUILD_SOURCE"
LABEL org.opencontainers.image.version="$BUILD_VERSION"
LABEL org.opencontainers.image.revision="$BUILD_REVISION"
LABEL org.opencontainers.image.vendor="$BUILD_VENDOR"
LABEL org.opencontainers.image.licenses="$BUILD_LICENSES"
LABEL org.opencontainers.image.ref.name="$BUILD_REF_NAME"
LABEL org.opencontainers.image.title="$BUILD_TITLE"
LABEL org.opencontainers.image.description="$BUILD_DESCRIPTION"
# Image building from here can use this for buildtime (that is usually set at the time of the last commit to their repo)
ONBUILD ARG BUILD_CREATED="1976-04-14T17:00:00-07:00"
# Location
WORKDIR /source
# Node and Yarn post-install normalize
RUN ln -s /opt/node-*/bin/* /usr/local/bin/; \
ln -s /opt/yarn-*/bin/yarn /usr/local/bin/; \
ln -s /opt/yarn-*/bin/yarnpkg /usr/local/bin/; \
ln -s /usr/local/bin/node /usr/local/bin/nodejs
#######################
# Slim go image, solely for goproxy or as a lightweight go building without CGO
#######################
FROM $FROM_REGISTRY/$FROM_IMAGE_RUNTIME AS builder-golang
# This is used to get the appropriate binaries from previous stages export
ARG TARGETPLATFORM
# Add go to path, and point GOPATH and GOROOT to the right locations
ENV GOPATH=/build/golang-current/source
ENV GOROOT=/build/golang-current/go
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH
ENV GOLANG_VERSION=1.21.8
ADD ./cache/$TARGETPLATFORM/golang-$GOLANG_VERSION.tar.gz /build/golang-current
# Add metadata
ARG BUILD_CREATED="1976-04-14T17:00:00-07:00"
ARG BUILD_URL="https://github.com/dubo-dubon-duponey/docker-base"
ARG BUILD_DOCUMENTATION="https://github.com/dubo-dubon-duponey/docker-base"
ARG BUILD_SOURCE="https://github.com/dubo-dubon-duponey/docker-base"
ARG BUILD_VERSION="unknown"
ARG BUILD_REVISION="unknown"
ARG BUILD_VENDOR="dubodubonduponey"
ARG BUILD_LICENSES="MIT"
ARG BUILD_REF_NAME="latest"
ARG BUILD_TITLE="A DBDBDP image"
ARG BUILD_DESCRIPTION="So image. Much DBDBDP. Such description."
LABEL org.opencontainers.image.created="$BUILD_CREATED"
LABEL org.opencontainers.image.authors="Dubo Dubon Duponey <dubo-dubon-duponey@farcloser.world>"
LABEL org.opencontainers.image.url="$BUILD_URL"
LABEL org.opencontainers.image.documentation="$BUILD_DOCUMENTATION"
LABEL org.opencontainers.image.source="$BUILD_SOURCE"
LABEL org.opencontainers.image.version="$BUILD_VERSION"
LABEL org.opencontainers.image.revision="$BUILD_REVISION"
LABEL org.opencontainers.image.vendor="$BUILD_VENDOR"
LABEL org.opencontainers.image.licenses="$BUILD_LICENSES"
LABEL org.opencontainers.image.ref.name="$BUILD_REF_NAME"
LABEL org.opencontainers.image.title="$BUILD_TITLE"
LABEL org.opencontainers.image.description="$BUILD_DESCRIPTION"
# hadolint ignore=DL3008
RUN --mount=type=secret,uid=100,id=CA \
--mount=type=secret,uid=100,id=CERTIFICATE \
--mount=type=secret,uid=100,id=KEY \
--mount=type=secret,uid=100,id=GPG.gpg \
--mount=type=secret,id=NETRC \
--mount=type=secret,id=APT_SOURCES \
--mount=type=secret,id=APT_CONFIG \
apt-get update -qq; \
apt-get install -qq --no-install-recommends \
curl=7.88.1-10+deb12u5 \
ca-certificates=20230311 \
git=1:2.39.2-1.1; \
apt-get -qq autoremove; \
apt-get -qq clean; \
rm -rf /var/lib/apt/lists/*; \
rm -rf /tmp/*; \
rm -rf /var/tmp/*
# Image building from here can use this for buildtime (that is usually set at the time of the last commit to their repo)
ONBUILD ARG BUILD_CREATED="1976-04-14T17:00:00-07:00"
# Location
WORKDIR /source
# Helper for our secrets
# Pointing curl home out, allowing for /run/secrets/.curlrc to be seen automatically
ENV CURL_HOME=/run/secrets
# go tools use this to find the netrc file
ENV NETRC=/run/secrets/NETRC
# go tools honor this to find our CA
ENV SSL_CERT_FILE=/run/secrets/CA
# Go stuff
# Images inheriting this will get a normal GOPROXY through the ARG (expected to go mod download), further inherits will get OFF (expected to ONLY build with no network)
ENV GOPROXY=off
ONBUILD ARG GOPROXY="https://proxy.golang.org,direct"
# Modules are on by default unless specifically disabled by projects
ENV GO111MODULE=on
# Make sure it's off by default
ENV CGO_ENABLED=0
# Make sure git stops whining about detached heads
RUN git config --global advice.detachedHead false