# stage deps
FROM node:18.17.0 AS deps
WORKDIR /usr/src/app
COPY package*.json yarn.lock ./
RUN yarn install # Install both production and development dependencies
# stage builder
FROM node:18.17.0 AS builder
COPY --from=deps ./
COPY . .
RUN yarn build
RUN yarn install --production
# Production image
FROM node:18.17.0-alpine
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./dist/node_modules
# Prune development dependencies
CMD ["node", "dist/main"]