Skip to content

Render per-arch image layer steps as valid sh - #248

Merged
russwyte merged 5 commits into
mainfrom
fix-layer-arch-case
Oct 23, 2026
Merged

russwyte merged 5 commits into
mainfrom
fix-layer-arch-case

Conversation

@russwyte

Copy link
Copy Markdown
Contributor

Problem

An SbtImageLayer whose steps differ by CPU arch (an ImageStep.File or ImageStep.Tree URL, or an ImageStep.Apt version) renders a case "$(uname -m)" block. That block went through the same ; \ joiner as the layer's statements, so the RUN came out as:

case "$(uname -m)" in;       x86_64) url='…' ;;;       aarch64) url='…' ;;;  …  esac;

in; and ;;; are sh syntax errors (Syntax error: word unexpected (expecting ")") in dash, syntax error near unexpected token ';' in bash). Any derived sbt image with a per-arch layer fails to build. A JDK, or any other native binary, is always per-arch, so the documented ImageStep.Tree example in Caching could not be built either.

The existing specs only checked that the rendered text contained the URLs and uname -m, so nothing parsed the shell.

Fix

archCase renders the case as one statement: its arms join on a bare continuation, and only esac takes the statement separator. File, Tree, and Apt share it. A single-arch layer renders as before.

Proof

  • New SbtImageSpec test: every RUN of a Dockerfile with a per-arch Tree and a per-arch Apt layer is joined the way Docker joins continuations, then checked with sh -n. It failed before the fix with the syntax errors above, and passes after.
  • core/testFull: 1010 passed. docs/testOnly zipx.docs.Caching: 6 passed.

Consumer

Found while adding a Temurin JDK layer to a downstream CI image (CVE-2026-91403: the pinned sbtscala image's JDK trusts a compromised root, and no newer sbtscala tag exists). That repo will pin this PR's snapshot.

Made with Cursor

A layer whose download URL or apt version differs by arch rendered its
uname case through the statement joiner, so the RUN had 'in;' and ';;;'
and every image build with such a layer failed with a sh syntax error.
The case is now one statement whose arms join on a bare continuation.

SbtImageSpec parses every rendered RUN with 'sh -n'.

Co-authored-by: Cursor <cursoragent@cursor.com>
@russwyte russwyte added the snapshots Publish x.y.z-prN-SNAPSHOT from this PR label Oct 23, 2026
@russwyte
russwyte merged commit 0e27df5 into main Oct 23, 2026
13 checks passed
@russwyte
russwyte deleted the fix-layer-arch-case branch October 23, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshots Publish x.y.z-prN-SNAPSHOT from this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant