Skip to content

feat: add NODE_VERSION build arg to sandbox Dockerfile (#610)#659

Open
mvanhorn wants to merge 1 commit intocloudflare:mainfrom
mvanhorn:feat/node-version-arg-issue-610
Open

feat: add NODE_VERSION build arg to sandbox Dockerfile (#610)#659
mvanhorn wants to merge 1 commit intocloudflare:mainfrom
mvanhorn:feat/node-version-arg-issue-610

Conversation

@mvanhorn
Copy link
Copy Markdown

@mvanhorn mvanhorn commented Apr 30, 2026

Closes #610.

What changed

Added a `NODE_VERSION` build arg to `packages/sandbox/Dockerfile`, mirroring the existing `BUN_VERSION` pattern from line 1. Default stays at `20` so existing builds are unchanged; operators who want to test against Node 22 (or pin to a specific patch) can now run:

```bash
docker build --build-arg NODE_VERSION=22 ...
```

Touched four spots in one file:

Line Change
4 (new) `ARG NODE_VERSION=20` declared next to `BUN_VERSION`, same override-via-build-arg comment style
13, 30 `FROM node:20-slim AS pruner` and `AS builder` → `FROM node:${NODE_VERSION}-slim ...`
102 (new) `ARG NODE_VERSION=20` re-declared inside `runtime-base` so the later `COPY --from` calls can resolve it (Docker scopes ARG to one stage at a time)
132–133 The two `COPY --from=node:20-slim ...` lines now use `${NODE_VERSION}`

Why this matters

The issue (vmsp) noted that BUN_VERSION is already a build arg and asked for the same treatment for Node. The Bun pattern was a simple one-line ARG plus interpolation; the Node side is a little more involved because the version is referenced in two FROM stages plus two COPY --from lines inside a third stage. With one global ARG plus one re-declaration, all four call sites now share a single source of truth.

Verification

  • `grep -n "node:20" packages/sandbox/Dockerfile` returns 0 matches after the change.
  • `grep -n "NODE_VERSION" packages/sandbox/Dockerfile` shows the two ARG lines plus the four interpolation sites, exactly as expected.
  • No build run locally — the change is mechanical (string interpolation with the same default) and the CI in this repo will exercise the actual docker build.

Open in Devin Review

Mirrors the existing BUN_VERSION pattern. Operators who want to test
their sandbox image against Node 22 (or pin to a specific patch
version) can now do:

  docker build --build-arg NODE_VERSION=22 ...

Default stays at Node 20 LTS, so the existing build behavior is
unchanged.

Changes:

- Top of file: declared `ARG NODE_VERSION=20` next to BUN_VERSION,
  with the same override-via-build-arg comment.
- The two `FROM node:20-slim` stages (pruner, builder) now use
  `FROM node:${NODE_VERSION}-slim`.
- The runtime-base stage re-declares `ARG NODE_VERSION=20` so the
  later `COPY --from=node:${NODE_VERSION}-slim` calls can resolve
  it (Docker requires re-declaration after each FROM).
- Updated the inline comment from "Install Node.js 20 LTS" to
  reflect the override path.

Closes cloudflare#610
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

⚠️ No Changeset found

Latest commit: 7c5a5fb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@whoiskatrin whoiskatrin added the ok-to-test Maintainer-approved: run full CI on fork PR label Apr 30, 2026
@whoiskatrin
Copy link
Copy Markdown
Collaborator

/bonk fix the build and code if needed

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

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

Review

The Dockerfile change itself is clean and correct — the ARG declaration, re-declaration inside runtime-base, and all four interpolation sites look good. Docker's stage-scoped ARG semantics are handled properly.

However, there are two issues that should be addressed before merging:

1. docker-bake.hcl needs updating

The CI builds use docker-bake.hcl, which passes build args to the Dockerfile via the _common target. Currently it only passes BUN_VERSION:

args = { SANDBOX_VERSION = SANDBOX_VERSION, BUN_VERSION = BUN_VERSION }

Without adding NODE_VERSION here, the bake variable/env var won't reach the Dockerfile — users would need to set it via --build-arg directly, bypassing the bake workflow entirely. For consistency with BUN_VERSION, docker-bake.hcl should declare a NODE_VERSION variable and pass it through args.

2. Missing changeset

Per this repo's contribution guidelines, Dockerfile changes that affect the published @cloudflare/sandbox package need a changeset file in .changeset/. The changeset bot already flagged this. Since this is a Dockerfile-only change with a backward-compatible default, a patch changeset referencing @cloudflare/sandbox is appropriate.

@@ -1,5 +1,7 @@
# Bun version — override via --build-arg BUN_VERSION=$(cat .bun-version)
ARG BUN_VERSION=1
# Node version — override via --build-arg NODE_VERSION=22
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: the comment shows NODE_VERSION=22 as the example override, while BUN_VERSION on line 1 shows the $(cat .bun-version) pattern. This is fine as-is (there's no .node-version file in the repo), just noting the slight inconsistency in comment style.

# Bun version — override via --build-arg BUN_VERSION=$(cat .bun-version)
ARG BUN_VERSION=1
# Node version — override via --build-arg NODE_VERSION=22
ARG NODE_VERSION=20
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The docker-bake.hcl file (used by CI) needs a corresponding NODE_VERSION variable and it needs to be added to the _common target's args map — otherwise this build arg can't be controlled through the bake workflow that CI and the publish pipeline use. Without that, the arg only works with raw docker build --build-arg invocations.

In docker-bake.hcl, something like:

variable "NODE_VERSION" { default = "20" }

and update the _common target:

args = { SANDBOX_VERSION = SANDBOX_VERSION, BUN_VERSION = BUN_VERSION, NODE_VERSION = NODE_VERSION }

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 1, 2026

Review posted. Here's a summary of the findings:

The Dockerfile changes are correct — the NODE_VERSION ARG is properly declared globally, re-declared inside runtime-base (required by Docker's stage-scoped ARG rules), and all four node:20 references are replaced with ${NODE_VERSION}.

Two issues flagged:

  1. docker-bake.hcl not updated — CI uses docker-bake.hcl to build images, and the _common target's args map only passes BUN_VERSION and SANDBOX_VERSION. Without adding NODE_VERSION there, the new build arg can't be controlled through the bake workflow. A NODE_VERSION variable and corresponding args entry are needed.

  2. Missing changeset — The repo requires a .changeset/ file for changes to the @cloudflare/sandbox package (which includes the Dockerfile). A patch changeset is appropriate here.

github run

@whoiskatrin
Copy link
Copy Markdown
Collaborator

/bonk fix all the issues you've found

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

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

Follow-up review

The Dockerfile changes are correct — the ARG declarations, re-declaration inside runtime-base, and all interpolation sites are handled properly.

Two issues from the previous review remain unresolved:

1. docker-bake.hcl must be updated

The CI pipeline builds all Docker images via docker-bake.hcl (see reusable-build.yml:244). The _common target explicitly passes build args to the Dockerfile, and currently only includes SANDBOX_VERSION and BUN_VERSION. Without updating it, NODE_VERSION will silently fall back to the Dockerfile default no matter what env var is set in CI.

Two changes needed in docker-bake.hcl:

Line 11 — add a variable declaration:

variable "NODE_VERSION" { default = "20" }

Line 28 — pass it through to the Dockerfile:

args = { SANDBOX_VERSION = SANDBOX_VERSION, BUN_VERSION = BUN_VERSION, NODE_VERSION = NODE_VERSION }

2. Missing changeset

The Dockerfile is part of the @cloudflare/sandbox package. A changeset file is required per repo conventions. Create e.g. .changeset/node-version-build-arg.md:

---
'@cloudflare/sandbox': patch
---

Add `NODE_VERSION` build arg to the Dockerfile, allowing operators to customize the Node.js version used in sandbox container images.

Per repo guidelines, only reference @cloudflare/sandbox — never the internal packages.

# Bun version — override via --build-arg BUN_VERSION=$(cat .bun-version)
ARG BUN_VERSION=1
# Node version — override via --build-arg NODE_VERSION=22
ARG NODE_VERSION=20
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The ARG itself is fine. Just a reminder: docker-bake.hcl (which drives CI builds) also needs a corresponding NODE_VERSION variable and args entry — otherwise this build arg is only usable via raw docker build --build-arg and won't be controllable through the bake workflow.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 1, 2026

Review posted successfully. Here's a summary:

Request Changes review submitted on PR #659 with two required fixes:

  1. docker-bake.hcl not updated — The CI pipeline uses this file to build all Docker images, and it explicitly passes build args via the _common target. Without adding NODE_VERSION as a variable and including it in the args map, the new build arg is invisible to CI and only works with raw docker build --build-arg invocations. Concrete HCL snippets were provided.

  2. Missing changeset — The Dockerfile is part of @cloudflare/sandbox, so a .changeset/ file with a patch bump is required. Example content was provided.

The Dockerfile changes themselves are correct — no issues there.

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Maintainer-approved: run full CI on fork PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add NODE_VERSION to Dockerfile

2 participants