Skip to content

docs(docker): split dependency install for better layer caching#3030

Merged
bartlomieju merged 1 commit into
2.8from
fix/docker-multistage-cache-2935
May 21, 2026
Merged

docs(docker): split dependency install for better layer caching#3030
bartlomieju merged 1 commit into
2.8from
fix/docker-multistage-cache-2935

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

@bartlomieju bartlomieju commented Apr 8, 2026

Rebased onto the 2.8 branch and updated the Dockerfile examples to use deno ci instead of deno install --entrypoint main.ts. deno ci is the new 2.8 install command intended for CI and image builds — it requires a committed lockfile, wipes any stale node_modules, and installs with --frozen semantics, so two builds of the same commit produce the same dependency tree.

For production images, the examples pass --prod --skip-types: --prod skips devDependencies from package.json and --skip-types drops @types/* packages from both deno.json imports and package.json dependencies. Both shrink the resulting image without changing runtime behavior.

The original layer-caching change is preserved: manifests (deno.json, deno.lock, package.json*) are copied before the full source tree so editing source code doesn't invalidate the dependency install layer, in both the basic and multi-stage examples. The DENO_DIR copy in the multi-stage example is untouched — that part of #2935 already landed in #3122.

Ref #2935

Copy link
Copy Markdown
Contributor

@lunadogbot lunadogbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting COPY deno.json deno.lock ./ + RUN deno install before COPY . . is the right caching shape — the dep layer only invalidates when deno.json/deno.lock change. COPY --from=builder /deno-dir /deno-dir in the multi-stage example matches DENO_DIR=/deno-dir/ baked into the denoland/deno image, so the runtime cache is preserved.

  • nit: last_modified: 2025-12-16 in the frontmatter wasn't bumped — repo convention is to bump it for substantive content changes.
  • nit: basic example runs deno install then deno install --entrypoint main.ts — the second resolves everything from main.ts anyway, so the first is purely a caching trick. Worth a one-line comment so readers don't think both are required.
  • nit: COPY deno.json deno.lock ./ fails the build if a project has no deno.lock yet. COPY deno.json deno.lock* ./ keeps it working for first-time users.

@bartlomieju bartlomieju force-pushed the fix/docker-multistage-cache-2935 branch from da42377 to a62ead0 Compare May 21, 2026 10:33
@bartlomieju bartlomieju changed the title fix: Docker multi-stage build missing DENO_DIR copy docs(docker): split dependency install for better layer caching May 21, 2026
Rebases on 2.8 and switches the Dockerfile examples from
`deno install --entrypoint main.ts` to `deno ci --prod --skip-types`.

`deno ci` is the 2.8 install command intended for CI and image builds:
it requires a committed lockfile, wipes any stale node_modules, and
runs install with `--frozen` semantics. `--prod` drops
devDependencies and `--skip-types` drops `@types/*` packages, both
shrinking the resulting image without changing runtime behavior.

Manifests (`deno.json`, `deno.lock`, `package.json*`) are copied
before the full source tree so the install layer caches across
source-only edits, in both the basic and multi-stage examples.

Ref #2935
@bartlomieju bartlomieju force-pushed the fix/docker-multistage-cache-2935 branch from a62ead0 to f9bf111 Compare May 21, 2026 10:46
@bartlomieju bartlomieju changed the base branch from main to 2.8 May 21, 2026 10:46
@bartlomieju bartlomieju merged commit 2673b76 into 2.8 May 21, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants