docker

package
v2.11.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EvalBuildArgsWithEnv evaluates the build args provided in the artifact definition and adds additional runtime defaults and extra arguments, based on OS and custom environment variables
	EvalBuildArgsWithEnv = evalBuildArgs

	// EvalBuildArgs evaluates the build args provided in the artifact definition and adds additional runtime defaults and extra arguments, based on OS environment variables
	EvalBuildArgs = func(mode config.RunMode, workspace string, dockerfilePath string, args map[string]*string, extra map[string]*string) (map[string]*string, error) {
		return evalBuildArgs(mode, workspace, dockerfilePath, args, extra, nil)
	}
)
View Source
var Name = "Docker"

Name is the name of the Docker builder

View Source
var (
	NewAPIClient = NewAPIClientImpl
)

For testing

View Source
var (
	RemoteDigest = getRemoteDigest
)

for testing

View Source
var (
	// RetrieveImage is overridden for unit testing
	RetrieveImage = retrieveImage
)
View Source
var (
	Validate = validate
)

For testing

Functions

func AddRemoteTag

func AddRemoteTag(src, target string, cfg Config, platforms []specs.Platform) error

func CreateDockerTarContext

func CreateDockerTarContext(ctx context.Context, w io.Writer, buildCfg BuildConfig, cfg Config) error

func CreateManifestList

func CreateManifestList(ctx context.Context, images []SinglePlatformImage, targetTag string) (string, error)

CreateManifestList returns a manifest list that contains the given images.

func GetDependencies

func GetDependencies(ctx context.Context, buildCfg BuildConfig, cfg Config) ([]string, error)

GetDependencies finds the sources dependency for the given docker artifact. it caches the results for the computed dependency which can be used by `GetDependenciesCached` All paths are relative to the workspace.

func GetDependenciesByDockerCopyFromTo

func GetDependenciesByDockerCopyFromTo(ctx context.Context, buildCfg BuildConfig, cfg Config) (map[string][]string, error)

GetDependencies finds the sources dependency for the given docker artifact. it caches the results for the computed dependency which can be used by `GetDependenciesCached` All paths are relative to the workspace.

func GetDependenciesCached

func GetDependenciesCached(ctx context.Context, buildCfg BuildConfig, cfg Config) ([]string, error)

GetDependenciesCached reads from cache finds the sources dependency for the given docker artifact. All paths are relative to the workspace.

func GetPlatforms

func GetPlatforms(image string) ([]spec.Platform, error)

GetPlatforms returns the platforms of the provided image.

func IsInsecure

func IsInsecure(ref name.Reference, insecureRegistries map[string]bool) bool

IsInsecure tests if an image is pulled from an insecure registry; default is false

func NewDockerIgnorePredicate

func NewDockerIgnorePredicate(workspace string, excludes []string) (walk.Predicate, error)

NewDockerIgnorePredicate creates a walk.Predicate that checks if directory entries should be ignored.

func NormalizeDockerfilePath

func NormalizeDockerfilePath(context, dockerfile string) (string, error)

NormalizeDockerfilePath returns the absolute path to the dockerfilePath.

func Push

func Push(tarPath, tag string, cfg Config, platforms []specs.Platform) (string, error)

Push pushes the tarball image

func ResolveDependencyImages

func ResolveDependencyImages(deps []*latest.ArtifactDependency, r ArtifactResolver, missingIsFatal bool) map[string]*string

ResolveDependencyImages creates a map of artifact aliases to their built image from a required artifacts slice. If `missingIsFatal` is false then it is permissive of missing entries in the ArtifactResolver and returns nil for those entries.

func RetrieveConfigFile

func RetrieveConfigFile(ctx context.Context, tagged string, cfg Config) (*v1.ConfigFile, error)

func RetrieveLabels

func RetrieveLabels(ctx context.Context, tagged string, cfg Config) (map[string]string, error)

func RetrieveRemoteConfig

func RetrieveRemoteConfig(identifier string, cfg Config, platform v1.Platform) (*v1.ConfigFile, error)

RetrieveRemoteConfig retrieves the remote config file for an image

func RetrieveWorkingDir

func RetrieveWorkingDir(ctx context.Context, tagged string, cfg Config) (string, error)

func SanitizeImageName

func SanitizeImageName(image string) string

SanitizeImageName removes prefixes and lowercases the name portion of images. This is primarily used to handle `ko` import paths in image fields, e.g. `ko://github.com/GoogleContainerTools/skaffold`. Tags can contain uppercase characters, so this function takes care not to change tag cases.

