-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathDockerfile
25 lines (19 loc) · 836 Bytes
/
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
# Stage 1: Build the jar
FROM gradle:8.12-jdk21 AS build
# Copy source code into the container and set the ownership to 'gradle' user
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle build -x test --no-daemon
# Stage 2: Production image
FROM openjdk:21-slim AS production
EXPOSE 8080
# Create a non-root user and group (using 'appuser' as an example)
RUN groupadd -r appgroup && useradd -r -g appgroup -m appuser
# Create the /app directory and set permissions
RUN mkdir /app && chown appuser:appgroup /app
# Copy the jar file from the build stage into the production image
COPY --from=build /home/gradle/src/build/libs/*.jar /app/companieshouse-*.jar
# Change to non-root user
USER appuser
# Set the entrypoint to run the Java application
ENTRYPOINT ["java", "-jar", "/app/companieshouse-*.jar"]