2022-05-14 10:22:06 +00:00
|
|
|
# base node image
|
|
|
|
FROM node:16-bullseye-slim as base
|
|
|
|
|
|
|
|
# set for base and all layer that inherit from it
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
|
|
|
|
# Install openssl for Prisma
|
|
|
|
RUN apt-get update && apt-get install -y openssl
|
|
|
|
|
|
|
|
# Install all node_modules, including dev dependencies
|
|
|
|
FROM base as deps
|
|
|
|
|
|
|
|
RUN mkdir /app
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
ADD package.json package-lock.json ./
|
|
|
|
RUN npm install --production=false
|
|
|
|
|
|
|
|
# Setup production node_modules
|
|
|
|
FROM base as production-deps
|
|
|
|
|
|
|
|
RUN mkdir /app
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
COPY --from=deps /app/node_modules /app/node_modules
|
|
|
|
ADD package.json package-lock.json ./
|
|
|
|
RUN npm prune --production
|
|
|
|
|
|
|
|
# Build the app
|
|
|
|
FROM base as build
|
|
|
|
|
|
|
|
RUN mkdir /app
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
COPY --from=deps /app/node_modules /app/node_modules
|
|
|
|
|
|
|
|
# Cache the prisma schema
|
|
|
|
ADD prisma .
|
|
|
|
RUN npx prisma generate
|
|
|
|
|
|
|
|
ADD . .
|
|
|
|
RUN npm run build
|
|
|
|
|
|
|
|
# Finally, build the production image with minimal footprint
|
|
|
|
FROM base
|
|
|
|
|
|
|
|
RUN mkdir /app
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
COPY --from=production-deps /app/node_modules /app/node_modules
|
|
|
|
COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma
|
|
|
|
COPY --from=build /app/build /app/build
|
|
|
|
COPY --from=build /app/public /app/public
|
2022-06-27 00:26:06 +00:00
|
|
|
COPY --from=build /app/server/index.js /app/server/index.js
|
2022-05-14 10:22:06 +00:00
|
|
|
ADD . .
|
|
|
|
|
|
|
|
CMD ["npm", "run", "start"]
|