forked from Sunagatov/Iced-Latte
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (42 loc) · 1.43 KB
/
Copy pathDockerfile
File metadata and controls
54 lines (42 loc) · 1.43 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
#
# Build stage with Maven
#
FROM maven:3.8.3-openjdk-17 as maven_build
# Create builder user
RUN groupadd -r builder && useradd -r -g builder builder
WORKDIR /opt/app
# Ensure that the builder user has a maven repository directory
RUN mkdir -p /home/builder/.m2 && chown -R builder:builder /home/builder/.m2
# Copy only necessary files for dependency resolution
COPY pom.xml .env ./
# Set user to builder for safety
USER builder
# Resolve dependencies
RUN export APP_ENV=$(grep APP_ENV .env | cut -d '=' -f2) && \
mvn dependency:go-offline -P${APP_ENV}
# Copy the source and build the application
COPY --chown=builder:builder . ./
RUN set -ex; \
export APP_ENV=$(grep APP_ENV .env | cut -d '=' -f2) && \
mvn versions:set-property -Dproperty=project.version -DnewVersion=${APP_VERSION} && \
mvn package -P${APP_ENV}
#
# Production stage
#
FROM eclipse-temurin:17-jre-jammy as prod
WORKDIR /opt/app
# Install necessary dependencies and cleanup
RUN apt-get update && \
apt-get install -y netcat acl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Copy compiled JAR, environment file, and entrypoint script
COPY --from=maven_build /opt/app/target/*.jar ./app.jar
COPY --from=maven_build /opt/app/.env ./.env
COPY --from=maven_build /opt/app/docker/docker-entrypoint.sh ./docker-entrypoint.sh
# Set permissions for entrypoint script
RUN chmod +x ./docker-entrypoint.sh
#
# Entrypoint
#
ENTRYPOINT ["./docker-entrypoint.sh"]