Documentation
¶
Index ¶
- Constants
- func ContainerName(name string) string
- func DockerEngineRunning(ctx context.Context) bool
- func EphemeralContainers() bool
- func Forward(ctx context.Context, reader io.Reader, writer io.Writer)
- func GetImageID(im *resources.DockerImage) (string, error)
- func GetImageIfNotPresent(ctx context.Context, c *client.Client, imag *resources.DockerImage, ...) error
- func ImageExists(ctx context.Context, c *client.Client, imag *resources.DockerImage) (bool, error)
- func NewClient() (*client.Client, error)
- func PrintDownloadPercentage(reader io.ReadCloser, out io.Writer)
- func ReapStaleContainers(ctx context.Context) error
- func SetEphemeralContainers(v bool)
- type DockerContainerInstance
- type DockerEnvironment
- func (docker *DockerEnvironment) ContainerDeleted() (bool, error)
- func (docker *DockerEnvironment) ContainerID() (string, error)
- func (docker *DockerEnvironment) GetContainer(ctx context.Context) error
- func (docker *DockerEnvironment) GetImageIfNotPresent(ctx context.Context, imag *resources.DockerImage) error
- func (docker *DockerEnvironment) GetLogs(ctx context.Context) error
- func (docker *DockerEnvironment) ImageExists(ctx context.Context, imag *resources.DockerImage) (bool, error)
- func (docker *DockerEnvironment) Init(ctx context.Context) error
- func (docker *DockerEnvironment) IsContainerPresent(ctx context.Context) (bool, error)
- func (docker *DockerEnvironment) NewProcess(bin string, args ...string) (base.Proc, error)
- func (docker *DockerEnvironment) PortMappings() []*DockerPortMapping
- func (docker *DockerEnvironment) Shutdown(ctx context.Context) error
- func (docker *DockerEnvironment) Stop(ctx context.Context) error
- func (docker *DockerEnvironment) TailLogs(ctx context.Context, lines int) string
- func (docker *DockerEnvironment) WithBinary(bin string) error
- func (docker *DockerEnvironment) WithCommand(cmd ...string)
- func (docker *DockerEnvironment) WithDir(dir string)
- func (docker *DockerEnvironment) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
- func (docker *DockerEnvironment) WithEphemeral() *DockerEnvironment
- func (docker *DockerEnvironment) WithMount(sourceDir string, targetDir string)
- func (docker *DockerEnvironment) WithOutput(w io.Writer)
- func (docker *DockerEnvironment) WithPause()
- func (docker *DockerEnvironment) WithPort(ctx context.Context, port uint16)
- func (docker *DockerEnvironment) WithPortMapping(ctx context.Context, local uint16, container uint16)
- func (docker *DockerEnvironment) WithWorkDir(dir string)
- type DockerPortMapping
- type DockerProc
- func (proc *DockerProc) FindPid(ctx context.Context) (int, error)
- func (proc *DockerProc) IsRunning(ctx context.Context) (bool, error)
- func (proc *DockerProc) Match(cmd []string) bool
- func (proc *DockerProc) Run(ctx context.Context) error
- func (proc *DockerProc) Start(ctx context.Context) error
- func (proc *DockerProc) StdinPipe() (io.WriteCloser, error)
- func (proc *DockerProc) StdoutPipe() (io.ReadCloser, error)
- func (proc *DockerProc) Stop(ctx context.Context) error
- func (proc *DockerProc) Wait(ctx context.Context) error
- func (proc *DockerProc) WaitOn(bin string)
- func (proc *DockerProc) WithDir(dir string)
- func (proc *DockerProc) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
- func (proc *DockerProc) WithEnvironmentVariablesAppend(ctx context.Context, added *resources.EnvironmentVariable, sep string)
- func (proc *DockerProc) WithOutput(output io.Writer)
- type DockerPullResponse
- type ProgressDetail
Constants ¶
const ( LabelCodeflyOwner = "codefly.owner" // always "true" LabelCodeflySession = "codefly.session" // PID of the spawning CLI LabelCodeflyName = "codefly.name" // container's logical name LabelCodeflyEphemeral = "codefly.ephemeral" // "true" for SDK/test (--cli-server) containers )
Container labels used by the startup sweep to identify codefly-owned containers and their spawning CLI. These are set on every container created via DockerEnvironment and consumed by ReapStaleContainers.
Variables ¶
This section is empty.
Functions ¶
func ContainerName ¶
func DockerEngineRunning ¶
func EphemeralContainers ¶
func EphemeralContainers() bool
EphemeralContainers reports whether this process spawns ephemeral containers.
func GetImageID ¶
func GetImageID(im *resources.DockerImage) (string, error)
func GetImageIfNotPresent ¶
func ImageExists ¶
func NewClient ¶ added in v0.2.13
NewClient builds a Docker client that honors the active docker context, mirroring the docker CLI's endpoint resolution (see resolveDockerHost). It exists so packages outside dockerrun — notably the image builder — reach the same engine as the runners instead of client.FromEnv's context-unaware default.
func PrintDownloadPercentage ¶
func PrintDownloadPercentage(reader io.ReadCloser, out io.Writer)
func ReapStaleContainers ¶
func SetEphemeralContainers ¶
func SetEphemeralContainers(v bool)
SetEphemeralContainers marks dependency containers spawned by this process as ephemeral so the startup sweep reaps them even while running. The CLI calls this when it parses --cli-server.
Types ¶
type DockerContainerInstance ¶
type DockerContainerInstance struct {
ID string
}
type DockerEnvironment ¶
type DockerEnvironment struct {
// contains filtered or unexported fields
}
func NewDockerEnvironment ¶
func NewDockerEnvironment(ctx context.Context, image *resources.DockerImage, dir, name string) (*DockerEnvironment, error)
NewDockerEnvironment creates a new docker environment.
If GetImageIfNotPresent fails, the docker client is closed before returning the error so the caller doesn't have to know about the half-constructed env (and isn't expected to call Shutdown on a nil return). Same defensive close in NewDockerHeadlessEnvironment.
func NewDockerHeadlessEnvironment ¶
func NewDockerHeadlessEnvironment(ctx context.Context, image *resources.DockerImage, name string) (*DockerEnvironment, error)
NewDockerHeadlessEnvironment creates a new docker runner
func (*DockerEnvironment) ContainerDeleted ¶
func (docker *DockerEnvironment) ContainerDeleted() (bool, error)
ContainerDeleted checks if the container with ID is gone
func (*DockerEnvironment) ContainerID ¶
func (docker *DockerEnvironment) ContainerID() (string, error)
func (*DockerEnvironment) GetContainer ¶
func (docker *DockerEnvironment) GetContainer(ctx context.Context) error
func (*DockerEnvironment) GetImageIfNotPresent ¶
func (docker *DockerEnvironment) GetImageIfNotPresent(ctx context.Context, imag *resources.DockerImage) error
func (*DockerEnvironment) GetLogs ¶
func (docker *DockerEnvironment) GetLogs(ctx context.Context) error
func (*DockerEnvironment) ImageExists ¶
func (docker *DockerEnvironment) ImageExists(ctx context.Context, imag *resources.DockerImage) (bool, error)
func (*DockerEnvironment) IsContainerPresent ¶
func (docker *DockerEnvironment) IsContainerPresent(ctx context.Context) (bool, error)
func (*DockerEnvironment) NewProcess ¶
func (*DockerEnvironment) PortMappings ¶
func (docker *DockerEnvironment) PortMappings() []*DockerPortMapping
func (*DockerEnvironment) Shutdown ¶
func (docker *DockerEnvironment) Shutdown(ctx context.Context) error
func (*DockerEnvironment) TailLogs ¶
func (docker *DockerEnvironment) TailLogs(ctx context.Context, lines int) string
TailLogs returns the last `lines` lines of combined stdout+stderr for the container. Used by agent runtimes to enrich startup-failure errors with the actual container output (otherwise the user only sees a generic "not ready" timeout). Returns "" on any error so callers can safely append without conditional logic.
func (*DockerEnvironment) WithBinary ¶
func (docker *DockerEnvironment) WithBinary(bin string) error
func (*DockerEnvironment) WithCommand ¶
func (docker *DockerEnvironment) WithCommand(cmd ...string)
func (*DockerEnvironment) WithDir ¶
func (docker *DockerEnvironment) WithDir(dir string)
func (*DockerEnvironment) WithEnvironmentVariables ¶
func (docker *DockerEnvironment) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
func (*DockerEnvironment) WithEphemeral ¶ added in v0.2.11
func (docker *DockerEnvironment) WithEphemeral() *DockerEnvironment
WithEphemeral marks this environment's container as ephemeral, so the startup sweep reaps it even when still running with a dead owner (no keep-alive reuse). For infra with no persistent state to preserve across runs.
func (*DockerEnvironment) WithMount ¶
func (docker *DockerEnvironment) WithMount(sourceDir string, targetDir string)
func (*DockerEnvironment) WithOutput ¶
func (docker *DockerEnvironment) WithOutput(w io.Writer)
func (*DockerEnvironment) WithPause ¶
func (docker *DockerEnvironment) WithPause()
func (*DockerEnvironment) WithPort ¶
func (docker *DockerEnvironment) WithPort(ctx context.Context, port uint16)
func (*DockerEnvironment) WithPortMapping ¶
func (docker *DockerEnvironment) WithPortMapping(ctx context.Context, local uint16, container uint16)
func (*DockerEnvironment) WithWorkDir ¶
func (docker *DockerEnvironment) WithWorkDir(dir string)
type DockerPortMapping ¶
type DockerProc ¶
type DockerProc struct {
ID string
// contains filtered or unexported fields
}
func (*DockerProc) FindPid ¶
func (proc *DockerProc) FindPid(ctx context.Context) (int, error)
FindPid locates the PID of the matching child process inside the container by scanning /proc. /proc is guaranteed on every Linux container; `ps` is not (debian-slim images ship without procps, Alpine busybox has a different flag set). Output format is one line per PID:
<pid>\t<cmdline-space-separated>
where cmdline is the full argv reconstructed from /proc/<pid>/cmdline (NUL-separated in the kernel — we convert NUL→space for splitting).
func (*DockerProc) Match ¶
func (proc *DockerProc) Match(cmd []string) bool
func (*DockerProc) StdinPipe ¶
func (proc *DockerProc) StdinPipe() (io.WriteCloser, error)
func (*DockerProc) StdoutPipe ¶
func (proc *DockerProc) StdoutPipe() (io.ReadCloser, error)
func (*DockerProc) Wait ¶
func (proc *DockerProc) Wait(ctx context.Context) error
Wait blocks until the container exec exits or ctx is cancelled. Returns the exec's exit error: nil for a clean (exit code 0) exit, non-nil carrying the code otherwise — matching Run and the Proc.Wait contract. The exit status comes from ContainerExecInspect (the authoritative source Run polls too), which stays queryable after the exec finishes, so repeated or late Wait calls all observe the same result. Polling IsRunning (the previous approach) scanned /proc and could only ever return nil or ctx.Err(), so a supervisor never saw a non-zero exit.
func (*DockerProc) WaitOn ¶
func (proc *DockerProc) WaitOn(bin string)
func (*DockerProc) WithDir ¶
func (proc *DockerProc) WithDir(dir string)
func (*DockerProc) WithEnvironmentVariables ¶
func (proc *DockerProc) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
func (*DockerProc) WithEnvironmentVariablesAppend ¶
func (proc *DockerProc) WithEnvironmentVariablesAppend(ctx context.Context, added *resources.EnvironmentVariable, sep string)
func (*DockerProc) WithOutput ¶
func (proc *DockerProc) WithOutput(output io.Writer)
type DockerPullResponse ¶
type DockerPullResponse struct {
ID string `json:"id"`
Status string `json:"status"`
ProgressDetail ProgressDetail `json:"progressDetail"`
}