Skip to content

Commit 499a4d2

Browse files
committed
perf(ci): build the app image on 16 vCPU and keep the toolchain out of it
Three independent changes to the app image build. The app image builds on 16 vCPU instead of 8. Its dominant steps -- bun install (~300-465s) and next build (~262s) -- both scale with cores, and this build gates every deploy because nothing ships until the image is pushed. The same next build already runs on 16 vCPU in the Build App verification job, which gates nothing. The isolated-vm rebuild will not benefit: JOBS=4 caps it deliberately to avoid an OOM. ARM64 stays at 8 -- that job is off the deploy path, and the workflow warns an unprovisioned runner label hangs a release in queued. node-gyp comes from the lockfile rather than npx. npx resolved it from the registry during every production image build, which pulled 13.x over the pinned 12.4.0 and bypassed the minimumReleaseAge gate in bunfig.toml. It has to be an apps/sim devDependency because the only other copy is transitive through @electron/rebuild, which turbo prune sim strips. base splits into base and build-base. The compiler toolchain exists only to build isolated-vm against Node and the runner copies the finished binary, so shipping it inflated every ECS task pull: measured 1.21 GB for base against 1.6 GB for build-base, so ~390 MB stays out of the final image. ffmpeg and python3 stay -- fluent-ffmpeg is a serverExternalPackage, and node-gyp needs the interpreter. Verified against real image builds rather than by inspection: g++/make/pip3 are absent from the runtime image while node/bun/python3/ffmpeg remain, the isolated-vm native module loads and evaluates, lib0/yjs/y-protocols including the lib0/logging.js subpath are intact, sharp and libvips load and encode a PNG so #6499's fix still works against the slimmed image, the container boots to Next.js Ready, and the full suite passes 21250 tests through the dependency hoisting reshuffle that promoting node-gyp causes (root which@6.0.1, fluent-ffmpeg keeps its own 1.3.1). Not included: an earlier attempt added a cache-key input to useblacksmith/setup-docker-builder, on the theory that the deps layer re-runs every build (286s/465s observed) because all five Dockerfiles share one layer cache. That input does not exist at the pinned SHA or on main, and the key is not configurable -- setup_builder.ts uses GITHUB_REPO_NAME. CI logs also show the sticky disk being obtained with a parent snapshot rather than falling back, so the cache is present and that cause remains unidentified.
1 parent c9f7354 commit 499a4d2

4 files changed

Lines changed: 60 additions & 25 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,20 @@ jobs:
155155
fail-fast: false
156156
matrix:
157157
include:
158-
# Only the app image needs the paid 8-core/32 GB runner: next build
159-
# exhausts the free 16 GB one (exit 137). The others build in <5 min.
160-
# bs_runner mirrors that per-image sizing on Blacksmith — a single
161-
# pinned tier put every image on 8 vCPU, where the non-app builds idle
162-
# at 12-15% CPU and under 10% memory.
158+
# Only the app image needs a large runner: next build exhausts the free
159+
# 16 GB one (exit 137). The others build in <5 min and idle at 12-15%
160+
# CPU on 8 vCPU, so they stay on the smaller tiers.
161+
#
162+
# 16 vCPU on Blacksmith because this build is the critical path to a
163+
# deploy — nothing ships until the image is pushed — and its two
164+
# dominant steps both scale with cores (`bun install` ~300-400s, `next
165+
# build` ~260s). The same `next build` runs on 16 vCPU in the separate
166+
# Build App verification job, which does not gate anything; this one
167+
# was doing comparable work on half the cores.
163168
- dockerfile: ./docker/app.Dockerfile
164169
ecr_repo_secret: ECR_APP
165170
gh_runner: linux-x64-8-core
166-
bs_runner: blacksmith-8vcpu-ubuntu-2404
171+
bs_runner: blacksmith-16vcpu-ubuntu-2404
167172
- dockerfile: ./docker/db.Dockerfile
168173
ecr_repo_secret: ECR_MIGRATIONS
169174
gh_runner: ubuntu-latest
@@ -278,7 +283,7 @@ jobs:
278283
ghcr_image: ghcr.io/simstudioai/simstudio
279284
ecr_repo_secret: ECR_APP
280285
gh_runner: linux-x64-8-core
281-
bs_runner: blacksmith-8vcpu-ubuntu-2404
286+
bs_runner: blacksmith-16vcpu-ubuntu-2404
282287
- dockerfile: ./docker/db.Dockerfile
283288
ghcr_image: ghcr.io/simstudioai/migrations
284289
ecr_repo_secret: ECR_MIGRATIONS