func SubstituteDefaultRepoIntoImage

func SubstituteDefaultRepoIntoImage(defaultRepo string, multiLevelRepo *bool, image string) (string, error)

func SyncMap

func SyncMap(ctx context.Context, workspace string, dockerfilePath string, buildArgs map[string]*string, cfg Config) (map[string][]string, error)

SyncMap creates a map of syncable files by looking at the COPY/ADD commands in the Dockerfile. All keys are relative to the Skaffold root, the destinations are absolute container paths. TODO(corneliusweig) destinations are not resolved across stages in multistage dockerfiles. Is there a use-case for that?

func ToCLIBuildArgs

func ToCLIBuildArgs(a *latest.DockerArtifact, evaluatedArgs map[string]*string) ([]string, error)

func WalkWorkspace

func WalkWorkspace(workspace string, excludes, deps []string) (map[string]bool, error)

WalkWorkspace walks the given host directories and records all files found. Note: if you change this function, you might also want to modify walkWorkspaceWithDestinations.

Types

type ArtifactConfig

type ArtifactConfig struct {
	File string `json:"path"`
}

ArtifactConfig holds information about a Docker build based project

func (ArtifactConfig) ArtifactType

func (c ArtifactConfig) ArtifactType(workspace string) latest.ArtifactType

ArtifactType returns the type of the artifact to be built.

func (ArtifactConfig) ConfiguredImage

func (c ArtifactConfig) ConfiguredImage() string

ConfiguredImage returns the target image configured by the builder, or an empty string if no image is configured

func (ArtifactConfig) Describe

func (c ArtifactConfig) Describe() string

Describe returns the initBuilder's string representation, used when prompting the user to choose a builder.

func (ArtifactConfig) Name

func (c ArtifactConfig) Name() string

Name returns the name of the builder, "Docker"

func (ArtifactConfig) Path

func (c ArtifactConfig) Path() string

Path returns the path to the dockerfile

type ArtifactResolver

type ArtifactResolver interface {
	GetImageTag(imageName string) (string, bool)
}

ArtifactResolver provides an interface to resolve built artifact tags by image name.

type AuthConfigHelper

type AuthConfigHelper interface {
	GetAuthConfig(registry string) (types.AuthConfig, error)
	GetAllAuthConfigs(ctx context.Context) (map[string]types.AuthConfig, error)
}

AuthConfigHelper exists for testing purposes since GetAuthConfig shells out to native store helpers. Ideally this shouldn't be public, but the LocalBuilder needs to use it.

var (
	// DefaultAuthHelper is exposed so that other packages can override it for testing
	DefaultAuthHelper AuthConfigHelper
)

type BuildConfig

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

BuildConfig encapsulates all the build configuration required for performing a dockerbuild.

func NewBuildConfig

func NewBuildConfig(ws string, a string, path string, args map[string]*string) BuildConfig

NewBuildConfig returns a `BuildConfig` for a dockerfilePath build.

type BuildOptions

type BuildOptions struct {
	Tag            string
	Mode           config.RunMode
	ExtraBuildArgs map[string]*string
}

BuildOptions provides parameters related to the LocalDaemon build.

type BuildResult

type BuildResult struct {
	ID string
}

BuildResult gives the information on an image that has been built.

type Config

type Config interface {
	Prune() bool
	ContainerDebugging() bool
	GlobalConfig() string
	GetKubeContext() string
	MinikubeProfile() string
	GetInsecureRegistries() map[string]bool
	Mode() config.RunMode
}

type ContainerCreateOpts

type ContainerCreateOpts struct {
	Name            string
	Network         string
	VolumesFrom     []string
	Wait            bool
	Bindings        nat.PortMap
	Mounts          []mount.Mount
	ContainerConfig *container.Config
	VerifyTestName  string
	Labels          map[string]string
}

type ContainerRun

type ContainerRun struct {
	Image       string
	User        string
	Command     []string
	Mounts      []mount.Mount
	Env         []string
	BeforeStart func(context.Context, string) error
}

type ExitCoder

type ExitCoder interface {
	ExitCode() int
}

type FromTo

type FromTo struct {
	// From is the relative path (wrt. the skaffold root directory) of the dependency on the host system.
	From string
	// To is the destination location in the container. Must use slashes as path separator.
	To string
	// ToIsDir indicates if the `to` path must be treated as directory
	ToIsDir bool
	// StartLine indicates the starting line in the dockerfile of the copy command
	StartLine int
	// EndLine indiciates the ending line in the dockerfile of the copy command
	EndLine int
}

