-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathDockerfileTest
More file actions
56 lines (45 loc) · 2.06 KB
/
DockerfileTest
File metadata and controls
56 lines (45 loc) · 2.06 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
# -----------------------------
# Builder stage
# -----------------------------
# Uses Maven with Eclipse Temurin Java 21 on Alpine.
# This stage builds the application jar only.
FROM maven:3.9.15-eclipse-temurin-21-alpine AS builder
# Copy the full project into the build container.
COPY ./ /usr/src/app/
# Set project directory.
WORKDIR /usr/src/app/
# Build the project and create the application jar.
# -B = batch mode, useful for CI
# -ntp = no transfer progress, cleaner logs
# Tests and JaCoCo are skipped because this image only needs the built runtime jar.
RUN mvn -B -ntp install \
-Dmaven.test.skip=true \
-Djacoco.skip=true \
-Dskip.generate=true > /dev/null
# -----------------------------
# Final runtime stage
# -----------------------------
# Uses a smaller Alpine-based Eclipse Temurin Java 21 JRE image.
# This avoids the Ubuntu-based OS package vulnerabilities reported by Snyk.
FROM eclipse-temurin:21.0.10_7-jre-alpine-3.23
# Set the runtime directory.
WORKDIR /usr/src/run/
# Copy only the built jar from the builder stage.
# This keeps Maven, source code, and build dependencies out of the final image.
COPY --from=builder /usr/src/app/rest-api/target/rest-api.jar /usr/src/run/rest-api.jar
# Copy test runtime artifacts, including qppConverterTest.sh.
COPY --from=builder /usr/src/app/tools/docker/docker-test-artifacts/ /usr/src/run/
# Fix the startup script for Alpine runtime:
# 1. Remove Windows CRLF line endings if present.
# 2. Replace #!/bin/bash with #!/bin/sh because Alpine does not include bash by default.
# 3. Make the script executable.
# 4. Validate that the jar and startup script exist during image build.
RUN sed -i 's/\r$//' /usr/src/run/qppConverterTest.sh \
&& sed -i '1s|^#!/bin/bash|#!/bin/sh|' /usr/src/run/qppConverterTest.sh \
&& chmod +x /usr/src/run/qppConverterTest.sh \
&& test -f /usr/src/run/rest-api.jar \
&& test -f /usr/src/run/qppConverterTest.sh
# Application test container listens on 8080.
EXPOSE 8080
# Start the test application using the startup script.
ENTRYPOINT ["/usr/src/run/qppConverterTest.sh"]