apps/sim/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
"@types/three": "0.177.0",
264264
"@vitejs/plugin-react": "^6.0.5",
265265
"@vitest/coverage-v8": "^4.1.0",
266+
"node-gyp": "12.4.0",
266267
"postcss": "^8",
267268
"react-email": "6.9.0",
268269
"tailwindcss": "^3.4.1",

bun.lock

Lines changed: 14 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/app.Dockerfile

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
11
# ========================================
2-
# Base Stage: Debian-based Bun with Node.js 24
2+
# Base Stage: runtime-only dependencies (inherited by the final image)
33
# ========================================
44
FROM oven/bun:1.3.14-slim AS base
55

6-
# Install Node.js 24 (Active LTS) and common dependencies once in base stage.
6+
# Install Node.js 24 (Active LTS) and the runtime dependencies once in base.
77
# Node runs only the isolated-vm sandbox worker (the app itself runs under Bun);
88
# the version is kept in lockstep with the `isolated-vm` pin in
99
# apps/sim/package.json — Node 24 (ABI 137) requires isolated-vm 6.x.
10+
#
11+
# Only what the running container needs belongs here. ffmpeg backs the
12+
# `fluent-ffmpeg` serverExternalPackage; python3 is the node-gyp interpreter and
13+
# is kept because build-base inherits from this stage. The compiler toolchain
14+
# lives in build-base so the runner does not ship it.
1015
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
1116
--mount=type=cache,target=/var/lib/apt,sharing=locked \
1217
apt-get update && apt-get install -y --no-install-recommends \
13-
python3 python3-pip python3-venv make g++ curl ca-certificates bash ffmpeg \
18+
python3 curl ca-certificates bash ffmpeg \
1419
&& curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
1520
&& apt-get install -y nodejs
1621

22+
# ========================================
23+
# Build Base: adds the native toolchain the isolated-vm rebuild needs
24+
# ========================================
25+
FROM base AS build-base
26+
27+
# The compiler toolchain, needed only to build isolated-vm against Node. The
28+
# runner copies the finished binary from deps, so shipping these would inflate
29+
# every ECS task pull for nothing: measured 1.21 GB for base against 1.6 GB for
30+
# build-base, so ~390 MB stays out of the final image.
31+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
32+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
33+
apt-get update && apt-get install -y --no-install-recommends \
34+
python3-pip python3-venv make g++
35+
1736
# ========================================
1837
# Pruner Stage: Emit a minimal monorepo subset that sim depends on
1938
# ========================================
20-
FROM base AS pruner
39+
FROM build-base AS pruner
2140
WORKDIR /app
2241

2342
RUN bun install -g turbo@2.9.6
@@ -29,7 +48,7 @@ RUN turbo prune sim --docker
2948
# ========================================
3049
# Dependencies Stage: Install Dependencies
3150
# ========================================
32-
FROM base AS deps
51+
FROM build-base AS deps
3352
WORKDIR /app
3453

3554
# Pruned manifests from the pruner stage. This layer only invalidates when
@@ -44,15 +63,22 @@ COPY --from=pruner /app/bun.lock ./bun.lock
4463
# Install all dependencies (including devDependencies — tailwindcss/postcss are
4564
# devDeps but required at build time). Then rebuild isolated-vm against Node.js.
4665
# JOBS=4 caps node-gyp parallelism — higher values OOM isolated-vm (laverdet/isolated-vm#428).
66+
#
67+
# node-gyp comes from the lockfile, not `npx`. It is a devDependency of apps/sim
68+
# purely so `turbo prune sim` keeps it: the only other copy is transitive through
69+
# `@electron/rebuild`, which belongs to apps/desktop and is pruned away. `npx`
70+
# resolved it from the registry at build time, which pulled a different major
71+
# (13.x vs the pinned 12.4.0) and bypassed the `minimumReleaseAge` supply-chain
72+
# gate in bunfig.toml on every production image build.
4773
RUN --mount=type=cache,id=bun-cache,target=/root/.bun/install/cache \
4874
--mount=type=cache,id=npm-cache,target=/root/.npm \
4975
HUSKY=0 bun install --ignore-scripts --linker=hoisted && \
50-
cd node_modules/isolated-vm && JOBS=4 npx node-gyp rebuild --release
76+
cd node_modules/isolated-vm && JOBS=4 /app/node_modules/.bin/node-gyp rebuild --release
5177

5278
# ========================================
5379
# Builder Stage: Build the Application
5480
# ========================================
55-
FROM base AS builder
81+
FROM build-base AS builder
5682
ARG TARGETPLATFORM
5783
WORKDIR /app
5884

0 commit comments

Comments
 (0)