Skip to content

Conversation

@realrajaryan
Copy link
Contributor

@realrajaryan realrajaryan commented Oct 29, 2025

When a Dockerfile only includes metadata directives like ENV, ARG, or LABEL and doesn’t perform any filesystem operations (RUN, COPY, ADD), BuildKit ends up returning a nil ref. Our builder currently treats that as an error, which blocks these metadata only Dockerfiles from building.

This PR makes the builder handle that case gracefully by creating a small marker layer (/.container-metadata-only) when ref is nil but the image is otherwise valid. That satisfies OCI manifest requirements and ensures the Swift decoder always gets a valid layers array instead of null, allowing metadata only Dockerfiles to build as expected.


// OCI manifests require a layers array (cannot be null)
stateWithLayer := llb.Scratch().
File(llb.Mkfile("/.container-metadata-only", 0644, []byte("# This image contains only metadata (ENV/ARG/LABEL)\n"))).
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a constant for marker path, that way it is self-documenting

const metadataOnlyMarker = "/.container-metadata-only"

use that const instead of the literal

@realrajaryan realrajaryan merged commit 5280dda into apple:main Oct 30, 2025
2 checks passed
jglogan pushed a commit to apple/container that referenced this pull request Oct 30, 2025
- Fixes #736.
- BuildKit returns nil ref for Dockerfiles containing only metadata
  (`ENV/ARG/LABEL`) directives without filesystem operations
  (`RUN/COPY/ADD`). Previously, this caused builds to fail with "no build
  directives" error.
- Builder-shim 0.6.3 [fixes this](apple/container-builder-shim#47) by
  creating a minimal marker layer when ref is nil but image config is
  valid, satisfying OCI manifest requirements.
- Also, added some tests for this behavior.
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.

[Bug]: "Error: unknown (2): failed to solve: no build directives" on environment-only container-file build (0.5.0)

3 participants