func ExtractOnlyCopyCommands

func ExtractOnlyCopyCommands(absDockerfilePath string) ([]FromTo, error)

func ReadCopyCmdsFromDockerfile

func ReadCopyCmdsFromDockerfile(ctx context.Context, onlyLastImage bool, absDockerfilePath, workspace string, buildArgs map[string]*string, cfg Config) ([]FromTo, error)

ReadCopyCmdsFromDockerfile parses a given dockerfile for COPY commands accounting for build args, env vars, globs, etc and returns an array of FromTos specifying the files that will be copied 'from' local dirs 'to' container dirs in the COPY statements

func (*FromTo) String

func (f *FromTo) String() string

type ImageRef

type ImageRef interface {
	MediaType() (types.MediaType, error)
}

ImageRef represents a v1.Image or v1.ImageIndex.

type ImageReference

type ImageReference struct {
	BaseName       string
	Domain         string
	Path           string
	Repo           string
	Name           string
	Tag            string
	Digest         string
	FullyQualified bool
}

ImageReference is a parsed image name.

func ParseReference

func ParseReference(image string) (*ImageReference, error)

ParseReference parses an image name to a reference.

type Keychain

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

Keychain stores an authenticator per registry.

func (*Keychain) Resolve

func (a *Keychain) Resolve(res authn.Resource) (authn.Authenticator, error)

Resolve retrieves the authenticator for a given resource.

type LocalDaemon

type LocalDaemon interface {
	Close() error
	ExtraEnv() []string
	ServerVersion(ctx context.Context) (types.Version, error)
	ConfigFile(ctx context.Context, image string) (*v1.ConfigFile, error)
	Build(ctx context.Context, out io.Writer, workspace string, artifact string, a *latest.DockerArtifact, opts BuildOptions) (string, error)
	ContainerLogs(ctx context.Context, w *io.PipeWriter, id string) error
	ContainerExists(ctx context.Context, name string) bool
	ContainerInspect(ctx context.Context, id string) (types.ContainerJSON, error)
	ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
	Push(ctx context.Context, out io.Writer, ref string) (string, error)
	Pull(ctx context.Context, out io.Writer, ref string, platform v1.Platform) error
	Load(ctx context.Context, out io.Writer, input io.Reader, ref string) (string, error)
	Run(ctx context.Context, out io.Writer, opts ContainerCreateOpts) (<-chan container.WaitResponse, <-chan error, string, error)
	Delete(ctx context.Context, out io.Writer, id string) error
	Tag(ctx context.Context, image, ref string) error
	TagWithImageID(ctx context.Context, ref string, imageID string) (string, error)
	ImageID(ctx context.Context, ref string) (string, error)
	ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error)
	ImageRemove(ctx context.Context, image string, opts types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
	ImageExists(ctx context.Context, ref string) bool
	ImageList(ctx context.Context, ref string) ([]types.ImageSummary, error)
	NetworkCreate(ctx context.Context, name string, labels map[string]string) error
	NetworkRemove(ctx context.Context, name string) error
	NetworkList(ctx context.Context, opts types.NetworkListOptions) ([]types.NetworkResource, error)
	Prune(ctx context.Context, images []string, pruneChildren bool) ([]string, error)
	DiskUsage(ctx context.Context) (uint64, error)
	RawClient() client.CommonAPIClient
	VolumeCreate(ctx context.Context, opts volume.CreateOptions) (volume.Volume, error)
	VolumeRemove(ctx context.Context, id string) error
	Stop(ctx context.Context, id string, stopTimeout *time.Duration) error
	Remove(ctx context.Context, id string) error
}

LocalDaemon talks to a local Docker API.

func NewAPIClientImpl

func NewAPIClientImpl(ctx context.Context, cfg Config) (LocalDaemon, error)

NewAPIClientImpl guesses the docker client to use based on current Kubernetes context.

func NewLocalDaemon

func NewLocalDaemon(apiClient client.CommonAPIClient, extraEnv []string, forceRemove bool, cfg Config) LocalDaemon

NewLocalDaemon creates a new LocalDaemon.

type PushResult

type PushResult struct {
	Digest string
}

PushResult gives the information on an image that has been pushed.

type SinglePlatformImage

type SinglePlatformImage struct {
	// Platform (OS + architecture) associated with the image built.
	Platform *v1.Platform

	// Name of the image built.
	Image string
}

Describes the result of an image build.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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