52 lines
1.8 KiB
Docker
52 lines
1.8 KiB
Docker
FROM node:alpine AS builder
|
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
ENV PNPM_HOME=/usr/local/bin
|
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
|
RUN apk add --no-cache libc6-compat
|
|
RUN apk update
|
|
# Set working directory
|
|
WORKDIR /app
|
|
RUN pnpm add -g turbo dotenv-cli
|
|
COPY . .
|
|
RUN turbo prune --scope=web --docker
|
|
|
|
# Add lockfile and package.json's of isolated subworkspace
|
|
FROM node:alpine AS installer
|
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
ENV PNPM_HOME=/usr/local/bin
|
|
RUN apk add --no-cache libc6-compat
|
|
RUN apk update
|
|
WORKDIR /app
|
|
|
|
# First install the dependencies (as they change less often)
|
|
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
|
|
RUN pnpm install
|
|
|
|
# Build the project
|
|
COPY --from=builder /app/out/full/ .
|
|
COPY turbo.json turbo.json
|
|
COPY .env .env
|
|
RUN pnpm dotenv -e .env turbo run build --filter=web...
|
|
|
|
FROM node:alpine AS runner
|
|
WORKDIR /app
|
|
|
|
# Don't run production as root
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
USER nextjs
|
|
|
|
COPY --from=installer /app/apps/web/next.config.js .
|
|
COPY --from=installer /app/apps/web/package.json .
|
|
COPY .env .env
|
|
|
|
# Automatically leverage output traces to reduce image size
|
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
|
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
|
|
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
|
|
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public
|
|
|
|
CMD node apps/web/server.js |