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

Lukáš Kratochvíl
committed
# we do not want to run under the root user
USER node

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

Lukáš Kratochvíl
committed
COPY --chown=node:node ["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

Lukáš Kratochvíl
committed
COPY --chown=node:node prisma/schema.prisma ./prisma/

Lukáš Kratochvíl
committed
COPY --chown=node:node . .
CMD ["npm", "run", "start:dev"]
#---------- PRODUCTION ----------
FROM node:16-alpine AS production

Lukáš Kratochvíl
committed
# we do not want to run under the root user
USER node
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src

Lukáš Kratochvíl
committed
COPY --chown=node:node --from=development /usr/src/package.json ./
COPY --chown=node:node --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

Lukáš Kratochvíl
committed
COPY --chown=node:node prisma/schema.prisma ./prisma/
RUN npx prisma generate

Lukáš Kratochvíl
committed
COPY --chown=node:node --from=development /usr/src/app/dist ./dist
CMD ["npm", "run", "start:prod"]