-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDockerfile.web
More file actions
86 lines (63 loc) · 2.83 KB
/
Dockerfile.web
File metadata and controls
86 lines (63 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# syntax=docker/dockerfile:1.7-labs
############################ base ##############################
FROM --platform=$TARGETPLATFORM node:25-alpine AS base
RUN apk update && apk add --no-cache libc6-compat curl bash ffmpeg jq git
# Install pnpm
RUN npm install -g pnpm@latest
# Equivalent to what we'd be doing with pnpm setup
ENV PNPM_HOME="/root/.local/share/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
############################ builder ###########################
FROM base AS builder
WORKDIR /app
RUN pnpm add -g turbo@^2
COPY . .
# Generate a partial monorepo with a pruned lockfile
RUN turbo prune @lapse/web --docker
############################ installer #########################
FROM base AS installer
WORKDIR /app
# We'll be passing this on to `generate-build-info.ts`.
ARG SOURCE_COMMIT
ENV SOURCE_COMMIT=${SOURCE_COMMIT}
# First install dependencies (they change less often)
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
# Copy prisma schema before install so postinstall can generate client
COPY --from=builder /app/out/full/apps/web/prisma ./apps/web/prisma
# Cache pnpm's global store to avoid network on rebuilds
RUN --mount=type=cache,id=pnpm-cache,target=/root/.local/share/pnpm \
--mount=type=cache,id=prisma-cache,target=/root/.cache/prisma \
pnpm install --frozen-lockfile
# Build the project and apps
COPY --from=builder /app/out/full/ .
# Write env vars to .env file for Next.js to read at build time
RUN printenv | grep -E '^(DATABASE_URL|JWT_SECRET|NEXT_PUBLIC_|PRIVATE_KEY_|S3_|SENTRY_|SLACK_|UPLOAD_TOKEN_)' > ./apps/web/.env || true
RUN --mount=type=cache,id=prisma-cache,target=/root/.cache/prisma \
--mount=type=cache,id=pnpm-cache,target=/root/.local/share/pnpm \
NODE_ENV=production pnpm turbo run build
# Apply database migrations
RUN cd apps/web && npx prisma migrate deploy
############################ runner ############################
FROM base AS runner
WORKDIR /app
# Non-root user
RUN addgroup -S nextjs && adduser -S nextjs -G nextjs
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=installer --chown=nextjs:nextjs /app/apps/web/.next/standalone ./
COPY --from=installer --chown=nextjs:nextjs /app/apps/web/.next/static ./apps/web/.next/static
COPY --from=installer --chown=nextjs:nextjs /app/apps/web/public ./apps/web/public
COPY --from=installer --chown=nextjs:nextjs /app/apps/web/prisma ./apps/web/prisma
# Switch to non-root user
USER nextjs
# Environment variables for nextjs user
ENV NODE_ENV=production
ENV PORT=3000
ENV NEXT_TELEMETRY_DISABLED=1
ENV PRISMA_HIDE_UPDATE_MESSAGE=1
ENV PNPM_HOME="/home/nextjs/.local/share/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
EXPOSE 3000
# Start NextJS (standalone ships server.js)
CMD ["sh","-c","HOSTNAME=0.0.0.0 node apps/web/server.js"]