Skip to content

Commit eef32f4

Browse files
Add java dedup docker variants
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
1 parent 6926352 commit eef32f4

9 files changed

Lines changed: 64 additions & 16 deletions

java-dedup/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
/keploy/reports/
33
/dedupData.yaml
44
/duplicates.yaml
5+
/docker-compose-tmp.yaml
6+
/jacoco.exec
7+
/.java-sdk-installed
8+
/java-sdk/
59
/*.log

java-dedup/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ RUN groupadd --gid 10001 appuser \
88

99
COPY --chown=10001:10001 target/java-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
1010
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
11-
COPY --chown=10001:10001 target/classes /app/target/classes
12-
13-
ENV KEPLOY_JAVA_CLASS_DIRS=/app/target/classes
1411
EXPOSE 8080
1512
USER 10001:10001
1613
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar"]

java-dedup/Dockerfile.classpath

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ARG JAVA_VERSION=8
2+
FROM eclipse-temurin:${JAVA_VERSION}-jre
3+
4+
WORKDIR /app
5+
6+
RUN groupadd --gid 10001 appuser \
7+
&& useradd --uid 10001 --gid 10001 --home-dir /home/appuser --create-home --shell /usr/sbin/nologin appuser
8+
9+
COPY --chown=10001:10001 target/classes /app/classes
10+
COPY --chown=10001:10001 target/dependency /app/libs
11+
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
12+
13+
ENV KEPLOY_JAVA_CLASS_DIRS=/app/classes
14+
15+
EXPOSE 8080
16+
USER 10001:10001
17+
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-cp", "/app/classes:/app/libs/*", "io.keploy.samples.javadedup.JavaDedupApplication"]

java-dedup/Dockerfile.distroless

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM gcr.io/distroless/java17-debian12:nonroot
2+
3+
WORKDIR /app
4+
5+
COPY --chown=10001:10001 target/java-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
6+
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
7+
8+
EXPOSE 8080
9+
USER 10001:10001
10+
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=destfile=/tmp/jacoco.exec", "-jar", "/app/app.jar"]

java-dedup/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ The Java SDK reads JaCoCo coverage in-process via `org.jacoco.agent.rt.RT.getAge
99
## Setup
1010

1111
```bash
12-
(cd ../../java-sdk && mvn -B -DskipTests -Dgpg.skip=true install -pl keploy-sdk -am)
13-
mvn -B -DskipTests package
12+
(cd ../../java-sdk && mvn -B -DskipTests -Dgpg.skip=true clean install -pl keploy-sdk -am)
13+
mvn -B -DskipTests clean package
1414
```
1515

1616
This installs the sibling SDK snapshot locally, builds the sample, produces `target/java-dedup-0.0.1-SNAPSHOT.jar`, and copies `target/jacocoagent.jar` next to it.
@@ -20,7 +20,9 @@ This installs the sibling SDK snapshot locally, builds the sample, produces `tar
2020
```bash
2121
keploy test \
2222
-c "java -javaagent:target/jacocoagent.jar -jar target/java-dedup-0.0.1-SNAPSHOT.jar" \
23-
--dedup --language java --delay 20 \
23+
--dedup --language java --delay 1 \
24+
--health-url "http://127.0.0.1:8080/healthz" \
25+
--health-poll-timeout 30s \
2426
--disableMockUpload --disableReportUpload
2527

2628
keploy dedup --path .
@@ -33,10 +35,16 @@ docker compose build
3335
keploy test \
3436
-c "docker compose up" \
3537
--container-name "dedup-java" \
36-
--dedup --language java --delay 20 \
38+
--host "127.0.0.1" \
39+
--dedup --language java --delay 1 \
40+
--health-url "http://127.0.0.1:8080/healthz" \
41+
--health-poll-timeout 30s \
3742
--disableMockUpload --disableReportUpload
3843

3944
keploy dedup --path .
4045
```
4146

4247
During `keploy test`, Enterprise rewrites the Compose file and injects its own shared `/tmp` volume for the dedup control/data sockets. The base sample Compose file does not need a host `/tmp` bind mount.
48+
Re-run `docker compose build` whenever the jar, JaCoCo agent, or Dockerfile changes so replay uses the current image.
49+
50+
The CI pipeline also validates additional production-style Docker layouts for the same app, including exploded classpath, restricted runtime, and distroless packaging.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
java-dedup:
3+
build:
4+
dockerfile: Dockerfile.classpath
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
java-dedup:
3+
build:
4+
dockerfile: Dockerfile.distroless

java-dedup/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ services:
66
dockerfile: Dockerfile
77
args:
88
JAVA_VERSION: ${JAVA_VERSION:-8}
9+
environment:
10+
KEPLOY_JAVA_DEDUP_DIAGNOSTICS: ${KEPLOY_JAVA_DEDUP_DIAGNOSTICS:-}
911
container_name: dedup-java
1012
ports:
1113
- "${JAVA_DEDUP_HOST_PORT:-8080}:8080"
12-
environment:
13-
KEPLOY_JAVA_CLASS_DIRS: /app/target/classes

java-dedup/pom.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
<artifactId>keploy-sdk</artifactId>
3434
<version>${keploy.sdk.version}</version>
3535
</dependency>
36-
<dependency>
37-
<groupId>org.jacoco</groupId>
38-
<artifactId>org.jacoco.agent</artifactId>
39-
<version>${jacoco.version}</version>
40-
<classifier>runtime</classifier>
41-
<scope>runtime</scope>
42-
</dependency>
4336
</dependencies>
4437

4538
<build>
@@ -73,6 +66,17 @@
7366
</artifactItems>
7467
</configuration>
7568
</execution>
69+
<execution>
70+
<id>copy-runtime-dependencies</id>
71+
<phase>package</phase>
72+
<goals>
73+
<goal>copy-dependencies</goal>
74+
</goals>
75+
<configuration>
76+
<includeScope>runtime</includeScope>
77+
<outputDirectory>${project.build.directory}/dependency</outputDirectory>
78+
</configuration>
79+
</execution>
7680
</executions>
7781
</plugin>
7882
</plugins>

0 commit comments

Comments
 (0)