-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathDockerfile
42 lines (33 loc) · 1.02 KB
/
Dockerfile
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
# Stage 1
# Use a base image with Maven and JDK 17
FROM maven:3.8.1-openjdk-17 AS stage1
# Speed up Maven JVM a bit
ENV MAVEN_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
# Set working directory
WORKDIR /app
# Copy just pom.xml
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
# Go-offline using the pom.xml
RUN mvn dependency:go-offline
# Copy your other files
COPY ./src ./src
# Compile the source code and package it in a jar file
RUN mvn package -Dmaven.test.skip=true
# Stage 2
# Use a base image with Eclipse Temurin JRE 17
FROM eclipse-temurin:17-jre-alpine
# Set deployment directory
WORKDIR /app
# Copy over the built artifact from the maven image
COPY --from=stage1 /app/target/*.jar app.jar
# Create a non-root user and group
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Change ownership of the application files to the non-root user
RUN chown -R appuser:appgroup /app
# Switch to the non-root user
USER appuser
# Expose the application port
EXPOSE 8080
# Run the application
CMD ["java", "-jar", "app.jar"]