-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDockerfile
71 lines (62 loc) · 2.19 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
# If you change this major version, change the --multi-release jdeps flag below
FROM openjdk:18-alpine AS build
RUN apk add \
# Install an Alpine-aware copy of Node. The version Kotlin would download targets glibc.
nodejs \
# Binutils provides objcopy binary which is used by --strip-debug jlink flag.
binutils \
# Gradle build runs git to embed SHA.
git \
;
WORKDIR /app
# Cache the Gradle binary separately from the build.
COPY gradlew ./
COPY gradle/wrapper ./gradle/wrapper
RUN ./gradlew --version
COPY gradle ./gradle
COPY build.gradle gradle.properties settings.gradle ./
COPY src ./src
RUN ./gradlew assemble -PskipNodeDownload
# Find modules which are required.
RUN jdeps \
--ignore-missing-deps \
# Keep in sync with major version of container above.
--multi-release 18 \
--print-module-deps \
--class-path build/install/posterbox/lib/* \
# Split comma-separated items into lines.
| tr ',' '\n' \
# Used only by Ktor's HOCON parser which we do not use.
| grep -v java.desktop \
# Used only by kotlinx.coroutines debug agent which we do not use.
| grep -v java.instrument \
# Used only by kotlinx.coroutines debug agent which we do not use.
| grep -v jdk.unsupported \
# Used only by Ktor for detecting IntelliJ IDEA debugger which we do not use.
# BUT our HTTP server cannot respond to requests without this module for some reason...
#| grep -v java.management \
# Join lines with comma.
| tr '\n' ',' \
# Replace trailing comma with a newline.
| sed 's/,$/\n/' \
# Print to stdout AND write to this file.
| tee jdeps.txt \
;
# Build custom minimal JRE with only the modules we need.
RUN jlink \
--verbose \
--compress 2 \
--strip-debug \
--no-header-files \
--no-man-pages \
--output jre \
--add-modules $(cat jdeps.txt) \
;
FROM alpine:3.20.3
EXPOSE 9931
HEALTHCHECK --interval=1m --timeout=3s \
CMD wget --no-verbose --tries=1 --spider http://localhost:9931/ || exit 1
COPY --from=build /app/jre /jre
ENV JAVA_HOME="/jre"
COPY --from=build /app/build/install/posterbox/ /app
ENTRYPOINT ["/app/bin/posterbox", "/config/config.toml"]