2024-01-15 12:01:16 +01:00
|
|
|
# BUILD STAGE
|
2024-04-05 10:56:07 +02:00
|
|
|
FROM amazoncorretto:22 as build
|
2024-01-15 12:01:16 +01:00
|
|
|
LABEL author="Marco Cetica"
|
|
|
|
|
|
|
|
# Prepare working environment
|
|
|
|
WORKDIR /workspace/app
|
|
|
|
COPY mvnw .
|
|
|
|
COPY .mvn .mvn
|
|
|
|
COPY pom.xml .
|
|
|
|
COPY src src
|
|
|
|
|
|
|
|
# Set environment variables for unit testing
|
|
|
|
ARG SERVER_PORT="3000"
|
|
|
|
ARG SPRING_DATASOURCE_URL="jdbc:h2:mem:testdb"
|
|
|
|
ARG SPRING_DATASOURCE_DRIVERCLASSNAME="org.h2.Driver"
|
2024-01-16 09:24:04 +01:00
|
|
|
ARG SPRING_DATASOURCE_USERNAME="test"
|
|
|
|
ARG SPRING_DATASOURCE_PASSWORD="test"
|
2024-01-15 12:01:16 +01:00
|
|
|
|
|
|
|
# Build the jar file and execute the unit tests
|
2024-01-16 09:34:19 +01:00
|
|
|
RUN chmod +x mvnw && ./mvnw package
|
2024-01-15 12:01:16 +01:00
|
|
|
|
|
|
|
# RUN STAGE
|
|
|
|
FROM amazoncorretto:21 as run
|
|
|
|
|
|
|
|
# Configure working environment
|
|
|
|
VOLUME /tmp
|
|
|
|
ARG BUILD=/workspace/app/target
|
|
|
|
|
|
|
|
# Copy jar file
|
|
|
|
COPY --from=build ${BUILD}/*.jar app.jar
|
|
|
|
|
|
|
|
# Run the application
|
|
|
|
ENTRYPOINT ["java", "-jar", "app.jar"]
|
|
|
|
|