Skip to content

Instantly share code, notes, and snippets.

@Sytten
Last active October 21, 2021 01:19
Show Gist options
  • Save Sytten/c1a4a0159a14cb4ee09a46d837257937 to your computer and use it in GitHub Desktop.
Save Sytten/c1a4a0159a14cb4ee09a46d837257937 to your computer and use it in GitHub Desktop.
Dockerfile for Typescript, Prisma2 and lerna
### BASE ###
FROM node:12-buster-slim AS base
RUN apt-get update && apt-get install --no-install-recommends --yes openssl
WORKDIR /app
### BUILDER ###
FROM base AS builder
# Install production dependencies
COPY *.json yarn.lock ./
COPY packages/common/*.json ./packages/common/
COPY packages/backend/*.json ./packages/backend/
RUN yarn install --production --pure-lockfile
RUN cp -RL packages/backend/node_modules/ /tmp/node_modules/
# Install all dependencies
RUN yarn install --pure-lockfile
# Copy source files
COPY packages/common/ ./packages/common/
COPY packages/backend/ ./packages/backend/
# Build
RUN yarn --cwd ./packages/common/ build
RUN yarn --cwd ./packages/backend/ generate
RUN yarn --cwd ./packages/backend/ build
### RUNNER ###
FROM base
# Copy runtime dependencies
COPY --from=builder /tmp/node_modules/ ./node_modules/
COPY --from=builder /app/packages/backend/node_modules/@prisma/client/ ./node_modules/@prisma/client/
COPY --from=builder /app/packages/backend/node_modules/.prisma/client/ ./node_modules/.prisma/client/
COPY --from=builder /app/packages/common/dist/ ./node_modules/common/dist/
# Copy runtime project
COPY --from=builder /app/packages/backend/dist/src/ ./src/
COPY packages/backend/package.json ./
USER node
CMD ["node", "-r", "tsconfig-paths/register", "src/server.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment