Skip to content

Commit 30d61e3

Browse files
committed
Dockerfile: Reproduzierbare (Multistage-)Builds mit definierter Maven- und JDK-Version
1 parent 78cc515 commit 30d61e3

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

phoneblock-ab/Dockerfile

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,55 @@
1-
FROM eclipse-temurin:17
2-
LABEL org.opencontainers.image.authors=play@haumacher.de
1+
# ===== Stage 1: Build the JAR using Maven =====
2+
FROM maven:3.9.9-eclipse-temurin-17 AS builder
3+
4+
ARG GITHUB_USER
5+
ARG GITHUB_TOKEN
6+
7+
# Set the working directory
8+
WORKDIR /build
9+
10+
# Configure Maven settings for GitHub Packages
11+
RUN mkdir -p /root/.m2
12+
RUN echo "<settings>\
13+
<servers>\
14+
<server>\
15+
<id>github</id>\
16+
<username>${GITHUB_USER}</username>\
17+
<password>${GITHUB_TOKEN}</password>\
18+
</server>\
19+
</servers>\
20+
</settings>" > /root/.m2/settings.xml
21+
22+
# Clone and install the missing dependency, see https://github.com/haumacher/phoneblock/issues/202 ---
23+
RUN git clone https://github.com/haumacher/java-utils-mail-dkim.git /tmp/java-utils-mail-dkim && \
24+
cd /tmp/java-utils-mail-dkim && \
25+
sed -i 's/<version>3.2.0<\/version>/<version>3.2.1-haumacher<\/version>/' pom.xml && \
26+
mvn clean install -DskipTests -Dspotbugs.skip=true && \
27+
rm -rf /tmp/java-utils-mail-dkim
28+
29+
# Copy the whole project
30+
COPY . .
31+
32+
# Pre-fetch dependencies (speeds up rebuilds)
33+
RUN mvn dependency:go-offline -B
34+
35+
# Build the project and package the jar with dependencies
36+
RUN mvn -am --projects de.haumacher:phoneblock-ab package -DskipTests
37+
38+
# ===== Stage 2: Runtime image =====
39+
FROM eclipse-temurin:17-jre
40+
LABEL org.opencontainers.image.authors="play@haumacher.de"
41+
342
USER root
443
RUN adduser --system --uid 999 --group --home /opt/phoneblock phoneblock
544

645
USER phoneblock
7-
RUN mkdir /opt/phoneblock/bin /opt/phoneblock/conversation /opt/phoneblock/recordings
8-
COPY --chown=phoneblock:phoneblock .phoneblock.docker /opt/phoneblock/.phoneblock
9-
COPY --chown=phoneblock:phoneblock target/phoneblock-ab-*-jar-with-dependencies.jar /opt/phoneblock/bin/phoneblock-ab.jar
46+
RUN mkdir -p /opt/phoneblock/bin /opt/phoneblock/conversation /opt/phoneblock/recordings
47+
COPY --from=builder --chown=phoneblock:phoneblock /build/phoneblock-ab/target/*-jar-with-dependencies.jar /opt/phoneblock/bin/
48+
COPY --chown=phoneblock:phoneblock phoneblock-ab/.phoneblock.docker ./.phoneblock
49+
50+
RUN for f in /opt/phoneblock/bin/*-jar-with-dependencies.jar; do \
51+
mv "$f" /opt/phoneblock/bin/phoneblock-ab.jar; \
52+
done
1053

1154
WORKDIR /opt/phoneblock/
1255
ENTRYPOINT ["java", "-jar", "/opt/phoneblock/bin/phoneblock-ab.jar"]

0 commit comments

Comments
 (0)