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

deps:
    COPY .yarnrc.yml .yarnrc.yml
    COPY .yarn .yarn
    COPY package.json .
    COPY Server/package.json Server/
    COPY Client/package.json Client/
    RUN apk add --no-cache git python3 make g++ gcc
    RUN yarn install

build:
    FROM +deps
    COPY Client ./Client
    COPY Server ./Server
    RUN yarn install
    RUN sh -c "find . -type f -name '*.ts' | grep -v node_modules"
    RUN yarn build
    SAVE ARTIFACT Client/dist /dist
    SAVE ARTIFACT Server/lib /lib

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

docker:
    FROM +deps

    COPY +build/lib ./Server/lib
    COPY +build/dist ./Server/public
    WORKDIR /build/Server

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

    ARG EARTHLY_TARGET_TAG
    ARG TAG=$EARTHLY_TARGET_TAG
    SAVE IMAGE --push git.hibas.dev/hibas123/screenshare:$TAG
