oci

package
v0.0.0-...-1e97fd4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 11 Imported by: 0

README

Webassembly Open Container Interface

Inspired by:

Push/Pull webassembly from registry. OCI manfiest sample json:

{
  "schemaVersion": 2,
  "config": {
    "mediaType": "application/vnd.wasm.config.v1+json",
    "digest": "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
    "size": 2,
    "annotations": {
      "org.wasmerd.wasm.title": "example.wasm",
      "org.opencontainers.image.created": "2021-11-12T19:22:07+08:00"
    }
  },
  "layers": [
    {
      "mediaType": "application/vnd.wasm.content.layer.v1+wasm",
      "digest": "sha256:821d0b0539620fb5c9a3a0d2ef69c5bcb10c7f7c4b27b8b958882969c84a4695",
      "size": 1865223,
      "annotations": { "org.wasmerd.wasm.title": "example.wasm" }
    }
  ],
  "annotations": {
    "org.wasmerd.wasm.title": "example.wasm",
    "org.opencontainers.image.created": "2021-11-12T19:22:07+08:00"
  }
}

Push example

client := oci.NewClient()
err := client.PushFromFile("ghcr.io/jeasonstudio/example-new.wasm:latest", "example.wasm")

Pull example

client := oci.NewClient()
client.PullToFile("ghcr.io/jeasonstudio/example.wasm:latest", "target.wasm")

Documentation

Index

Constants

View Source
const (
	// MediaTypeWasmContentLayer content layer media type
	MediaTypeWasmContentLayer = "application/vnd.wasm.content.layer.v1+wasm"
	// MediaTypeWasmConfig config media type
	MediaTypeWasmConfig = "application/vnd.wasm.config.v1+json"
	// AnnotationWasmTitle filename of webassembly, such as example.wasm
	AnnotationWasmTitle = "org.wasmerd.wasm.title"
)

Thanks to https://github.com/engineerd/wasm-to-oci

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client OCI client

func NewClient

func NewClient() *Client

NewClient create oci client

func (*Client) Pull

func (c *Client) Pull(ctx context.Context, ref string, middlewares ...OptPullPush) (*Image, error)

Pull pulls a Wasm module from an OCI registry given a reference

func (*Client) PullToFile

func (c *Client) PullToFile(ref, filename string, middlewares ...OptPullPush) (*Image, error)

PullToFile Pull and write to file system

func (*Client) Push

func (c *Client) Push(ctx context.Context, ref, filename string, moduleContent []byte, middlewares ...OptPullPush) (*Image, error)

Push pushes a WASM module to an OCI registry

func (*Client) PushFromFile

func (c *Client) PushFromFile(ref, modulePath string, middlewares ...OptPullPush) error

PushFromFile push to registry from file in file system

type Image

type Image struct {
	// Name of the webassembly image.
	//
	// To be pulled, it must be a reference compatible with resolvers.
	Name string

	// Labels provide runtime decoration for the image record.
	//
	// There is no default behavior for how these labels are propagated. They
	// only decorate the static metadata object.
	// This field is optional.
	Labels map[string]string

	// Manifest describes the root content for this image. Typically, this is
	// a manifest, index or manifest list.
	Manifest v1.Descriptor

	// Webassembly describes the webassembly layer content for this image.
	Webassembly v1.Descriptor

	// Content describes webassembly file content.
	Content []byte

	CreatedAt, UpdatedAt time.Time
}

Image is the OCI Image

func (*Image) Size

func (i *Image) Size() int64

Size get webassembly file size

type OptPullPush

type OptPullPush func(o *options) error

OptPullPush options for pull/push

func WithHandleLayerDesc

func WithHandleLayerDesc(save func(layer v1.Descriptor)) OptPullPush

WithHandleLayerDesc sets the allowed media types

func WithHandleManifestDesc

func WithHandleManifestDesc(save func(manifest v1.Descriptor)) OptPullPush

WithHandleManifestDesc sets the allowed media types

func WithNetworkConfig

func WithNetworkConfig(insecure, plainHTTP bool) OptPullPush

WithNetworkConfig sets the allowed media types

func WithRegistryConfig

func WithRegistryConfig(insecure, plainHTTP bool) OptPullPush

WithRegistryConfig sets the allowed media types

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL