tarball

package
v5.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 21 Imported by: 4

Documentation

Overview

Package tarball provides a way to generate images using one or more layer tarballs and an optional template configuration.

An example:

package main

import (
	"context"

	cp "github.com/containers/image/v5/copy"
	"github.com/containers/image/v5/signature"
	"github.com/containers/image/v5/tarball"
	"github.com/containers/image/v5/transports/alltransports"
	"github.com/containers/image/v5/types"
	imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
)

func imageFromTarball() {
	src, err := alltransports.ParseImageName("tarball:/var/cache/mock/fedora-26-x86_64/root_cache/cache.tar.gz")
	// - or -
	// src, err := tarball.Transport.ParseReference("/var/cache/mock/fedora-26-x86_64/root_cache/cache.tar.gz")
	if err != nil {
		panic(err)
	}
	updater, ok := src.(tarball.ConfigUpdater)
	if !ok {
		panic("unexpected: a tarball reference should implement tarball.ConfigUpdater")
	}
	config := imgspecv1.Image{
		Config: imgspecv1.ImageConfig{
			Cmd: []string{"/bin/bash"},
		},
	}
	annotations := make(map[string]string)
	annotations[imgspecv1.AnnotationDescription] = "test image built from a mock root cache"
	err = updater.ConfigUpdate(config, annotations)
	if err != nil {
		panic(err)
	}
	dest, err := alltransports.ParseImageName("docker-daemon:mock:latest")
	if err != nil {
		panic(err)
	}

	policy, err := signature.DefaultPolicy(nil)
	if err != nil {
		panic(err)
	}

	pc, err := signature.NewPolicyContext(policy)
	if err != nil {
		panic(err)
	}
	defer pc.Destroy()
	_, err = cp.Image(context.TODO(), pc, dest, src, nil)
	if err != nil {
		panic(err)
	}
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// Transport implements the types.ImageTransport interface for "tarball:" images,
	// which are makeshift images constructed using one or more possibly-compressed tar
	// archives.
	Transport = &tarballTransport{}
)

Functions

func NewReference added in v5.3.0

func NewReference(fileNames []string, stdin []byte) (types.ImageReference, error)

NewReference creates a new "tarball:" reference for the listed fileNames. If any of the fileNames is "-", the contents of stdin are used instead.

Types

type ConfigUpdater

type ConfigUpdater interface {
	ConfigUpdate(config imgspecv1.Image, annotations map[string]string) error
}

ConfigUpdater is an interface that ImageReferences for "tarball" images also implement. It can be used to set values for a configuration, and to set image annotations which will be present in the images returned by the reference's NewImage() or NewImageSource() methods.

Jump to

Keyboard shortcuts

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