FROM gradle:7.5.1 as build_backend

COPY --chown=gradle:gradle /private/minis-backend /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle buildFatJar --no-daemon

FROM node:18 as build_frontend

RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY --chown=node:node /public ./

USER node
WORKDIR /home/node/app
RUN npm install
RUN npm run build-only


FROM openjdk:latest as miniplan
LABEL authors="walamana"

RUN mkdir -p /app/public
COPY --from=build_backend /home/gradle/src/build/libs/*.jar /app/backend.jar
COPY --from=build_frontend /home/node/app/dist /app/public
COPY /private/minis-backend/application_docker.conf /app/application.conf

WORKDIR /app

ENTRYPOINT ["java", "-jar", "backend.jar", "-config=application.conf"]
