-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDockerfile
110 lines (100 loc) · 3.52 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
# syntax=docker/dockerfile:1
FROM alpine:3.20.3 AS entry
RUN apk add --no-cache npm && npm install -g [email protected] @types/[email protected]
COPY entry.ts .
RUN tsc \
--noUnusedLocals \
--noUnusedParameters \
--strict \
--typeRoots /usr/local/lib/node_modules/@types \
entry.ts \
&& chmod +x entry.js
# "Creating a JRE using jlink" at https://hub.docker.com/_/eclipse-temurin
# List of required modules is determined by starting with `docker run --rm
# eclipse-temurin:21-alpine java --list-modules`, then removing modules by trial
# and error until `make test` throws ClassNotFoundException. When first
# implemented, this custom JRE reduced our image size from 574 MB to 469 MB
FROM amazoncorretto:21.0.6-alpine3.21 as jre
RUN apk add binutils && jlink \
--add-modules java.se,jdk.compiler,jdk.unsupported \
--compress zip-6 \
--no-header-files \
--no-man-pages \
--output /jre \
--strip-debug
FROM alpine:3.20.3
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_NO_CACHE_DIR=1
RUN <<EOF
set -eu
# Install Alpine dependencies
apk add --no-cache --virtual .build-deps \
gcc \
musl-dev \
npm \
openjdk17-jre-headless \
py3-pip \
python3-dev
apk add --no-cache \
libxslt \
nodejs \
python3
pip3 install --break-system-packages \
autoflake==1.7.8 \
isort==5.13.2 \
ruff==0.7.3
# Install Python dependencies
python3 -m venv /black21-venv
source /black21-venv/bin/activate
pip3 install black==21.12b0 click==8.0.4
deactivate
echo 'source /black21-venv/bin/activate && black "$@"' > /usr/bin/black21
chmod +x /usr/bin/black21
# Install Node dependencies
npm install -g \
@prettier/[email protected] \
# Install Scala dependencies
wget https://github.com/coursier/coursier/releases/download/v2.1.17/coursier -O /bin/coursier
chmod +x /bin/coursier
coursier bootstrap org.scalameta:scalafmt-cli_2.13:3.8.3 \
-r sonatype:snapshots --main org.scalafmt.cli.Cli \
--standalone \
-o scalafmt
# Install static binaries
wget https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-32d3ac78/clang-format-18_linux-amd64 -O clang-format
chmod +x clang-format
wget https://github.com/google/google-java-format/releases/download/v1.24.0/google-java-format-1.24.0-all-deps.jar -O google-java-format
wget https://search.maven.org/remotecontent?filepath=com/facebook/ktfmt/0.53/ktfmt-0.53-jar-with-dependencies.jar -O ktfmt
wget https://github.com/mvdan/sh/releases/download/v3.10.0/shfmt_v3.10.0_linux_amd64 -O shfmt
chmod +x shfmt
wget https://github.com/tamasfe/taplo/releases/download/0.9.3/taplo-linux-x86_64.gz -O taplo.gz
gzip -d taplo.gz
chmod +x taplo
wget https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_linux_amd64.zip -O tf.zip
unzip tf.zip
rm tf.zip
# Create an empty file for the linters that need one for some reason
touch /emptyfile
# Delete unused files found by running `apk add ncdu && ncdu` inside `make shell`
apk del .build-deps
rm -rf \
/bin/coursier \
/black21-venv/lib/python3.11/site-packages/pip \
/black21-venv/lib/python3.11/site-packages/pkg_resources \
/black21-venv/lib/python3.11/site-packages/setuptools \
/root/.cache \
/root/.npm \
/usr/bin/lto-dump \
/var/cache
EOF
# https://stackoverflow.com/a/59485924
COPY --from=golang:1.23.3-alpine3.20 /usr/local/go/bin/gofmt /gofmt
ENV PATH="/jre/bin:${PATH}"
COPY --from=jre /jre /jre
COPY . .
COPY --from=entry /entry.js /entry
# https://github.com/coursier/coursier/issues/1955#issuecomment-956697764
ENV COURSIER_CACHE=/tmp/coursier-cache
ENV COURSIER_JVM_CACHE=/tmp/coursier-jvm-cache