imagefs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

ImageFS provides access to an OCI container image filesystem using Go's FS interface. It was implemented primarily for testing the Blubber BuildKit frontend.

It currently supports the following layer media types.

  • application/vnd.oci.image.layer.v1.tar
  • application/vnd.oci.image.layer.v1.tar+gzip
  • application/vnd.oci.image.layer.nondistributable.v1.tar
  • application/vnd.oci.image.layer.nondistributable.v1.tar+gzip

Examples

Read files from an OCI archive

import (
  "context"
  
  "github.com/containers/image/v5/oci/archive"
  memoryblobcache "github.com/containers/image/v5/pkg/blobinfocache/memory"
  "github.com/containers/image/v5/types"
  imagefs "gitlab.wikimedia.org/repos/releng/imagefs"
)

ref, _ := archive.ParseReference("/some/oci/archive.tar")

sys := &types.SystemContext{
  OSChoice:           "linux",
  ArchitectureChoice: "amd64",
}

fs := imagefs.New(context.TODO(), ref, sys, memoryblobcache.New())

// Be sure to call Close() to remove temp files
defer fs.Close()

fs.Open("/some/file/from/the/image")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterBlobOpener

func RegisterBlobOpener(mediaType string, opener BlobOpener)

RegisterBlobOpener registers a new BlobOpener that will be used to initialize an FS from blobs of the given media type.

This function is not thread safe and should only be called from init().

Types

type BlobOpener

type BlobOpener func(ctx context.Context, reader io.ReadCloser, size int64) (FS, error)

BlobOpener is a function that, given an open io.ReadCloser and size for an image layer, returns a valid FS.

type FS

type FS interface {
	fs.FS

	// Close will remove any underlying temporary resources that have been created
	// as a result of accessing the image filesystem. If the filesystem was never
	// accessed, this should be a noop.
	Close() error

	// WithContext returns a copy of the filesystem with a newly given context.
	WithContext(context.Context) FS
}

FS provides an fs.FS interface to the underlying image layers as well as a Close() method to remove temporary resources that are created upon first access.

func New

New returns a new FS that will provide JIT access to the given image's layered filesystem.

Jump to

Keyboard shortcuts

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