Skip to content

Instantly share code, notes, and snippets.

@callingmedic911
Created May 9, 2022 08:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save callingmedic911/791f6f9d3d07f78c643c98e8ccf86db6 to your computer and use it in GitHub Desktop.
Save callingmedic911/791f6f9d3d07f78c643c98e8ccf86db6 to your computer and use it in GitHub Desktop.
**/node_modules
# Stage 1: Node alpine base image
FROM node:16-alpine as base
ENV NODE_ENV=production
WORKDIR /app
COPY package.json package.json
COPY web/package.json web/package.json
COPY api/package.json api/package.json
COPY yarn.lock yarn.lock
COPY .yarnrc.yml .yarnrc.yml
COPY .yarn/releases .yarn/releases
RUN yarn install --immutable --inline-builds
COPY redwood.toml .
COPY graphql.config.js .
# Stage 2: Generate web build with selected env variables
FROM base as web_build
# TODO: To make includeEnvironmentVariables work, setup ENV here
COPY web web
RUN yarn rw build web
# Stage 3: Generate api build
FROM base as api_build
COPY api api
RUN yarn rw build api
# Stage 4: Prepare api dependencies (this layer has prisma and yarn cache)
FROM node:16-alpine as api_with_minimal_dep
ENV NODE_ENV=production
WORKDIR /app
# Only install API packages to keep image small
COPY api/package.json .
COPY .yarn/releases .yarn/releases
COPY yarn.lock .
COPY .yarnrc.yml .
RUN yarn install --inline-builds && yarn add react react-dom @redwoodjs/api-server @redwoodjs/internal prisma
# Stage 5: Use minimal alpine image and copy api dependencies (no cached file)
FROM node:16-alpine
ENV NODE_ENV=production
WORKDIR /app
COPY .yarn/releases .yarn/releases
COPY .yarnrc.yml .
COPY graphql.config.js .
COPY redwood.toml .
COPY --from=api_with_minimal_dep /app/package.json /app/
COPY --from=api_with_minimal_dep /app/yarn.lock /app/
COPY --from=web_build /app/web/dist /app/web/dist
COPY --from=api_build /app/api/dist /app/api/dist
COPY --from=api_build /app/api/db /app/api/db
COPY --from=api_with_minimal_dep /app/node_modules /app/node_modules
COPY --from=api_build /app/node_modules/.prisma /app/node_modules/.prisma
CMD [ "node_modules/.bin/rw-server" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment