Documentation ¶
Index ¶
- Constants
- Variables
- func CreateClientOpts(_ context.Context, env Env) ([]client.Opt, error)
- func HasFinished(cState v1alpha1.DockerContainerState) bool
- func HasStarted(cState v1alpha1.DockerContainerState) bool
- func IsExitError(err error) bool
- func NewCreatedContainerState() types.ContainerState
- func NewExitErrorContainerState() types.ContainerState
- func NewExitSuccessContainerState() types.ContainerState
- func NewFakeDockerResponse(contents string) fakeDockerResponse
- func NewRunningContainerState() types.ContainerState
- func SupportedVersion(v types.Version) bool
- func SupportsBuildkit(v types.Version, env Env) bool
- func WithOrchestrator(ctx context.Context, orc model.Orchestrator) context.Context
- func WrapReadCloserWithTearDown(wrapped io.ReadCloser, tearDown func() error) readCloserWrapper
- type BuildOptions
- type Cli
- func (c *Cli) BuilderVersion() types.BuilderVersion
- func (c *Cli) CheckConnected() error
- func (c *Cli) ContainerRestartNoWait(ctx context.Context, containerID string) error
- func (c *Cli) Env() Env
- func (c *Cli) ExecInContainer(ctx context.Context, cID container.ID, cmd model.Cmd, in io.Reader, ...) error
- func (c *Cli) ForOrchestrator(orc model.Orchestrator) Client
- func (c *Cli) ImageBuild(ctx context.Context, buildContext io.Reader, options BuildOptions) (types.ImageBuildResponse, error)
- func (c *Cli) ImagePull(ctx context.Context, ref reference.Named) (reference.Canonical, error)
- func (c *Cli) ImagePush(ctx context.Context, ref reference.NamedTagged) (io.ReadCloser, error)
- func (c *Cli) Run(ctx context.Context, opts RunConfig) (RunResult, error)
- func (c *Cli) ServerVersion() types.Version
- func (c *Cli) SetOrchestrator(orc model.Orchestrator)
- type Client
- type ClusterClient
- type ClusterEnv
- type CompositeClient
- type Env
- type ExecCall
- type ExitError
- type FakeClient
- func (c *FakeClient) BuildCachePrune(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error)
- func (c *FakeClient) BuilderVersion() types.BuilderVersion
- func (c *FakeClient) CheckConnected() error
- func (c *FakeClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
- func (c *FakeClient) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
- func (c *FakeClient) ContainerRestartNoWait(ctx context.Context, containerID string) error
- func (c *FakeClient) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error)
- func (c *FakeClient) Env() Env
- func (c *FakeClient) ExecInContainer(ctx context.Context, cID container.ID, cmd model.Cmd, in io.Reader, ...) error
- func (c *FakeClient) ForOrchestrator(orc model.Orchestrator) Client
- func (c *FakeClient) ImageBuild(ctx context.Context, buildContext io.Reader, options BuildOptions) (types.ImageBuildResponse, error)
- func (c *FakeClient) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error)
- func (c *FakeClient) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
- func (c *FakeClient) ImagePull(_ context.Context, ref reference.Named) (reference.Canonical, error)
- func (c *FakeClient) ImagePush(ctx context.Context, ref reference.NamedTagged) (io.ReadCloser, error)
- func (c *FakeClient) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
- func (c *FakeClient) ImageTag(ctx context.Context, source, target string) error
- func (c *FakeClient) NewVersionError(apiRequired, feature string) error
- func (c *FakeClient) Run(ctx context.Context, opts RunConfig) (RunResult, error)
- func (c *FakeClient) ServerVersion() types.Version
- func (c *FakeClient) SetContainerListOutput(output map[string][]types.Container)
- func (c *FakeClient) SetDefaultContainerListOutput()
- func (c *FakeClient) SetExecError(err error)
- func (c *FakeClient) SetOrchestrator(orc model.Orchestrator)
- func (c *FakeClient) VersionError(apiRequired, feature string) error
- type ImgNameAndTag
- type LocalClient
- type LocalEnv
- type RunConfig
- type RunResult
Constants ¶
const ( BuiltByLabel = "builtby" BuiltByValue = "tilt" )
Label that we attach to all of the images we build.
const ( TestPod = "test_pod" TestContainer = "test_container" )
const ExampleBuildOutput1 = `` /* 276-byte string literal not displayed */
const ExampleBuildOutput2 = `` /* 276-byte string literal not displayed */
same as ExampleBuildOutput1 but with a different digest
const ExampleBuildOutputV1_23 = `` /* 186-byte string literal not displayed */
const ExampleBuildSHA1 = "sha256:11cd0b38bc3ceb958ffb2f9bd70be3fb317ce7d255c8a4c3f4af30e298aa1aab"
const ExamplePushSHA1 = "sha256:cc5f4c463f81c55183d8d737ba2f0d30b3e6f3670dbe2da68f0aac168e93fbb1"
const TagLatest = "latest"
const ZeroTime = "0001-01-01T00:00:00Z"
Helper functions for dealing with ContainerState.
Variables ¶
var ( BuiltByTiltLabel = map[string]string{BuiltByLabel: BuiltByValue} BuiltByTiltLabelStr = fmt.Sprintf("%s=%s", BuiltByLabel, BuiltByValue) )
var ClusterWireSet = wire.NewSet( ProvideClusterCli, ProvideLocalCli, ProvideLocalEnv, ProvideClusterEnv, ProvideClusterAsDefault)
Bind a docker client that talks to the in-cluster Docker daemon.
var DefaultContainerListOutput = map[string][]types.Container{ TestPod: []types.Container{ types.Container{ID: TestContainer, ImageID: ExampleBuildSHA1, Command: "./stuff"}, }, "two-containers": []types.Container{ types.Container{ID: "not a match", ImageID: ExamplePushSHA1, Command: "/pause"}, types.Container{ID: "the right container", ImageID: ExampleBuildSHA1, Command: "./stuff"}, }, }
var ExamplePushOutput1 = `` /* 1660-byte string literal not displayed */
var LocalWireSet = wire.NewSet( ProvideLocalCli, ProvideLocalEnv, ProvideEmptyClusterEnv, ProvideLocalAsDefault)
Bind a docker client that can only talk to the local Docker daemon.
var SwitchWireSet = wire.NewSet( ProvideClusterCli, ProvideLocalCli, ProvideSwitchCli, ProvideLocalEnv, ProvideClusterEnv, wire.Bind(new(Client), new(CompositeClient)))
Bind a docker client that can either talk to the in-cluster Docker daemon or to the local Docker daemon.
Functions ¶
func CreateClientOpts ¶
Adapted from client.FromEnv
Supported environment variables: DOCKER_HOST to set the url to the docker server. DOCKER_API_VERSION to set the version of the API to reach, leave empty for latest. DOCKER_CERT_PATH to load the TLS certificates from. DOCKER_TLS_VERIFY to enable or disable TLS verification, off by default.
func HasFinished ¶ added in v0.14.0
func HasFinished(cState v1alpha1.DockerContainerState) bool
func HasStarted ¶ added in v0.14.0
func HasStarted(cState v1alpha1.DockerContainerState) bool
func IsExitError ¶
func NewCreatedContainerState ¶ added in v0.14.0
func NewCreatedContainerState() types.ContainerState
func NewExitErrorContainerState ¶ added in v0.14.0
func NewExitErrorContainerState() types.ContainerState
func NewExitSuccessContainerState ¶ added in v0.14.0
func NewExitSuccessContainerState() types.ContainerState
func NewFakeDockerResponse ¶
func NewFakeDockerResponse(contents string) fakeDockerResponse
func NewRunningContainerState ¶ added in v0.14.0
func NewRunningContainerState() types.ContainerState
func SupportedVersion ¶ added in v0.4.1
func SupportsBuildkit ¶ added in v0.4.1
Sadly, certain versions of docker return an error if the client requests buildkit. We have to infer whether it supports buildkit from version numbers.
Inferred from release notes https://docs.docker.com/engine/release-notes/
func WithOrchestrator ¶ added in v0.25.1
WithOrchestrator returns a Context with the current orchestrator set.
func WrapReadCloserWithTearDown ¶ added in v0.14.0
func WrapReadCloserWithTearDown(wrapped io.ReadCloser, tearDown func() error) readCloserWrapper
Types ¶
type BuildOptions ¶ added in v0.7.1
type Cli ¶ added in v0.5.0
func (*Cli) BuilderVersion ¶ added in v0.9.1
func (c *Cli) BuilderVersion() types.BuilderVersion
func (*Cli) CheckConnected ¶ added in v0.10.8
func (*Cli) ContainerRestartNoWait ¶ added in v0.5.0
func (*Cli) ExecInContainer ¶ added in v0.5.0
func (*Cli) ForOrchestrator ¶ added in v0.25.1
func (c *Cli) ForOrchestrator(orc model.Orchestrator) Client
func (*Cli) ImageBuild ¶ added in v0.5.0
func (c *Cli) ImageBuild(ctx context.Context, buildContext io.Reader, options BuildOptions) (types.ImageBuildResponse, error)
func (*Cli) ImagePush ¶ added in v0.10.8
func (c *Cli) ImagePush(ctx context.Context, ref reference.NamedTagged) (io.ReadCloser, error)
func (*Cli) ServerVersion ¶ added in v0.9.1
func (*Cli) SetOrchestrator ¶ added in v0.9.1
func (c *Cli) SetOrchestrator(orc model.Orchestrator)
type Client ¶ added in v0.5.0
type Client interface { CheckConnected() error // If you'd like to call this Docker instance in a separate process, these // are the environment variables you'll need to do so. Env() Env // If you'd like to call this Docker instance in a separate process, this // is the default builder version you want (buildkit or legacy) BuilderVersion() types.BuilderVersion ServerVersion() types.Version // Set the orchestrator we're talking to. This is only relevant to switchClient, // which can talk to either the Local or in-cluster docker daemon. SetOrchestrator(orc model.Orchestrator) // Return a client suitable for use with the given orchestrator. Only // relevant for the switchClient which has clients for both types. ForOrchestrator(orc model.Orchestrator) Client ContainerInspect(ctx context.Context, contianerID string) (types.ContainerJSON, error) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) ContainerRestartNoWait(ctx context.Context, containerID string) error Run(ctx context.Context, opts RunConfig) (RunResult, error) // Execute a command in a container, streaming the command output to `out`. // Returns an ExitError if the command exits with a non-zero exit code. ExecInContainer(ctx context.Context, cID container.ID, cmd model.Cmd, in io.Reader, out io.Writer) error ImagePull(ctx context.Context, ref reference.Named) (reference.Canonical, error) ImagePush(ctx context.Context, image reference.NamedTagged) (io.ReadCloser, error) ImageBuild(ctx context.Context, buildContext io.Reader, options BuildOptions) (types.ImageBuildResponse, error) ImageTag(ctx context.Context, source, target string) error ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) NewVersionError(APIrequired, feature string) error BuildCachePrune(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error) }
Create an interface so this can be mocked out.
func ProvideClusterAsDefault ¶ added in v0.9.1
func ProvideClusterAsDefault(cli ClusterClient) Client
func ProvideLocalAsDefault ¶ added in v0.9.1
func ProvideLocalAsDefault(cli LocalClient) Client
type ClusterClient ¶ added in v0.9.1
type ClusterClient Client
func ProvideClusterCli ¶ added in v0.9.1
func ProvideClusterCli(ctx context.Context, lEnv LocalEnv, cEnv ClusterEnv, lClient LocalClient) (ClusterClient, error)
The LocalClient is the docker server from docker env variables. The ClusterClient is the docker server from kubectl configs.
We may need both or just one or neither, depending on what options the Tiltfile has set to drive the build
type ClusterEnv ¶ added in v0.9.1
type ClusterEnv Env
Tell wire to create two docker envs: one for the local CLI and one for the in-cluster CLI.
func ProvideClusterEnv ¶ added in v0.9.1
func ProvideClusterEnv(ctx context.Context, kubeContext k8s.KubeContext, env clusterid.Product, runtime container.Runtime, minikubeClient k8s.MinikubeClient) ClusterEnv
func ProvideEmptyClusterEnv ¶ added in v0.9.5
func ProvideEmptyClusterEnv() ClusterEnv
type CompositeClient ¶ added in v0.25.1
type CompositeClient interface { Client DefaultLocalClient() Client DefaultClusterClient() Client ClientFor(cluster v1alpha1.Cluster) Client HasMultipleClients() bool }
Add-on interface for a client that manages multiple clients transparently.
func ProvideSwitchCli ¶ added in v0.9.1
func ProvideSwitchCli(clusterCli ClusterClient, localCli LocalClient) CompositeClient
type Env ¶ added in v0.7.11
type Env struct { Host string APIVersion string TLSVerify string CertPath string // Minikube's docker client has a bug where it can't use buildkit. See: // https://github.com/kubernetes/minikube/issues/4143 IsOldMinikube bool // Some Kubernetes contexts have a Docker daemon that they use directly // as their container runtime. Any images built on that daemon will // show up automatically in the runtime. // // We used to store this as a property of the k8s env but now store it as a field of the Docker Env, because this // really affects how we interact with the Docker Env (rather than // how we interact with the K8s Env). // // In theory, you can have more than one, but in practice, // this is very difficult to set up. BuildToKubeContexts []string // If the env failed to load for some reason, propagate that error // so that we can report it when the user tries to do a docker_build. Error error }
See notes on CreateClientOpts. These environment variables are standard docker env configs.
func (Env) AsEnviron ¶ added in v0.7.11
Serializes this back to environment variables for os.Environ
func (Env) WillBuildToKubeContext ¶ added in v0.20.7
func (e Env) WillBuildToKubeContext(kctx k8s.KubeContext) bool
Determines if this docker client can build images directly to the given cluster.
type FakeClient ¶ added in v0.5.0
type FakeClient struct { FakeEnv Env PushCount int PushImage string PushOptions types.ImagePushOptions PushOutput string BuildCount int BuildOptions BuildOptions BuildContext *bytes.Buffer BuildOutput string BuildErrorToThrow error // next call to Build will throw this err (after which we clear the error) ImageListCount int ImageListOpts []types.ImageListOptions TagCount int TagSource string TagTarget string ContainerListOutput map[string][]types.Container CopyCount int CopyContainer string CopyContent io.Reader ExecCalls []ExecCall ExecErrorsToThrow []error // next call to exec will throw ExecError[0] (which we then pop) RestartsByContainer map[string]int RemovedImageIDs []string // Images returned by ImageInspect. Images map[string]types.ImageInspect // Containers returned by ContainerInspect Containers map[string]types.ContainerState // If true, ImageInspectWithRaw will always return an ImageInspect, // even if one hasn't been explicitly pre-loaded. ImageAlwaysExists bool Orchestrator model.Orchestrator CheckConnectedErr error ThrowNewVersionError bool BuildCachePruneErr error BuildCachePruneOpts types.BuildCachePruneOptions BuildCachesPruned []string ContainersPruneErr error ContainersPruneFilters filters.Args ContainersPruned []string }
func NewFakeClient ¶ added in v0.5.0
func NewFakeClient() *FakeClient
func (*FakeClient) BuildCachePrune ¶ added in v0.10.14
func (c *FakeClient) BuildCachePrune(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error)
func (*FakeClient) BuilderVersion ¶ added in v0.9.1
func (c *FakeClient) BuilderVersion() types.BuilderVersion
func (*FakeClient) CheckConnected ¶ added in v0.10.8
func (c *FakeClient) CheckConnected() error
func (*FakeClient) ContainerInspect ¶ added in v0.14.0
func (c *FakeClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
func (*FakeClient) ContainerList ¶ added in v0.5.0
func (c *FakeClient) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
func (*FakeClient) ContainerRestartNoWait ¶ added in v0.5.0
func (c *FakeClient) ContainerRestartNoWait(ctx context.Context, containerID string) error
func (*FakeClient) ContainersPrune ¶ added in v0.10.14
func (c *FakeClient) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error)
func (*FakeClient) Env ¶ added in v0.9.1
func (c *FakeClient) Env() Env
func (*FakeClient) ExecInContainer ¶ added in v0.5.0
func (*FakeClient) ForOrchestrator ¶ added in v0.25.1
func (c *FakeClient) ForOrchestrator(orc model.Orchestrator) Client
func (*FakeClient) ImageBuild ¶ added in v0.5.0
func (c *FakeClient) ImageBuild(ctx context.Context, buildContext io.Reader, options BuildOptions) (types.ImageBuildResponse, error)
func (*FakeClient) ImageInspectWithRaw ¶ added in v0.5.0
func (c *FakeClient) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error)
func (*FakeClient) ImageList ¶ added in v0.5.0
func (c *FakeClient) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
func (*FakeClient) ImagePush ¶ added in v0.5.0
func (c *FakeClient) ImagePush(ctx context.Context, ref reference.NamedTagged) (io.ReadCloser, error)
func (*FakeClient) ImageRemove ¶ added in v0.5.0
func (c *FakeClient) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
func (*FakeClient) ImageTag ¶ added in v0.5.0
func (c *FakeClient) ImageTag(ctx context.Context, source, target string) error
func (*FakeClient) NewVersionError ¶ added in v0.10.14
func (c *FakeClient) NewVersionError(apiRequired, feature string) error
func (*FakeClient) ServerVersion ¶ added in v0.9.1
func (c *FakeClient) ServerVersion() types.Version
func (*FakeClient) SetContainerListOutput ¶ added in v0.5.0
func (c *FakeClient) SetContainerListOutput(output map[string][]types.Container)
func (*FakeClient) SetDefaultContainerListOutput ¶ added in v0.5.0
func (c *FakeClient) SetDefaultContainerListOutput()
func (*FakeClient) SetExecError ¶ added in v0.10.0
func (c *FakeClient) SetExecError(err error)
func (*FakeClient) SetOrchestrator ¶ added in v0.9.1
func (c *FakeClient) SetOrchestrator(orc model.Orchestrator)
func (*FakeClient) VersionError ¶ added in v0.10.14
func (c *FakeClient) VersionError(apiRequired, feature string) error
type ImgNameAndTag ¶
For use storing reference.NamedTagged as a map key, since we can't rely on the two different underlying representations the same name+tag combo being equivalent.
func ToImgNameAndTag ¶
func ToImgNameAndTag(nt reference.NamedTagged) ImgNameAndTag
type LocalClient ¶ added in v0.9.1
type LocalClient Client
func ProvideLocalCli ¶ added in v0.9.1
func ProvideLocalCli(ctx context.Context, lEnv LocalEnv) LocalClient
type LocalEnv ¶ added in v0.9.1
type LocalEnv Env
func ProvideLocalEnv ¶ added in v0.9.1
func ProvideLocalEnv(_ context.Context, kubeContext k8s.KubeContext, env clusterid.Product, cEnv ClusterEnv) LocalEnv
type RunConfig ¶ added in v0.22.11
type RunConfig struct { // Image to execute. // // If Pull is true, this must be a reference.Named. Image reference.Reference // Pull will ensure the image exists locally before running. // // If an image will only be used once, this is a convenience to avoid calling ImagePull first. // If an image will be used multiple times (across containers), prefer explicitly calling ImagePull // to avoid the overhead of calling the registry API to check if the image is up-to-date every time. Pull bool // ContainerName is a unique name for the container. If not specified, Docker will generate a random name. ContainerName string // Stdout from the container will be written here if non-nil. // // Errors copying the container output are logged but not propagated. Stdout io.Writer // Stderr from the container will be written here if non-nil. // // Errors copying the container output are logged but not propagated. Stderr io.Writer // Cmd to run when starting the container. Cmd []string // Mounts to attach to the container. Mounts []mount.Mount }
RunConfig defines the container to create and start.
type RunResult ¶ added in v0.22.11
type RunResult struct { ContainerID string // contains filtered or unexported fields }
RunResult contains information about a container execution.
func (*RunResult) Close ¶ added in v0.22.11
Close removes the container (forcibly if it's still running).