Skip to content

reduce image size, offer slim image#38479

Merged
sallyom merged 1 commit intoopenclaw:mainfrom
sallyom:smaller-image
Mar 7, 2026
Merged

reduce image size, offer slim image#38479
sallyom merged 1 commit intoopenclaw:mainfrom
sallyom:smaller-image

Conversation

@sallyom
Copy link
Copy Markdown
Contributor

@sallyom sallyom commented Mar 7, 2026

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem:
    Docker/multi-stage build: restructure Dockerfile as a multi-stage build to produce a minimal runtime image without build tools, source code, or Bun; add OPENCLAW_VARIANT=slim build arg for a bookworm-slim variant with only necessary packages.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #

User-visible / Behavior Changes

List user-visible changes (including defaults/config).
If none, write None.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (Yes/No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS:
  • Runtime/container: Podman, Cri-O (K8s)

Steps

Regular (bookworm)

  podman build -t openclaw:latest .

Slim (bookworm-slim)

  podman build --build-arg OPENCLAW_VARIANT=slim -t openclaw:slim .

With extra packages

  podman build --build-arg OPENCLAW_DOCKER_APT_PACKAGES="python3 wget" -t openclaw:latest .

Human Verification (required)

Ran as container and within K8s deployment

@openclaw-barnacle openclaw-barnacle bot added docker Docker and sandbox tooling size: S maintainer Maintainer-authored PR labels Mar 7, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e2ce2871d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +99 to +101
COPY --from=build --chown=node:node /app/extensions ./extensions
COPY --from=build --chown=node:node /app/skills ./skills
COPY --from=build --chown=node:node /app/docs ./docs
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Copy bundled browser extension assets into runtime image

The new runtime stage no longer includes assets/chrome-extension, so openclaw browser extension install will fail in built images with Bundled Chrome extension is missing. The CLI resolves its source bundle from assets/chrome-extension (see src/cli/browser-cli-extension.ts), and previously this directory was present because the full repo was copied into the image; after this change only selected paths are copied.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

assets/ was already in .dockerignore, so it was never in the Docker image. The chrome extension install from a container would have failed before our changes too.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR converts the single-stage Dockerfile into a proper multi-stage build (ext-deps → build → runtime) that strips Bun, build tools, and source code from the final image, and adds a bookworm-slim variant selectable via --build-arg OPENCLAW_VARIANT=slim. The CI workflow is updated to build and publish both default and slim images for amd64 and arm64, assembling each into a multi-arch manifest.

The multi-stage refactor is logically sound:

  • The UI build (pnpm ui:build) outputs to dist/control-ui/, which is correctly covered by the COPY --from=build /app/dist ./dist in the runtime stage.
  • All essential build artifacts (dist/, node_modules, skills/, docs/, extensions/, openclaw.mjs) are explicitly copied to the runtime stage.
  • One structural concern identified: ARG OPENCLAW_VARIANT on line 69 is scoped to the base-slim stage rather than the runtime stage, though this is harmless today since the global ARG on line 14 drives the FROM base-${OPENCLAW_VARIANT} substitution. Moving the declaration will improve clarity and prevent silent variable expansion if future code references it in the runtime stage.

Confidence Score: 4/5

  • Safe to merge — multi-stage refactor is logically sound with proper artifact handling and no functional regressions.
  • Changes are additive and well-structured. The one identified issue is a style/clarity concern (ARG scope misplacement) rather than a correctness bug. Build artifacts are all explicitly copied to the runtime stage, and the CI workflow correctly builds and publishes both variants. The missing slim_tags guard in CI is not a current issue due to co-population in the build logic.
  • Dockerfile: minor style improvement suggested for ARG placement

Last reviewed commit: 7e2ce28

Dockerfile Outdated
Comment on lines +69 to +70
ARG OPENCLAW_VARIANT
FROM base-${OPENCLAW_VARIANT}
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.

ARG OPENCLAW_VARIANT belongs in the runtime stage, not base-slim

Per Dockerfile multi-stage semantics, the ARG OPENCLAW_VARIANT on line 69 sits between FROM ... AS base-slim (line 66) and FROM base-${OPENCLAW_VARIANT} (line 70), so it is scoped to the base-slim stage and effectively unused.

The FROM base-${OPENCLAW_VARIANT} substitution works today because the global ARG OPENCLAW_VARIANT=default declared on line 14 (before any FROM) is available to all FROM instructions. However, if a future maintainer needs to reference OPENCLAW_VARIANT inside a RUN command in the runtime stage, the variable would silently expand to an empty string.

Consider moving the re-declaration to after the runtime FROM:

Suggested change
ARG OPENCLAW_VARIANT
FROM base-${OPENCLAW_VARIANT}
FROM base-${OPENCLAW_VARIANT}
ARG OPENCLAW_VARIANT
Prompt To Fix With AI
This is a comment left during a code review.
Path: Dockerfile
Line: 69-70

Comment:
**`ARG OPENCLAW_VARIANT` belongs in the runtime stage, not `base-slim`**

Per Dockerfile multi-stage semantics, the `ARG OPENCLAW_VARIANT` on line 69 sits between `FROM ... AS base-slim` (line 66) and `FROM base-${OPENCLAW_VARIANT}` (line 70), so it is scoped to the `base-slim` stage and effectively unused.

The `FROM base-${OPENCLAW_VARIANT}` substitution works today because the global `ARG OPENCLAW_VARIANT=default` declared on line 14 (before any `FROM`) is available to all `FROM` instructions. However, if a future maintainer needs to reference `OPENCLAW_VARIANT` inside a `RUN` command in the runtime stage, the variable would silently expand to an empty string.

Consider moving the re-declaration to after the runtime `FROM`:

```suggestion
FROM base-${OPENCLAW_VARIANT}
ARG OPENCLAW_VARIANT
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor Author

@sallyom sallyom Mar 7, 2026

Choose a reason for hiding this comment

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

added, updated

@sallyom
Copy link
Copy Markdown
Contributor Author

sallyom commented Mar 7, 2026

image size was 4.6G, now (with diagnostics-otel extension added):

quay.io/sallyom/openclaw:default with diagnostics-otel   2.81 GB
quay.io/sallyom/openclaw:slim with diagnostics-otel  1.97 GB

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b4c864159

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +58 to +63
RUN pnpm canvas:a2ui:bundle || \
(echo "A2UI bundle: creating stub (non-fatal)" && \
mkdir -p src/canvas-host/a2ui && \
echo "/* A2UI bundle unavailable in this build */" > src/canvas-host/a2ui/a2ui.bundle.js && \
echo "stub" > src/canvas-host/a2ui/.bundle.hash && \
rm -rf vendor/a2ui apps/shared/OpenClawKit/Tools/CanvasA2UI)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fail the image build when A2UI bundling fails

This fallback turns any pnpm canvas:a2ui:bundle failure into a successful build by writing a stub bundle and deleting the real A2UI sources, so the subsequent pnpm build can pass while shipping an image with missing/placeholder canvas UI assets. In environments where bundling fails for reasons other than QEMU flakiness (for example toolchain regressions), CI will silently publish degraded images instead of surfacing a hard failure.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is actually a new graceful degradation path — previously, A2UI bundle failures under QEMU cross-compilation would fail the entire build. CI builds natively on both arch amd64, arm64, so this isn't a fallback path for released images.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added a comment to clarify!

@sallyom sallyom force-pushed the smaller-image branch 2 times, most recently from c9ee11d to ee84b85 Compare March 7, 2026 18:21
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: sallyom <[email protected]>
@sallyom
Copy link
Copy Markdown
Contributor Author

sallyom commented Mar 7, 2026

merging! secrets check is broken

@sallyom sallyom merged commit 499c1ee into openclaw:main Mar 7, 2026
23 of 24 checks passed
mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 7, 2026
* main: (133 commits)
  reduce image size, offer slim image (openclaw#38479)
  fix(security): harden install base drift cleanup
  fix(agents): respect explicit provider baseUrl in merge mode (openclaw#39103)
  fix(agents): apply contextTokens cap for compaction threshold (openclaw#39099)
  fix(exec): block dangerous override-only env pivots
  fix(security): stage installs before publish
  fix(daemon): normalise whitespace in checkTokenDrift to prevent false-positive warning (openclaw#39108)
  fix(security): harden fs-safe copy writes
  refactor: dedupe bluebubbles webhook auth test setup
  refactor: dedupe discord native command test scaffolding
  refactor: dedupe anthropic probe target test setup
  refactor: dedupe minimax provider auth test setup
  refactor: dedupe runtime snapshot test fixtures
  fix: harden zip extraction writes
  fix(tests): stabilize diffs localReq headers (supersedes openclaw#39063)
  fix: harden workspace skill path containment
  fix(agents): land openclaw#38935 from @MumuTW
  fix(models): land openclaw#38947 from @davidemanuelDEV
  fix(gateway): land openclaw#39064 from @Narcooo
  fix(models-auth): land openclaw#38951 from @MumuTW
  ...
vincentkoc pushed a commit to BryanTegomoh/openclaw-fork that referenced this pull request Mar 8, 2026
openperf pushed a commit to openperf/moltbot that referenced this pull request Mar 8, 2026
mcaxtr pushed a commit to mcaxtr/openclaw that referenced this pull request Mar 8, 2026
Saitop pushed a commit to NomiciAI/openclaw that referenced this pull request Mar 8, 2026
Signed-off-by: sallyom <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
@vincentkoc vincentkoc mentioned this pull request Mar 8, 2026
20 tasks
GordonSH-oss pushed a commit to GordonSH-oss/openclaw that referenced this pull request Mar 9, 2026
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
senw-developers pushed a commit to senw-developers/va-openclaw that referenced this pull request Mar 17, 2026
V-Gutierrez pushed a commit to V-Gutierrez/openclaw-vendor that referenced this pull request Mar 17, 2026
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 21, 2026
Signed-off-by: sallyom <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
(cherry picked from commit 499c1ee)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 21, 2026
Signed-off-by: sallyom <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
(cherry picked from commit 499c1ee)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docker Docker and sandbox tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant