mirror of
https://github.com/Afilmory/afilmory
synced 2026-02-01 22:48:17 +00:00
feat(docker): add Dockerfile for Next.js app in pnpm monorepo
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
64
Dockerfile
Normal file
64
Dockerfile
Normal file
@@ -0,0 +1,64 @@
|
||||
# Dockerfile for Next.js app in a pnpm monorepo
|
||||
# This Dockerfile should be built from the root of the monorepo:
|
||||
# > docker build -t photo-gallery-ssr -f apps/ssr/dockerfile .
|
||||
|
||||
# -----------------
|
||||
# Base stage
|
||||
# -----------------
|
||||
FROM node:20-alpine AS base
|
||||
WORKDIR /app
|
||||
RUN corepack enable
|
||||
|
||||
# -----------------
|
||||
# Builder stage
|
||||
# -----------------
|
||||
FROM base AS builder
|
||||
|
||||
RUN apk update && apk add --no-cache git
|
||||
# Copy dependency definition files to leverage Docker cache
|
||||
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
|
||||
COPY package.json ./
|
||||
COPY apps/web/package.json ./apps/web/package.json
|
||||
COPY apps/ssr/package.json ./apps/ssr/package.json
|
||||
COPY packages/data/package.json ./packages/data/package.json
|
||||
|
||||
COPY scripts ./scripts
|
||||
COPY config.json ./
|
||||
COPY builder.config.json ./
|
||||
|
||||
# Install all dependencies
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Copy all source code
|
||||
COPY . .
|
||||
|
||||
# Build the app.
|
||||
# The build script in the ssr package.json handles building the web app first.
|
||||
RUN pnpm --filter=@photo-gallery/ssr build
|
||||
|
||||
# -----------------
|
||||
# Runner stage
|
||||
# -----------------
|
||||
FROM base AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
# ENV PORT and other configurations are now in the config files
|
||||
# and passed through environment variables during runtime.
|
||||
RUN apk add --no-cache curl wget
|
||||
# Create a non-root user
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
USER nextjs
|
||||
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/ssr/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/ssr/.next/static /app/apps/ssr/.next/static
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/ssr/public /app/apps/ssr/public
|
||||
|
||||
# The standalone output includes the server.js file.
|
||||
# The PORT environment variable is automatically used by Next.js.
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "apps/ssr/server.js"]
|
||||
Reference in New Issue
Block a user