Skip to content

Commit b57e1c2

Browse files
backspaceclaude
andcommitted
deploy: cache pnpm fetch layer in service Dockerfiles
Reorder the dep-install steps so the `pnpm fetch` layer only invalidates when the lockfile changes, not on every source edit. Previously the lockfile COPY was followed immediately by `ADD . ./`, which meant any file change blew away the fetch and forced ~2-3 min of re-downloading into the pnpm store. With `cache-from/cache-to: type=gha,mode=max` already wired through docker-ecr, this should cut several minutes off each Docker build on the common no-dep-change path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9ac6763 commit b57e1c2

5 files changed

Lines changed: 38 additions & 25 deletions

File tree

packages/postgres/Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ ARG PNPM_VERSION
66
RUN apt-get update && apt-get install -y postgresql
77
RUN npm install -g pnpm@${PNPM_VERSION}
88
WORKDIR /boxel
9+
10+
# Cache-friendly dependency fetch: this layer only re-runs when the lockfile
11+
# (or patches it references) changes, not on every source edit. `pnpm fetch`
12+
# populates the global pnpm store in $HOME from the lockfile alone, so the
13+
# subsequent `pnpm install --offline` doesn't need the registry.
14+
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
15+
COPY patches/ ./patches
16+
RUN CI=1 pnpm fetch
17+
918
COPY . .
10-
RUN pnpm install --frozen-lockfile
19+
RUN CI=1 pnpm install -r --offline
1120

1221
WORKDIR /boxel/packages/postgres
1322

packages/realm-server/prerender-manager.Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ WORKDIR /realm-server
99
RUN apt-get update && apt-get install -y ca-certificates curl unzip jq
1010
RUN npm install -g pnpm@11.0.9
1111

12-
COPY pnpm-lock.yaml ./
13-
12+
# Cache-friendly dependency fetch: this layer only re-runs when the lockfile
13+
# (or patches it references) changes, not on every source edit. `pnpm fetch`
14+
# populates the global pnpm store in $HOME from the lockfile alone, so the
15+
# subsequent `pnpm install --offline` doesn't need the registry.
16+
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
1417
COPY patches/ ./patches
15-
COPY vendor/ ./vendor
16-
17-
ADD . ./
18-
1918
RUN CI=1 pnpm fetch
19+
20+
COPY . ./
2021
RUN CI=1 pnpm install -r --offline
2122

2223
EXPOSE 4222

packages/realm-server/prerender.Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ ENV PUPPETEER_CHROME_ARGS="--disable-dev-shm-usage"
6060

6161
RUN mkdir -p /home/pptruser/Downloads "${PUPPETEER_CACHE_DIR}"
6262

63-
COPY pnpm-lock.yaml ./
64-
63+
# Cache-friendly dependency fetch: this layer only re-runs when the lockfile
64+
# (or patches it references) changes, not on every source edit. `pnpm fetch`
65+
# populates the global pnpm store in $HOME from the lockfile alone, so the
66+
# subsequent `pnpm install --offline` doesn't need the registry.
67+
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
6568
COPY patches/ ./patches
66-
COPY vendor/ ./vendor
67-
68-
ADD . ./
69-
7069
RUN CI=1 pnpm fetch
70+
71+
COPY . ./
7172
RUN CI=1 pnpm install -r --offline
7273
RUN chown -R pptruser:pptruser /home/pptruser /realm-server
7374

packages/realm-server/realm-server.Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ WORKDIR /realm-server
99
RUN apt-get update && apt-get install -y ca-certificates curl unzip postgresql jq rsync git
1010
RUN npm install -g pnpm@11.0.9
1111

12-
COPY pnpm-lock.yaml ./
13-
12+
# Cache-friendly dependency fetch: this layer only re-runs when the lockfile
13+
# (or patches it references) changes, not on every source edit. `pnpm fetch`
14+
# populates the global pnpm store in $HOME from the lockfile alone, so the
15+
# subsequent `pnpm install --offline` doesn't need the registry.
16+
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
1417
COPY patches/ ./patches
15-
COPY vendor/ ./vendor
16-
17-
ADD . ./
18-
1918
RUN CI=1 pnpm fetch
19+
20+
COPY . ./
2021
RUN CI=1 pnpm install -r --offline
2122

2223
EXPOSE 3000

packages/realm-server/worker.Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ WORKDIR /realm-server
99
RUN apt-get update && apt-get install -y ca-certificates curl unzip postgresql jq
1010
RUN npm install -g pnpm@11.0.9
1111

12-
COPY pnpm-lock.yaml ./
13-
12+
# Cache-friendly dependency fetch: this layer only re-runs when the lockfile
13+
# (or patches it references) changes, not on every source edit. `pnpm fetch`
14+
# populates the global pnpm store in $HOME from the lockfile alone, so the
15+
# subsequent `pnpm install --offline` doesn't need the registry.
16+
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
1417
COPY patches/ ./patches
15-
COPY vendor/ ./vendor
16-
17-
ADD . ./
18-
1918
RUN CI=1 pnpm fetch
19+
20+
COPY . ./
2021
RUN CI=1 pnpm install -r --offline
2122

2223
EXPOSE 3000

0 commit comments

Comments
 (0)