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) error
- 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) WithDockerSocket() *DockerEnvironment
- 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) WithPublicPorts() *DockerEnvironment
- func (docker *DockerEnvironment) WithUser(user string)
- 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 // EphemeralContainersEnvironment carries ephemeral lifecycle intent across // the CLI → agent process boundary: the CLI owns orchestration, but service // agents create the containers. The CLI plants this marker before spawning // agents, which inherit it via os.Environ() (see agents/manager loader). // // Its value is the PID of the process that enabled ephemeral mode, not a // bare flag. EphemeralContainers honors an inherited marker only when it // names the reader's live parent — scoping propagation to a genuine spawn // (one hop, CLI → agent) and ignoring a stale value left in an interactive // shell or CI environment. That matters because the marker decides whether // running containers are reaped mid-run: a stale ambient value must never // silently mark real containers for reaping. EphemeralContainersEnvironment = "CODEFLY_EPHEMERAL_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. It is true when this process enabled the mode in-process, or when it inherited the marker from its live parent (the process that spawned it). An inherited marker that does not name the current parent is stale and deliberately ignored.
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) error
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 before spawning agents, which inherit the environment marker.
This is owned by the process that establishes the run (the CLI). Enabling records this process's PID in the environment so freshly spawned children inherit the scoped marker; disabling clears both the in-process flag and the marker for this process and its future children. Agents query state via EphemeralContainers and must not call this.
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) WithDockerSocket ¶ added in v0.2.15
func (docker *DockerEnvironment) WithDockerSocket() *DockerEnvironment
WithDockerSocket explicitly grants the container control of the host Docker daemon. The socket is root-equivalent host access, so ordinary service and database containers never receive it by default.
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) WithPublicPorts ¶ added in v0.2.15
func (docker *DockerEnvironment) WithPublicPorts() *DockerEnvironment
WithPublicPorts explicitly publishes subsequent Docker port mappings on all host interfaces. The secure default is loopback-only because Codefly's service and companion ports are consumed by the local CLI and workspace.
func (*DockerEnvironment) WithUser ¶ added in v0.2.35
func (docker *DockerEnvironment) WithUser(user string)
WithUser runs the container as the given user, in Docker's "UID[:GID]" form. Bind-mounted output is then owned by that user instead of root, so a non-root host process can read (and clean up) what the container wrote. Empty string keeps the image's default user.
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"`
Error string `json:"error"`
ErrorDetail struct {
Message string `json:"message"`
} `json:"errorDetail"`
}