forked from jithinrb/spring-boot-docker-aca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerfile
54 lines (37 loc) · 1.55 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
50
51
52
53
54
# ----------------------- Stage 1 (Install Maven and Build source code) -----------------------
# initialize build and set base image for first stage
FROM maven:3.9.3-eclipse-temurin-17-alpine as stage1
# speed up Maven JVM a bit
ENV MAVEN_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
# set working directory
WORKDIR /build
# copy just pom.xml
COPY 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 clean install -Dmaven.test.skip=true
RUN mvn clean verify -PintegrationTest
# ----- Stage 2 (Install JDK and create final image for Springboot app) -------------
# set base image for second stage
FROM openjdk:17-oraclelinux8
# Basic Props
VOLUME /tmp
EXPOSE 8080
# set deployment directory
WORKDIR /springboot-app
# copy over the built artifact from the maven image
COPY --from=stage1 /build/target/sb-docker-aca-*.jar /springboot-app/app.jar
ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar /springboot-app/app.jar
# ------------------------ Stage 3 (Test Stage) -----------------------
# Create a lightweight image for running tests
FROM openjdk:17-oraclelinux8 as test
# Set the working directory for tests
WORKDIR /test
# Copy the JAR file from the previous stage
COPY --from=stage1 /build/target/sb-docker-aca-*.jar /test/app.jar
# Run test command
CMD [".\mvnw", "test", "-f", ".\pom.xml"]
# ----------------------- End of Dockerfile -----------------------