forked from shadcn-ui/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
74 lines (55 loc) · 2.06 KB
/
Dockerfile
File metadata and controls
74 lines (55 loc) · 2.06 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
ARG NEXT_PUBLIC_APP_URL=https://ui.sciol.ac.cn
ARG NODE_VERSION=24
FROM node:${NODE_VERSION} AS base
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
PNPM_HOME=/pnpm
RUN corepack enable \
&& corepack prepare pnpm@latest --activate
ENV PATH=$PNPM_HOME:$PATH
# 1) Install dependencies with maximal cache reuse
FROM base AS deps
WORKDIR /app
# Only copy lockfile and workspace manifests for better caching
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json turbo.json tsconfig.json ./
COPY packages/shadcn/package.json packages/shadcn/
COPY packages/tests/package.json packages/tests/
COPY apps/v4/package.json apps/v4/
# If you have other apps/packages with postinstall/build hooks required for dependency graph,
# add their package.json similarly above to warm the install cache.
RUN pnpm fetch \
&& pnpm install --no-frozen-lockfile
# 2) Build the app
FROM base AS builder
WORKDIR /app
COPY --from=deps /app /app
ARG NEXT_PUBLIC_APP_URL
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
# Copy the full workspace (respect .dockerignore to keep context small)
COPY . .
# Build the v4 app (its script builds workspace package "shadcn" first)
RUN pnpm --filter v4 build
# 3) Create a minimal deployable directory for the v4 app with only prod deps
# This leverages pnpm deploy to gather exactly what's needed to run the app
FROM base AS deployer
WORKDIR /app
COPY --from=builder /app /app
ARG NEXT_PUBLIC_APP_URL
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
# Prune to production-only files for the v4 application
RUN pnpm deploy --filter v4 --prod /runtime
# 4) Final runtime image
FROM node:${NODE_VERSION} AS runner
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1
WORKDIR /app
ARG NEXT_PUBLIC_APP_URL
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
# Bring in the pruned app produced by pnpm deploy
COPY --from=deployer /runtime /app
# Expose the port used by apps/v4 (see scripts:start)
EXPOSE 3000
# Switch to the app workspace and drop privileges
WORKDIR /app/apps/v4
# Start Next.js in production
CMD ["node", "node_modules/next/dist/bin/next", "start", "-p", "3000"]