FROM openjdk:17 AS builder

COPY src /app/src
#COPY keystore.jceks /app/keystore.jceks
COPY gradle /app/gradle
COPY build.gradle settings.gradle gradle.properties gradlew /app/
WORKDIR /app
RUN ./gradlew assemble

FROM openjdk:17 AS test

COPY --from=builder /app/build /app/build
COPY --from=builder /app/gradle /app/gradle
COPY --from=builder /app/build.gradle /app/
COPY --from=builder /app/settings.gradle /app/
COPY --from=builder /app/gradle.properties /app/
COPY --from=builder /app/gradlew /app/

WORKDIR /app

RUN ./gradlew test

FROM openjdk:17-jdk-slim-buster AS production

COPY --from=builder /app/build/libs/ /app/
COPY --from=builder /app/gradle.properties /app/
#COPY --from=builder /app/keystore.jceks /app/

WORKDIR /app

CMD java -cp "analytics.jar" cz.senslog.analytics.app.Main

FROM openjdk:17-jdk-slim-buster AS dev-debug

COPY --from=builder /app/build/libs/ /app/
COPY --from=builder /app/gradle.properties /app/
#COPY --from=builder /app/keystore.jceks /app/

WORKDIR /app

CMD java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -cp "analytics.jar" cz.senslog.analytics.app.Main