-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
74 lines (58 loc) · 2.07 KB
/
Copy pathDockerfile
File metadata and controls
74 lines (58 loc) · 2.07 KB
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
# --- First stage: Get our app, work out its dependencies, create a JRE
FROM gradle:9.3.0-jdk25-noble AS builder
# See https://hub.docker.com/_/gradle for available images
WORKDIR /app
# Copy our gradle build environment over
RUN mkdir app
COPY app ./app/
RUN mkdir gradle
COPY gradle ./gradle/
COPY settings.gradle ./
# And the run scripts we'll need in stage 2
COPY run.sh ./
COPY setup_auth.sh ./
# Start by building the app as a fat (uber) JAR
# This gives us a smaller executable in stage 2
RUN gradle clean AnomalyDetectorAppUberJar --no-daemon
RUN cp app/build/libs/AnomalyDetectorApp-uber.jar ./
# Unpack the contents of our fat JAR
RUN mkdir temp && cd temp && jar xf ../AnomalyDetectorApp-uber.jar
# And find out what depedencies it lacks - this tells us what we need from
# the external Java environment
RUN jdeps --print-module-deps \
--ignore-missing-deps \
--recursive \
--multi-release 17 \
--class-path="./temp/BOOT-INF/lib/*" \
--module-path="./temp/BOOT-INF/lib/*" \
./AnomalyDetectorApp-uber.jar > modules.txt
# Now assemble our own custom JRE with only those things in it
RUN $JAVA_HOME/bin/jlink \
--verbose \
--add-modules $(cat modules.txt) \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=zip-6 \
--output ./custom-jre
# ----------------------------------------------------------------------------
# --- Second stage: Run the actual image
# Use the smallest base image possible (alpine)
FROM debian:bookworm-slim
WORKDIR /app
# Install RocksDB library for Kafka Streams
RUN apt-get update \
&& apt-get install -y librocksdb7.8
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& apt-get autoclean -y \
&& rm -rf /var/lib/apt/lists/*
# Copy the custom JRE and application artifacts from the builder stage
COPY --from=builder /app/custom-jre /usr/lib/jvm/custom-jre
COPY --from=builder /app/AnomalyDetectorApp-uber.jar ./
COPY --from=builder /app/setup_auth.sh ./
COPY --from=builder /app/run.sh ./
RUN chmod +x ./run.sh
RUN chmod +x ./setup_auth.sh
# Set the custom entrypoint
CMD [ "./run.sh" ]