Skip to content

Commit 6238fd8

Browse files
improve Dockerfile generation
1 parent 03c8a62 commit 6238fd8

3 files changed

Lines changed: 140 additions & 7 deletions

File tree

.dockerignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Build artifacts
2+
target/
3+
**/target/
4+
*.jar
5+
6+
# Maven local state
7+
.mvn/wrapper/maven-wrapper.jar
8+
dependency-reduced-pom.xml
9+
10+
# Git & GitHub
11+
.git/
12+
.gitignore
13+
.gitattributes
14+
.github/
15+
16+
# IDE / editor
17+
.idea/
18+
*.iml
19+
.vscode/
20+
.project
21+
.classpath
22+
.settings/
23+
*.swp
24+
25+
# OS / misc
26+
.DS_Store
27+
Thumbs.db
28+
29+
# Local Docker / dev
30+
Dockerfile
31+
.dockerignore
32+
docker-compose*.yml
33+
34+
# Docs that aren't needed in the build context
35+
README.markdown
36+
CHANGELOG
37+
LICENSE
38+
LICENSE.3RD_PARTY
39+
SECURITY.md
40+
CLAUDE.md

Dockerfile

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1+
# syntax=docker/dockerfile:1.7
2+
3+
# -------- Build stage --------
4+
FROM maven:3.9-eclipse-temurin-11 AS build
5+
WORKDIR /build
6+
7+
# Cache dependencies first
8+
COPY pom.xml ./
9+
RUN mvn -B -ntp dependency:go-offline
10+
11+
# Then bring sources and build the shaded JAR
12+
COPY src ./src
13+
RUN mvn -B -ntp -DskipTests \
14+
-Dgpg.skip=true \
15+
-Dmaven.javadoc.skip=true \
16+
-Dmaven.source.skip=true \
17+
package \
18+
&& mv target/TestingBotTunnel-*.jar target/testingbot-tunnel.jar
19+
20+
# -------- Runtime stage --------
121
FROM eclipse-temurin:11-jre-jammy
222
LABEL author="TestingBot <info@testingbot.com>"
323

4-
RUN apt-get update && apt-get install -y tini && rm -rf /var/lib/apt/lists/*
24+
# tini for proper PID-1 signal handling
25+
RUN apt-get update \
26+
&& apt-get install -y --no-install-recommends tini ca-certificates \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
# Non-root user
30+
RUN groupadd --system --gid 1001 tunnel \
31+
&& useradd --system --uid 1001 --gid tunnel --home-dir /home/tunnel --create-home tunnel
32+
33+
COPY --from=build --chown=tunnel:tunnel /build/target/testingbot-tunnel.jar /opt/testingbot/testingbot-tunnel.jar
34+
35+
USER tunnel
36+
WORKDIR /home/tunnel
537

6-
# Copy the pre-built JAR from the build context
7-
ARG JAR_FILE=target/TestingBotTunnel-*.jar
8-
COPY ${JAR_FILE} /testingbot-tunnel.jar
38+
# Metrics / insight endpoint (default --metrics-port 8003)
39+
EXPOSE 8003
940

10-
ENTRYPOINT ["/usr/bin/tini", "--", "java", "-jar", "/testingbot-tunnel.jar"]
41+
ENTRYPOINT ["/usr/bin/tini", "--", "java", "-jar", "/opt/testingbot/testingbot-tunnel.jar"]

pom.xml

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@
125125
<includes>
126126
<include>**/*Test.java</include>
127127
</includes>
128-
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED</argLine>
128+
<argLine>@{argLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED</argLine>
129129
<forkCount>1</forkCount>
130130
<reuseForks>false</reuseForks>
131131
</configuration>
132132
</plugin>
133133
<plugin>
134134
<groupId>org.apache.maven.plugins</groupId>
135135
<artifactId>maven-shade-plugin</artifactId>
136-
<version>3.2.4</version>
136+
<version>3.6.2</version>
137137
<executions>
138138
<execution>
139139
<phase>package</phase>
@@ -201,6 +201,68 @@
201201
<artifactId>versions-maven-plugin</artifactId>
202202
<version>2.18.0</version>
203203
</plugin>
204+
<plugin>
205+
<groupId>org.jacoco</groupId>
206+
<artifactId>jacoco-maven-plugin</artifactId>
207+
<version>0.8.13</version>
208+
<executions>
209+
<execution>
210+
<id>prepare-agent</id>
211+
<goals>
212+
<goal>prepare-agent</goal>
213+
</goals>
214+
</execution>
215+
<execution>
216+
<id>report</id>
217+
<phase>verify</phase>
218+
<goals>
219+
<goal>report</goal>
220+
</goals>
221+
</execution>
222+
</executions>
223+
</plugin>
224+
<plugin>
225+
<groupId>org.apache.maven.plugins</groupId>
226+
<artifactId>maven-enforcer-plugin</artifactId>
227+
<version>3.6.2</version>
228+
<dependencies>
229+
<dependency>
230+
<groupId>org.codehaus.mojo</groupId>
231+
<artifactId>extra-enforcer-rules</artifactId>
232+
<version>1.10.0</version>
233+
</dependency>
234+
</dependencies>
235+
<executions>
236+
<execution>
237+
<id>enforce</id>
238+
<phase>validate</phase>
239+
<goals>
240+
<goal>enforce</goal>
241+
</goals>
242+
<configuration>
243+
<rules>
244+
<requireJavaVersion>
245+
<version>[11,)</version>
246+
<message>TestingBot Tunnel requires Java 11 or higher to build.</message>
247+
</requireJavaVersion>
248+
<requireMavenVersion>
249+
<version>[3.6.0,)</version>
250+
</requireMavenVersion>
251+
<banDuplicatePomDependencyVersions/>
252+
<banDuplicateClasses>
253+
<findAllDuplicates>true</findAllDuplicates>
254+
<ignoreWhenIdentical>true</ignoreWhenIdentical>
255+
<!-- Multi-release JAR module-info entries collide harmlessly across modular deps. -->
256+
<ignoreClasses>
257+
<ignoreClass>module-info</ignoreClass>
258+
<ignoreClass>META-INF.versions.*.module-info</ignoreClass>
259+
</ignoreClasses>
260+
</banDuplicateClasses>
261+
</rules>
262+
</configuration>
263+
</execution>
264+
</executions>
265+
</plugin>
204266
</plugins>
205267
</build>
206268
<dependencies>

0 commit comments

Comments
 (0)