Skip to content

feat(builder): Add rootfs implementation for reading OCI images#413

Open
craciunoiuc wants to merge 2 commits into
prod-stagingfrom
craciunoiuc/handle-oci-type
Open

feat(builder): Add rootfs implementation for reading OCI images#413
craciunoiuc wants to merge 2 commits into
prod-stagingfrom
craciunoiuc/handle-oci-type

Conversation

@craciunoiuc

@craciunoiuc craciunoiuc commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Tested work and it seemed fine. Pasting again uses:
Case 1:

rootfs:
  format: erofs
  type: oci
  source: index.unikraft.io/test/check-pr:latest
rootfs:
  format: erofs
  source: oci://index.unikraft.io/test/check-pr:latest

Case 2:

rootfs:
  format: erofs
  type: oci
  source: index.docker.io/hello-world:latest
rootfs:
  format: erofs
  source: oci://index.docker.io/hello-world:latest

You can use these prefixes: oci://, oci-layout://, oci-archive:// taken from image-spec:

case imagespec.URISchemeOCI, imagespec.URISchemeOCILayout, imagespec.URISchemeOCIArchive:

Closes: TOOL-1073

Either through 'type: oci' or the 'oci://' prefix.

Signed-off-by: Cezar Craciunoiu <[email protected]>
@craciunoiuc

Copy link
Copy Markdown
Contributor Author

let me know if these single use functions you want to inline

I found them significant enough to keep separate for now

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds support in the builder to treat OCI image references (registry, OCI layout, OCI archive) as rootfs sources, including logic to unpack regular OCI layers into a rootfs and to use a Unikraft-specific initrd component when present.

Changes:

  • Detect OCI rootfs sources via URI schemes and route BuildRootfs to a new OCI implementation.
  • Implement buildRootfsOCI to load OCI images per requested platform, flatten layers into a directory, and package into CPIO/EROFS.
  • Update kraftfile-to-buildopts translation and expand unit/integration-style tests for OCI sources.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/builder/rootfs.go Adds OCI source detection + buildRootfsOCI (load, platform match, layer flatten, repack).
internal/builder/rootfs_test.go Adds DetectSourceType tests for OCI schemes and integration-style rootfs OCI tests.
internal/builder/rootfs_oci_test.go Adds helpers to generate local OCI archives used by tests.
internal/builder/kraftfile.go Avoids filepath-joining when rootfs/ROM source is an OCI reference or explicitly typed OCI.
internal/builder/kraftfile_test.go Adds coverage for OCI paths/types in kraftfile-to-buildopts conversion.
go.mod Pulls in new (indirect) deps required by containerd/v2 usage.
go.sum Updates sums for newly introduced transitive dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +63 to +77
layerDesc, layerBlob := tarGzipLayer(t, srcDir)

config := ocispec.Image{
Platform: ocispec.Platform{
Architecture: "amd64",
OS: "linux",
},
Config: ocispec.ImageConfig{
Cmd: []string{"/bin/sh"},
},
RootFS: ocispec.RootFS{
Type: "layers",
DiffIDs: []digest.Digest{layerDesc.Digest},
},
}

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.

@jedevc sounds 🧢

should I change?

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