forked from pbrane/tac-case-api-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
49 lines (35 loc) · 1.57 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
43
44
45
46
47
48
49
# Use OpenJDK as the base image for Java 21
FROM openjdk:21-jdk-slim AS builder
# Set the JAVA_HOME environment variable to the correct path for OpenJDK
# The path may vary; you can check it by running: docker run --rm openjdk:21-jdk-slim bash -c 'echo $JAVA_HOME'
ENV JAVA_HOME=/usr/local/openjdk-21
ENV PATH="$JAVA_HOME/bin:$PATH"
# Set the working directory inside the container
WORKDIR /app
# Install necessary utilities like wget and tar for Maven installation
RUN apt-get update && apt-get install -y wget tar && rm -rf /var/lib/apt/lists/*
# Download and install Maven separately to ensure mvnw can work
RUN wget -qO- https://downloads.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz | tar xz -C /opt \
&& ln -s /opt/apache-maven-3.9.9 /opt/maven
# Set Maven environment variables
ENV MAVEN_HOME=/opt/maven
ENV PATH="$MAVEN_HOME/bin:$PATH"
# Copy the Maven wrapper and configuration files to the container
COPY pom.xml mvnw ./
COPY .mvn .mvn
# Run Maven to download dependencies
RUN mvn dependency:go-offline
# Copy the source code to the container
COPY src src
# Build the application
RUN mvn clean package -DskipTests
# Use a minimal runtime image for the final stage
FROM openjdk:21-jdk-slim
# Set the working directory for the runtime container
WORKDIR /app
# Copy the JAR file from the builder stage to the runtime stage
COPY --from=builder /app/target/client-api-demo-*.jar /app/client-api-demo.jar
# Expose the port the application runs on
EXPOSE 8080
# Define the command to run the application
ENTRYPOINT ["java", "-jar", "/app/client-api-demo.jar"]