-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (54 loc) · 2.76 KB
/
Copy pathDockerfile
File metadata and controls
61 lines (54 loc) · 2.76 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
# Next.js (App Router) build for the seastar-app monorepo, run under Bun.
# Built on a remote amd64 builder via ginger; deployed behind Traefik.
#
# Bun is pinned rather than tracking `oven/bun:1`: a floating base tag changes
# digest whenever upstream releases, which invalidates every layer below it and
# turns an incremental deploy into a full cold build. 1.3.14 is what local dev
# runs, and is what `oven/bun:1` resolved to when this was pinned.
FROM oven/bun:1.3.14 AS build
WORKDIR /app
# Dependencies first, in their own layer, so an ordinary source change reuses
# the cached install instead of re-resolving ~700MB of node_modules every
# deploy. Only the manifests are copied here — the workspace member manifests
# included, since `workspaces: [packages/*]` is resolved at install time and
# bun errors out if packages/sola-sdk/package.json is missing.
#
# --ignore-scripts avoids native builds (e.g. better-sqlite3) we don't need.
COPY package.json bun.lock ./
COPY packages/sola-sdk/package.json packages/sola-sdk/
RUN bun install --frozen-lockfile --ignore-scripts
# Now the source. node_modules is in .dockerignore, so this cannot clobber the
# install above. .env.production has to be in the context: `next build` reads it
# to inline NEXT_PUBLIC_* into the client bundle.
COPY . .
RUN bun --bun run build
# Runtime dependencies only. The build above needs the devDependencies
# (typescript, tailwind, postcss, sass), but `next start` does not — shipping
# them meant cypress/storybook/sass/typescript rode along in the deployed
# image, ~800MB of the 956MB node_modules, paid for on every push and pull.
FROM oven/bun:1.3.14 AS prod-deps
WORKDIR /app
COPY package.json bun.lock ./
COPY packages/sola-sdk/package.json packages/sola-sdk/
RUN bun install --frozen-lockfile --ignore-scripts --production
FROM oven/bun:1.3.14 AS production
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
# Only what `next start` actually reads at runtime. packages/ comes along because
# `@sola/sdk` resolves through the tsconfig path alias to
# packages/sola-sdk/src/index.ts; the bundler inlines it, but keeping the source
# present means nothing breaks if a server-side path ever resolves it lazily.
# .env.production is read on boot for server-side NEXT_PUBLIC_* reads (ginger
# also injects them at runtime; this keeps the two consistent).
COPY --from=prod-deps /app/node_modules node_modules
COPY --from=build /app/.next .next
COPY --from=build /app/public public
COPY --from=build /app/packages packages
COPY --from=build /app/package.json /app/next.config.mjs /app/.env.production ./
# Build-time incremental state — dead weight in a deployed image.
RUN rm -rf .next/cache
EXPOSE 3000
# `next start` serves the .next build on 0.0.0.0:$PORT.
ENTRYPOINT ["bun", "--bun", "run", "start"]