ARG ENV=production ARG MONGO_VERSION=latest ARG PORT=9001 ARG NPM_TOKEN=not_set ARG YARN_VERSION=3.5.0 ## mongo build stage FROM mongo:$MONGO_VERSION AS database COPY docker-entrypoint-initdb.d/mongo-init-$MONGO_VERSION.sh ./docker-entrypoint-initdb.d/mongo-init.sh ## stage one, build the service FROM node:20-bullseye-slim AS build ENV YARN_VERSION $YARN_VERSION ENV NODE_ENV development ENV NPM_TOKEN $NPM_TOKEN WORKDIR /home/node/app COPY .npmrc /root COPY .build.yarnrc.yml /root/.yarnrc.yml COPY . . RUN yarn set version stable && yarn install RUN yarn build:production ## this is stage two , where the app actually runs FROM node:20-bullseye-slim AS containerize ENV YARN_VERSION $YARN_VERSION ENV NODE_ENV $ENV ENV NPM_TOKEN $NPM_TOKEN WORKDIR /home/node/app COPY .npmrc /root COPY .build.yarnrc.yml /root/.yarnrc.yml COPY package*.json yarn.lock ./ RUN yarn set version stable && yarn install && yarn cache clean COPY --from=build /home/node/app/dist ./ EXPOSE $PORT CMD ["node","index.js"]