-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
391 lines (372 loc) · 15.5 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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# syntax=docker/dockerfile:1
FROM alpine:3.15
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG BUILDPLATFORM
ARG BUILDOS
ARG BUILDARCH
ARG BUILDVARIANT
RUN set -eu; \
echo "TARGETPLATFORM=$TARGETPLATFORM"; \
echo "TARGETOS=$TARGETOS"; \
echo "TARGETARCH=$TARGETARCH"; \
echo "TARGETVARIANT=$TARGETVARIANT"; \
echo "BUILDPLATFORM=$BUILDPLATFORM"; \
echo "BUILDOS=$BUILDOS"; \
echo "BUILDARCH=$BUILDARCH"; \
echo "BUILDVARIANT=$BUILDVARIANT";
RUN --mount=type=secret,id=GITHUB_TOKEN \
set -eux; \
DEPS='alpine-sdk bash libstdc++ libc6-compat python3'; \
apk add --no-cache $DEPS; \
# Constraint to npm 8, or else npm will fail with 'npm ERR! python is not a valid npm option'. See: https://stackoverflow.com/questions/74522956/python-is-not-a-valid-npm-option and https://jubianchi.github.io/semver-check/#/~8/8
apk add --no-cache npm~8 nodejs~16; \
npm config set python python3; \
# Use 'NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT' to fix node 18.20 and 20.12 making experimental API the default, which breaks builds
# Use '-U_FORTIFY_SOURCE' to fix vsnprintf errors in alpine: https://gitlab.alpinelinux.org/alpine/aports/-/issues/8626
# Use '-DUSE_IPO=OFF -DWHOLE_PROGRAM_OPTIMISATION=OFF' to fix lto-wrapper errors?
( set +x; export GITHUB_TOKEN=$( cat /run/secrets/GITHUB_TOKEN ); set -x; CXXFLAGS='-DNODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT' npm install --global [email protected] --unsafe-perm ); \
# Fix missing dependencies. See: https://github.com/coder/code-server/issues/5530
( cd /usr/local/lib/node_modules/code-server/lib/vscode; set +x; export GITHUB_TOKEN=$( cat /run/secrets/GITHUB_TOKEN ); set -x; CXXFLAGS='-DNODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT' npm install --legacy-peer-deps ); \
code-server --version; \
apk del $DEPS
# Install tools
RUN set -eux; \
apk add --no-cache bash bash-completion ca-certificates curl gnupg git git-lfs github-cli iotop jq less lsblk make nano openssh-client openssl p7zip rsync tree yq
# Install pwsh
# See: https://learn.microsoft.com/en-us/powershell/scripting/install/install-alpine?view=powershell-7.3
RUN set -eux; \
apk add --no-cache \
ca-certificates \
less \
ncurses-terminfo-base \
krb5-libs \
libgcc \
libintl \
libssl1.1 \
libstdc++ \
tzdata \
userspace-rcu \
zlib \
icu-libs \
curl
RUN apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache lttng-ust
RUN set -eux; \
mkdir -p /opt/microsoft/powershell/7; \
curl -sSL https://github.com/PowerShell/PowerShell/releases/download/v7.2.8/powershell-7.2.8-linux-alpine-x64.tar.gz | tar -C /opt/microsoft/powershell/7 -zxf -; \
chmod +x /opt/microsoft/powershell/7/pwsh; \
ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh
# Disable telemetry for powershell 7.0.0 and above and .NET core: https://github.com/PowerShell/PowerShell/issues/16234#issuecomment-942139350
ENV POWERSHELL_CLI_TELEMETRY_OPTOUT=1
ENV POWERSHELL_TELEMETRY_OPTOUT=1
ENV POWERSHELL_UPDATECHECK=Off
ENV POWERSHELL_UPDATECHECK_OPTOUT=1
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
ENV DOTNET_TELEMETRY_OPTOUT=1
ENV COMPlus_EnableDiagnostics=0
RUN pwsh -version
# Install pwsh module(s)
RUN pwsh -c 'Install-Module Pester -Force -Scope AllUsers -MinimumVersion 4.0.0 -MaximumVersion 4.10.1 -ErrorAction Stop'
RUN apk add --no-cache sudo
RUN adduser -u 1000 --gecos '' -D user
RUN echo 'user ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/user
# Install common extensions
USER user
# beautify - code formatter
RUN code-server --install-extension [email protected]
# docker
RUN code-server --install-extension [email protected]
# firefox
RUN code-server --install-extension [email protected]
# git
RUN code-server --install-extension [email protected]
RUN code-server --install-extension [email protected]
# github. Install the latest compatible version
RUN code-server --install-extension github.vscode-pull-request-github
# gitlab
RUN code-server --install-extension [email protected]
# jinja
RUN code-server --install-extension [email protected]
RUN code-server --install-extension [email protected]
# kubernetes
RUN code-server --install-extension [email protected]
# markdown
RUN code-server --install-extension [email protected]
RUN code-server --install-extension [email protected]
# prettier - code formatter
RUN code-server --install-extension [email protected]
# pwsh
RUN code-server --install-extension [email protected]
# svg
RUN code-server --install-extension [email protected]
# terraform
RUN code-server --install-extension [email protected]
# toml
RUN code-server --install-extension [email protected]
# vscode
RUN code-server --install-extension [email protected]
# xml
RUN code-server --install-extension [email protected]
# yaml
RUN code-server --install-extension [email protected]
# Install docker
# See: https://github.com/moby/moby/blob/v20.10.22/project/PACKAGERS.md
# Install docker-cli dependencies
USER root
RUN set -eux; \
apk add --no-cache \
ca-certificates \
git \
# Workaround for golang 1.15 not producing static binaries. See: https://github.com/containerd/containerd/issues/5824
libc6-compat \
openssh-client
# Install dockerd dependencies
RUN apk add --no-cache \
btrfs-progs \
e2fsprogs \
e2fsprogs-extra \
ip6tables \
iptables \
openssl \
pigz \
shadow-uidmap \
xfsprogs \
xz \
zfs
# Add userns-remap support. See: https://docs.docker.com/engine/security/userns-remap/
RUN set -eux; \
addgroup -S dockremap; \
adduser -S -G dockremap dockremap; \
echo 'dockremap:231072:65536' >> /etc/subuid; \
echo 'dockremap:231072:65536' >> /etc/subgid
# Install docker
RUN set -eux; \
case "$( uname -m )" in \
'x86_64') \
URL='https://download.docker.com/linux/static/stable/x86_64/docker-24.0.9.tgz'; \
;; \
'armhf') \
URL='https://download.docker.com/linux/static/stable/armel/docker-24.0.9.tgz'; \
;; \
'armv7') \
URL='https://download.docker.com/linux/static/stable/armhf/docker-24.0.9.tgz'; \
;; \
'aarch64') \
URL='https://download.docker.com/linux/static/stable/aarch64/docker-24.0.9.tgz'; \
;; \
# These architectures are no longer supported as of docker 20.10.x
# 'ppc64le') \
# URL='https://download.docker.com/linux/static/stable/ppc64le/docker-24.0.9.tgz'; \
# ;; \
# 's390x') \
# URL='https://download.docker.com/linux/static/stable/s390x/docker-24.0.9.tgz'; \
# ;; \
*) \
echo "Architecture not supported"; \
exit 1; \
;; \
esac; \
wget -q "$URL" -O docker.tgz; \
tar -xvf docker.tgz --strip-components=1 --no-same-owner --no-same-permissions -C /usr/local/bin; \
ls -al /usr/local/bin; \
rm -v docker.tgz; \
containerd --version; \
ctr --version; \
docker --version; \
dockerd --version; \
runc --version
# Install bash completion
RUN wget -q https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker -O /usr/share/bash-completion/completions/docker
# Post-install docker. See: https://docs.docker.com/engine/install/linux-postinstall/
RUN set -eux; \
addgroup docker; \
adduser user docker;
VOLUME /var/lib/docker
# Install rootless docker. See: https://docs.docker.com/engine/security/rootless/
USER root
RUN apk add --no-cache iproute2 fuse-overlayfs
RUN set -eux; \
echo user:100000:65536 >> /etc/subuid; \
echo user:100000:65536 >> /etc/subgid
RUN set -eux; \
case "$( uname -m )" in \
'x86_64') \
URL='https://download.docker.com/linux/static/stable/x86_64/docker-rootless-extras-24.0.9.tgz'; \
;; \
'aarch64') \
URL='https://download.docker.com/linux/static/stable/aarch64/docker-rootless-extras-24.0.9.tgz'; \
;; \
'armv7') \
URL='https://download.docker.com/linux/static/stable/armhf/docker-rootless-extras-24.0.9.tgz'; \
;; \
'aarch64') \
URL='https://download.docker.com/linux/static/stable/aarch64/docker-rootless-extras-24.0.9.tgz'; \
;; \
*) \
echo "Architecture not supported"; \
exit 1; \
;; \
esac; \
wget -q "$URL" -O docker-rootless-extras.tgz; \
tar -xvf docker-rootless-extras.tgz --strip-components=1 --no-same-owner --no-same-permissions -C /usr/local/bin \
'docker-rootless-extras/rootlesskit' \
'docker-rootless-extras/rootlesskit-docker-proxy' \
'docker-rootless-extras/vpnkit' \
; \
ls -al /usr/local/bin; \
rm -v docker-rootless-extras.tgz; \
rootlesskit --version; \
vpnkit --version
# Create XDG_RUNTIME_DIR
RUN set -eux; \
mkdir /run/user; \
chmod 1777 /run/user
# Create /var/lib/docker
RUN set -eux; \
mkdir -p /home/user/.local/share/docker; \
chown user:user /home/user/.local/share/docker
VOLUME /home/user/.local/share/docker
# Set env vars
ENV XDG_RUNTIME_DIR=/run/user/1000
ENV DOCKER_HOST=unix:///run/user/1000/docker.sock
# Install docker-compose v1 (deprecated, but for backward compatibility)
USER root
RUN apk add --no-cache docker-compose
# Install docker-compose
RUN set -eux; \
DOCKER_COMPOSE_VERSION=v2.30.3; \
case "$( uname -m )" in \
'x86') \
URL="https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-x86_64"; \
SHA256=fbb4853d3f2148b0f2f0916f8971c9e500784e4e4949324934fc0b7dc2ed5016; \
;; \
'x86_64') \
URL="https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-x86_64"; \
SHA256=fbb4853d3f2148b0f2f0916f8971c9e500784e4e4949324934fc0b7dc2ed5016; \
;; \
'armhf') \
URL="https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-armv6"; \
SHA256=7116c73bd22504ff61e5e25f3ea6638a7b2a5d126764fccdec4fd7623cf17963; \
;; \
'armv7l') \
URL="https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-armv7"; \
SHA256=944402b85b5eb8492ebbe2e4dcbf962adcaaa16b0ed66b51abaf2ac3e3809b1b; \
;; \
'aarch64') \
URL="https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-aarch64"; \
SHA256=8fed7b79b8bd1cb0624142f7d723c3cc67ba747c77ed69abbdefdc77a6d416d1; \
;; \
'ppc64le') \
URL="https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-ppc64le"; \
SHA256=9a5d9fd85e852a9c3c9137ea8ea80d66f0fe349d34b3e329255d98cd960c331e; \
;; \
'riscv64') \
URL="https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-riscv64"; \
SHA256=eda617db72d24fe79be98e2273e1fb433943a18479cedc86601963f75666304f; \
;; \
's390x') \
URL="https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-s390x"; \
SHA256=9476a64e9605df956e3e33b09acfdaed2d4a2c71da5b4a09899a9b7d428263a0; \
;; \
*) \
echo "Architecture not supported"; \
exit 1; \
;; \
esac; \
FILE=docker-compose; \
wget -q "$URL" -O "$FILE"; \
echo "$SHA256 $FILE" | sha256sum -c -; \
mkdir -pv /usr/libexec/docker/cli-plugins; \
mv -v docker-compose /usr/libexec/docker/cli-plugins/docker-compose; \
chmod +x /usr/libexec/docker/cli-plugins/docker-compose; \
docker compose version; \
:
# Install docker-buildx
RUN set -eux; \
DOCKER_BUILDX_VERSION=v0.12.1; \
case "$( uname -m )" in \
'x86_64') \
URL="https://github.com/docker/buildx/releases/download/v0.12.1/buildx-v0.12.1.linux-amd64"; \
SHA256=716321df8ca9c82ffe96f37e9f4aa1199d4969795836dbd57ef72d12e3ac5085; \
;; \
'armhf') \
URL="https://github.com/docker/buildx/releases/download/v0.12.1/buildx-v0.12.1.linux-arm-v6"; \
SHA256=4b3c78b59c0383ab21327e2902af2ea317e3b85e442b1cd776f0c2a7bbbb2999; \
;; \
'armv7l') \
URL="https://github.com/docker/buildx/releases/download/v0.12.1/buildx-v0.12.1.linux-arm-v7"; \
SHA256=fe0a9e7812051a72c47d009bf9373e76e23644cc3291c848ac4a9b6f237e9e75; \
;; \
'aarch64') \
URL="https://github.com/docker/buildx/releases/download/v0.12.1/buildx-v0.12.1.linux-arm64"; \
SHA256=fb72d627f2ee080bba70375c367f4292867821e29ca9a8cf485622f6ede8f436; \
;; \
'ppc64le') \
URL="https://github.com/docker/buildx/releases/download/v0.12.1/buildx-v0.12.1.linux-ppc64le"; \
SHA256=1c649498d727183d82fb243e08856533ea90e8d63bfcd6f8b23b264dbcf7ea7a; \
;; \
'riscv64') \
URL="https://github.com/docker/buildx/releases/download/v0.12.1/buildx-v0.12.1.linux-riscv64"; \
SHA256=152e7b423c1ce888eb0a658321eb8c28cc1d09af01acd5c66eddf8474dddf55c; \
;; \
's390x') \
URL="https://github.com/docker/buildx/releases/download/v0.12.1/buildx-v0.12.1.linux-s390x"; \
SHA256=acee98a9f0550bf2c6c1161cf8067c031ddf0c566c41de7db27847bb72e8ee0b; \
;; \
*) \
echo "Architecture not supported"; \
exit 1; \
;; \
esac; \
FILE=docker-buildx; \
wget -q "$URL" -O "$FILE"; \
echo "$SHA256 $FILE" | sha256sum -c -; \
mkdir -pv /usr/libexec/docker/cli-plugins; \
mv -v docker-buildx /usr/libexec/docker/cli-plugins/docker-buildx; \
chmod +x /usr/libexec/docker/cli-plugins/docker-buildx; \
docker buildx version; \
:
# Install binary tool(s)
RUN set -eux; \
wget https://github.com/GoogleContainerTools/container-diff/releases/download/v0.17.0/container-diff-linux-amd64 -O container-diff; \
sha256sum container-diff | grep '^818c219ce9f9670cd5c766b9da5036cf75bbf98bc99eb258f5e8f90e80367c88 '; \
mv container-diff /usr/local/bin/container-diff; \
chmod +x /usr/local/bin/container-diff; \
container-diff version
# Install golang binaries from official golang image
# See: https://go.dev/dl/
USER root
ENV GOLANG_VERSION 1.20.14
ENV PATH=/usr/local/go/bin:$PATH
COPY --from=golang:1.20.14-alpine /usr/local/go /usr/local/go
RUN go version
# Install development tools
RUN set -eux; \
export GOBIN=/usr/local/bin; \
go install github.com/go-delve/delve/cmd/[email protected]; \
dlv version; \
go install golang.org/x/tools/[email protected]; \
gopls version; \
rm -rf ~/go;
# Install extensions
USER user
RUN code-server --install-extension [email protected]
# Add a default settings.json
USER user
COPY --chown=1000:1000 settings.json /home/user/.local/share/code-server/User/settings.json
# Remove the default code-server config file created when extensions are installed
USER user
RUN rm -fv ~/.config/code-server/config.yaml
# Symlink code to code-server
USER root
RUN ln -sfn /usr/local/bin/code-server /usr/local/bin/code
USER root
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENV LANG=en_US.UTF-8
USER user
WORKDIR /home/user
ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "--bind-addr=0.0.0.0:8080", "--disable-telemetry", "--disable-update-check" ]