VERSION 0.7
FROM node:20-alpine3.18
WORKDIR /build

project:
   COPY . .
   RUN yarn install

build:
   FROM +project

   RUN yarn build

   SAVE ARTIFACT /build/_API /API
   SAVE ARTIFACT /build/Backend/lib /Backend
   SAVE ARTIFACT /build/Frontend/build /Frontend
   SAVE ARTIFACT /build/FrontendLegacy/out /FrontendLegacy

docker-multi:
   BUILD +build
   BUILD --platform linux/amd64 --platform linux/arm64 +docker

docker:
   FROM +project

#   RUN apk add --no-cache caddy supervisor

#   COPY ./supervisord.conf /etc/supervisord.conf
   
   COPY +build/API /build/_API
   COPY +build/Backend /build/Backend/lib
   COPY +build/Frontend /build/Frontend/build
   COPY +build/FrontendLegacy /build/FrontendLegacy/out

   WORKDIR /build/Backend

   ENTRYPOINT ["node", "lib/index.js"]

   ARG EARTHLY_TARGET_TAG
   ARG TAG=$EARTHLY_TARGET_TAG
   SAVE IMAGE --push git.hibas.dev/openserver/openauth:$TAG
