1 unstable release

0.4.0 Mar 20, 2024

#616 in WebAssembly

Download history 168/week @ 2024-03-18 22/week @ 2024-04-01

190 downloads per month
Used in containerd-shim-wasm

Apache-2.0

18KB
318 lines

OCI Tar Builder

This is a library that can be used to build OCI tar archives. It is used by the wasi-demo-app crate to build the OCI tar archive that is used to run the demo app. The current implementation is to support encapsulating the wasi-demo-app wasm module as an OCI tar.

Contributing

We welcome contributions to this to make it more robust, useful, and generally better.

Library Usage

The library is currently not published to crates.io, so you will need to add the following to your Cargo.toml:

[dependencies]
oci-tar-builder = { git = "https://github.com/containerd/runwasi.git" }

See wasi-demo-app build script for an example.

Executable usage

There is an experimental executable that uses the library and can package a wasm module as an OCI image with wasm layers. See the OCI WASM in containerd for more information.

To generate the package and import to a registry using a tool such as regctl:

cargo run --bin oci-tar-builder -- --name wasi-demo-oci --repo ghcr.io/containerd/runwasi --tag latest --module ./target/wasm32-wasi/debug/wasi-demo-app.wasm -o ./dist/img-oci.tar
regctl image import localhost:5000/wasi-demo-oci:latest ./dist/img-oci.tar        

View the manifest created, notice that the media types for the layers are application/vnd.bytecodealliance.wasm.component.layer.v0+wasm which are subject to change.

Name:                                localhost:5000/wasi-demo-oci:latest
MediaType:                           application/vnd.oci.image.manifest.v1+json
Digest:                              sha256:6c48b431d29a1ea1ece13fa50e9f33e4d164e07f6a501dbed668aed947002c5c
Annotations:
  io.containerd.image.name:          ghcr.io/containerd/runwasi/wasi-demo-oci:latest
  org.opencontainers.image.ref.name: latest
Total Size:                          2.590MB

Config:
  Digest:                            sha256:beb7483682ae4ec45d02cd7cee8ee733f8dc610cb7e91070dc8f10567365bdd7
  MediaType:                         application/vnd.oci.image.config.v1+json
  Size:                              138B

Layers:

  Digest:                            sha256:656e978ae0c37156a6abe06052a588e5c700346650765859981ebd2089cffd42
  MediaType:                         application/vnd.bytecodealliance.wasm.component.layer.v0+wasm
  Size:                              2.590MB

Spec

See the OCI Image Spec for more information on the OCI tar format.

In order to be compatible with Docker, since Docker does not currently support the OCI format, this also includes a manifest.json file at the root of the tar that describes the image in a way that Docker can import it.

Dependencies

~6–17MB
~215K SLoC