Newer
Older
#---------- DEVELOPMENT ----------
FROM node:16-alpine AS development

Lukáš Kratochvíl
committed
# install node_modules outside app root in container so local development won't run into a problem of bind-mounting over it with local source code

Lukáš Kratochvíl
committed
WORKDIR /usr/src
COPY ["package.json", "package-lock.json", "./"]

Lukáš Kratochvíl
committed
# ensures that exactly these executables (from the node_modules folder) are used instead of any other executables which might also be installed on the system inside the Docker image

Lukáš Kratochvíl
committed
ENV PATH=/usr/src/node_modules/.bin:$PATH
WORKDIR /usr/src/app
COPY prisma/schema.prisma ./prisma/
RUN npx prisma generate
CMD ["npm", "run", "start:dev"]
#---------- PRODUCTION ----------
FROM node:16-alpine AS production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src
COPY --from=development /usr/src/package.json ./
COPY --from=development /usr/src/package-lock.json ./
# install only 'dependencies' and not 'devDependencies'
RUN npm install --omit=dev
# ensures that exactly these executables (from the node_modules folder) are used instead of any other executables which might also be installed on the system inside the Docker image
ENV PATH=/usr/src/node_modules/.bin:$PATH
WORKDIR /usr/src/app
COPY prisma/schema.prisma ./prisma/
RUN npx prisma generate
COPY --from=development /usr/src/app/dist ./dist
CMD ["npm", "run", "start:prod"]