FROM node:18-alpine AS build
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install
COPY . .

# typecheck because this isn't done automatically by the build process
RUN yarn tsc --noEmit

# bundle the code and its dependencies so we can copy just the bundle to the final image
# and get a much smaller container
RUN yarn run --silent rollup -c /app/src/session-backend/rollup.config.mjs > /app/bundle.mjs

FROM node:18-alpine
WORKDIR /app
COPY --from=build /app/bundle.mjs .
CMD ["node", "bundle.mjs"]