Created
January 30, 2025 14:18
-
-
Save PhantomKnight287/f10d7d990098ee05b02e1194f87b57db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use a specific version of Node | |
| FROM node:18-alpine AS base | |
| ARG DATABASE_URL | |
| ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser | |
| ENV DATABASE_URL=${DATABASE_URL} | |
| # Set up environment for pnpm | |
| ENV PNPM_HOME="/pnpm" | |
| ENV PATH="$PNPM_HOME:$PATH" | |
| # Install corepack, Turbo, and OpenSSL | |
| RUN apk add --no-cache libc6-compat openssl \ | |
| && apk update \ | |
| && corepack enable \ | |
| && pnpm i -g [email protected] | |
| # Create a builder stage | |
| FROM base AS builder | |
| # Install libc6-compat and OpenSSL (required for some dependencies) | |
| RUN apk add --no-cache libc6-compat openssl \ | |
| && apk update | |
| # Set working directory and copy project files | |
| WORKDIR /app | |
| COPY . . | |
| # Prune dependencies using Turbo | |
| RUN turbo prune --scope @[redacted]/backend --docker | |
| # Create an installer stage | |
| FROM base AS installer | |
| # Install libc6-compat and OpenSSL (required for some dependencies) | |
| RUN apk add --no-cache libc6-compat openssl \ | |
| && apk update | |
| # Set working directory and copy project files | |
| WORKDIR /app | |
| COPY .gitignore .gitignore | |
| COPY --from=builder /app/out/json/ . | |
| COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml | |
| COPY --from=builder /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml | |
| # Copy project files from the builder stage | |
| COPY --from=builder /app/out/full/ . | |
| # Install dependencies using pnpm | |
| RUN corepack enable \ | |
| && pnpm install -w [email protected] && pnpm install | |
| # Build the project | |
| RUN pnpx turbo run build --filter @[redacted]/backend | |
| # Create a runner stage | |
| FROM base AS runner | |
| # Set working directory | |
| WORKDIR /app | |
| # Install corepack, Chromium, and OpenSSL | |
| RUN apk add --no-cache \ | |
| chromium \ | |
| nss \ | |
| freetype \ | |
| harfbuzz \ | |
| ca-certificates \ | |
| ttf-freefont \ | |
| openssl | |
| # Add a system group and user for running the app | |
| RUN addgroup --system --gid 1001 nodejs \ | |
| && adduser --system --uid 1001 nestjs | |
| # Copy project files from the installer stage | |
| COPY --from=installer --chown=nestjs:nodejs /app/ . | |
| # Switch to the nestjs user and set the default command | |
| USER nestjs | |
| CMD ["pnpm", "start"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment