FROM eclipse-temurin:21-jdk-alpine AS builder

WORKDIR /workspace/app

RUN mkdir -p ../api

COPY api/legalconsenthub.yml ../api/

COPY legalconsenthub-backend/gradlew .
COPY legalconsenthub-backend/gradle gradle
COPY legalconsenthub-backend/build.gradle .
COPY legalconsenthub-backend/settings.gradle .

RUN chmod +x ./gradlew

RUN ./gradlew dependencies --no-daemon

COPY legalconsenthub-backend/src src

RUN ./gradlew bootJar -x test --no-daemon

FROM eclipse-temurin:21-jre-alpine AS runner

WORKDIR /app

RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring

COPY --from=builder /workspace/app/build/libs/*.jar app.jar

ENV SPRING_PROFILES_ACTIVE=prod
ENV JAVA_OPTS="-Xms256m -Xmx512m"

EXPOSE 8080

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

