FROM maven:3.9.9-eclipse-temurin-17 AS build

WORKDIR /workspace
COPY pom.xml .
COPY mvnw .
COPY .mvn .mvn
RUN chmod +x mvnw && sed -i 's/\r$//' mvnw

COPY src src
RUN ./mvnw -DskipTests package

FROM eclipse-temurin:17-jre-alpine

WORKDIR /app
ENV JAVA_OPTS=""

COPY --from=build /workspace/target/ems-backend-0.0.1-SNAPSHOT.jar /app/app.jar
COPY json-db /app/json-db
COPY uploads /app/uploads

EXPOSE 8080
VOLUME ["/app/json-db", "/app/uploads"]

ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"]
