-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.native
More file actions
51 lines (37 loc) · 1.3 KB
/
Dockerfile.native
File metadata and controls
51 lines (37 loc) · 1.3 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
# Multi-stage build for GraalVM Native Image
# Stage 1: Build the native image
FROM ghcr.io/graalvm/native-image-community:21 AS builder
WORKDIR /build
# Install Maven
RUN microdnf install -y findutils wget && \
wget https://archive.apache.org/dist/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz && \
tar -xzf apache-maven-3.9.6-bin.tar.gz && \
mv apache-maven-3.9.6 /opt/maven && \
rm apache-maven-3.9.6-bin.tar.gz
ENV PATH="/opt/maven/bin:${PATH}"
# Copy project files
COPY pom.xml .
COPY src ./src
# Build native image
RUN mvn -Pnative clean package -DskipTests
# Stage 2: Create the runtime image
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.3
WORKDIR /app
# Copy the native executable
COPY --from=builder /build/target/cartonization /app/cartonization
# Create a non-root user
RUN microdnf install -y shadow-utils && \
useradd -u 1000 -r -g 0 -s /sbin/nologin \
-c "Application user" appuser && \
chown -R 1000:0 /app && \
chmod -R g=u /app && \
microdnf remove shadow-utils && \
microdnf clean all
USER 1000
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8080/api/v1/actuator/health || exit 1
# Run the native executable
ENTRYPOINT ["/app/cartonization"]