# First stage: complete build environment
FROM maven:3.8.4-eclipse-temurin-11-alpine AS builder

# add pom.xml 
COPY pom.xml .

RUN mvn -B dependency:go-offline 

# add later source code

ADD ./src src/

# package jar
RUN mvn -B package

# Second stage: minimal runtime environment
FROM eclipse-temurin:11-jre-alpine

# copy jar from the first stage
COPY --from=builder target/demo-1.0-SNAPSHOT.jar demo-1.0-SNAPSHOT.jar

EXPOSE 8080

CMD ["java", "-jar", "demo-1.0-SNAPSHOT.jar"]