-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfileNative.Multistage
More file actions
42 lines (30 loc) · 970 Bytes
/
DockerfileNative.Multistage
File metadata and controls
42 lines (30 loc) · 970 Bytes
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
# First stage: JDK with GraalVM
FROM container-registry.oracle.com/graalvm/native-image:25 AS build
# Update package lists and Install Maven
RUN microdnf install -y maven
RUN microdnf clean all
#ENV GRAALVM_HOME="$JAVA_HOME"
WORKDIR /usr/src/app
# Copy pom.xml and download dependencies
COPY pom.xml .
RUN mvn -Pnative dependency:go-offline
COPY src src
RUN mvn package
RUN mvn -PnativeTest test
RUN mvn -Pnative -DskipTests clean native:compile
## Second stage: Lightweight image
FROM alpine:latest
# prepare to run glibc programs
RUN apk add gcompat
# Create non-root user
RUN apk add --no-cache shadow && \
groupadd -g 1000 appuser && \
useradd -u 1000 -g 1000 -m appuser && \
mkdir -p /app && \
chown -R appuser:appuser /app
WORKDIR /app
# Copy the native binary from the build stage
COPY --from=build --chown=appuser:appuser /usr/src/app/target/k8s-demo-app /app/k8s-demo-app
USER appuser
EXPOSE 8080/tcp
ENTRYPOINT ["/app/k8s-demo-app"]