# syntax=docker.io/docker/dockerfile:1.3@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2
FROM node:18-alpine@sha256:44aaf1ccc80eaed6572a0f2ef7d6b5a2982d54481e4255480041ac92221e2f11 as cli-build

# Copy package.json & package-lock.json by themselves to create a cache layer
COPY clients/js/package.json clients/js/package-lock.json /clients/js/

WORKDIR /clients/js

RUN npm ci

# Copy the rest of the source files, as a layer on top of the deps
COPY clients/js /clients/js

# Build CLI
RUN npm run build

FROM scratch AS cli-export

COPY --from=cli-build clients/js/build/main.js clients/js/build/main.js
COPY --from=cli-build clients/js/package.json clients/js/package.json
