ecr

package
v0.0.0-...-92b956e Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package ecr provides implementations of the containerd Resolver, Fetcher, and Pusher interfaces that can use the Amazon ECR API to push and pull images.

References

containerd specifies images with a reference, or a "ref". References are different from Docker image names, as references encode an identifier, but not a retrieval mechanism. refs start with a DNS-style namespace that can be used to select separate Resolvers to use.

The canonical ref format used by this package is ecr.aws/ followed by the ARN of the repository and a label and/or a digest. Valid references are of the form "ecr.aws/arn:aws:ecr:<region>:<account>:repository/<name>:<tag>".

License

This package is licensed under the Apache 2.0 license.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidManifest = errors.New("invalid manifest")
)

Functions

func NewResolver

func NewResolver(options ...ResolverOption) (remotes.Resolver, error)

NewResolver creates a new remotes.Resolver capable of interacting with Amazon ECR. NewResolver can be called with no arguments for default configuration, or can be customized by specifying ResolverOptions. By default, NewResolver will allocate a new AWS session.Session and an in-memory tracker for layer progress.

Example (Pull)
package main

import (
	"context"
	"fmt"

	"github.com/awslabs/amazon-ecr-containerd-resolver/ecr"
	"github.com/containerd/containerd"
	"github.com/containerd/containerd/namespaces"
)

func main() {
	client, _ := containerd.New("/run/containerd/containerd.sock")
	resolver, _ := ecr.NewResolver()
	img, _ := client.Pull(
		namespaces.NamespaceFromEnv(context.TODO()),
		"ecr.aws/arn:aws:ecr:us-west-2:123456789012:repository/myrepository:mytag",
		containerd.WithResolver(resolver),
		containerd.WithPullUnpack,
		containerd.WithSchema1Conversion)
	fmt.Println(img.Name())
}
Output:

Example (Push)
package main

import (
	"context"

	"github.com/awslabs/amazon-ecr-containerd-resolver/ecr"
	"github.com/containerd/containerd"
	"github.com/containerd/containerd/namespaces"
)

func main() {
	client, _ := containerd.New("/run/containerd/containerd.sock")
	ctx := namespaces.NamespaceFromEnv(context.TODO())

	img, _ := client.ImageService().Get(
		ctx,
		"docker.io/library/busybox:latest")
	resolver, _ := ecr.NewResolver()
	_ = client.Push(
		ctx,
		"ecr.aws/arn:aws:ecr:us-west-2:123456789012:repository/myrepository:mytag",
		img.Target,
		containerd.WithResolver(resolver))
}
Output:

Types

type ECRSpec

type ECRSpec struct {
	// Repository name for this reference.
	Repository string
	// Object is the image reference's object descriptor. This may be a label or
	// a digest specifier.
	Object string
	// contains filtered or unexported fields
}

ECRSpec represents a parsed reference.

Valid references are of the form "ecr.aws/arn:aws:ecr:<region>:<account>:repository/<name>:<tag>".

func ParseImageURI

func ParseImageURI(input string) (ECRSpec, error)

ParseImageURI takes an ECR image URI and then constructs and returns an ECRSpec struct

func ParseRef

func ParseRef(ref string) (ECRSpec, error)

ParseRef parses an ECR reference into its constituent parts

func (ECRSpec) ARN

func (spec ECRSpec) ARN() string

ARN returns the canonical representation of the ECR ARN

func (ECRSpec) Canonical

func (spec ECRSpec) Canonical() string

Canonical returns the canonical representation for the reference

func (ECRSpec) ImageID

func (spec ECRSpec) ImageID() *ecr.ImageIdentifier

ImageID returns an ecr.ImageIdentifier suitable for using in calls to ECR

func (ECRSpec) Partition

func (spec ECRSpec) Partition() string

Partition returns the AWS partition

func (ECRSpec) Region

func (spec ECRSpec) Region() string

Region returns the AWS region

func (ECRSpec) Registry

func (spec ECRSpec) Registry() string

Registry returns the Amazon ECR registry

func (ECRSpec) Spec

func (spec ECRSpec) Spec() reference.Spec

Spec returns a reference.Spec

func (ECRSpec) TagDigest

func (spec ECRSpec) TagDigest() (string, digest.Digest)

TagDigest returns the tag and/or digest specified by the reference

type ResolverOption

type ResolverOption func(*ResolverOptions) error

ResolverOption represents a functional option for configuring the ECR Resolver

func WithHTTPClient

func WithHTTPClient(client *http.Client) ResolverOption

WithHTTPClient is a ResolverOption to use a specific http.Client.

func WithLayerDownloadParallelism

func WithLayerDownloadParallelism(parallelism int) ResolverOption

WithLayerDownloadParallelism is a ResolverOption to configure whether layer parts should be downloaded in parallel. Layer parallelism is backed by the htcat library and can increase the speed at which layers are downloaded at the cost of increased memory consumption. It is recommended to test your workload to determine whether the tradeoff is worthwhile.

func WithSession

func WithSession(session *session.Session) ResolverOption

WithSession is a ResolverOption to use a specific AWS session.Session

func WithTracker

func WithTracker(tracker docker.StatusTracker) ResolverOption

WithTracker is a ResolverOption to use a specific docker.Tracker

type ResolverOptions

type ResolverOptions struct {
	// Session is used for configuring the ECR client.  If not specified, a
	// generic session is used.
	Session *session.Session
	// Tracker is used to track uploads to ECR.  If not specified, an in-memory
	// tracker is used instead.
	Tracker docker.StatusTracker
	// LayerDownloadParallelism configures whether layer parts should be
	// downloaded in parallel.  If not specified, parallelism is currently
	// disabled.
	LayerDownloadParallelism int
	// HTTPClient configures the HTTP client the resolver internally use for fetching.
	// If not specified, http.DefaultClient is used.
	HTTPClient *http.Client
}

ResolverOptions represents available options for configuring the ECR Resolver

Directories

Path Synopsis
internal
Package stream contains functionality for processing arbitrarily large streaming data.
Package stream contains functionality for processing arbitrarily large streaming data.

Jump to

Keyboard shortcuts

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