docker

package
v0.1.0-beta.49 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerNetworkIP

func ContainerNetworkIP(containerInfo container.InspectResponse, networkName string) (string, error)

ContainerNetworkInfo extracts the container's IP address

func EnsureImageUpToDate

func EnsureImageUpToDate(ctx context.Context, cli *client.Client, logger *slog.Logger, imageConfig config.Image) error

func EnsureVolumes

func EnsureVolumes(ctx context.Context, cli *client.Client, logger *slog.Logger, appName string, volumes []string) error

EnsureVolumes creates named volumes with labels if they don't exist. It parses volume specifications from the config (e.g., "postgres-data:/var/lib/postgresql") and creates the named volumes with the app label for later cleanup.

func ExecInContainer

func ExecInContainer(ctx context.Context, cli *client.Client, containerID string, cmd []string) (stdout, stderr string, exitCode int, err error)

ExecInContainer executes a command in a running container and returns the output.

func ExecuteImagePrunePlan

func ExecuteImagePrunePlan(ctx context.Context, cli *client.Client, logger *slog.Logger, plan ImagePrunePlan) error

func GetAppContainers

func GetAppContainers(ctx context.Context, cli *client.Client, listAll bool, appName string) ([]container.Summary, error)

GetAppContainers returns a slice of container summaries filtered by labels.

Parameters:

  • ctx: the context for the Docker API requests.
  • cli: the Docker client used to interact with the Docker daemon.
  • listAll: if true, the function returns all containers including stopped ones; if false, only running containers are returned.
  • appName: if not empty, only containers associated with the given app name are returned.

Returns:

  • A slice of container summaries.
  • An error if something went wrong during the container listing.

func GetContainerLogs

func GetContainerLogs(ctx context.Context, cli *client.Client, containerID string, tailLines int) (string, error)

GetContainerLogs retrieves the last N lines of logs from a container. This works even for stopped containers, making it useful for debugging failed deployments.

func LoadImageFromTar

func LoadImageFromTar(ctx context.Context, cli *client.Client, tarPath string) error

func NewClient

func NewClient(ctx context.Context) (*client.Client, error)

func PruneImages

func PruneImages(ctx context.Context, cli *client.Client, logger *slog.Logger) (uint64, error)

PruneImages removes dangling (unused) Docker images and returns the amount of space reclaimed.

func PushImage

func PushImage(ctx context.Context, cli *client.Client, imageRef string, imageConfig *config.Image) error

func RemoveContainers

func RemoveContainers(ctx context.Context, cli *client.Client, logger *slog.Logger, appName, ignoreDeploymentID string) (removedIDs []string, err error)

func RemoveContainersByDeploymentID

func RemoveContainersByDeploymentID(ctx context.Context, cli *client.Client, logger *slog.Logger, appName, deploymentID string) (removedIDs []string, err error)

func RemoveImages

func RemoveImages(ctx context.Context, cli *client.Client, logger *slog.Logger, appName, ignoreDeploymentID string, deploymentsToKeep int) error

func RemoveVolumes

func RemoveVolumes(ctx context.Context, cli *client.Client, logger *slog.Logger, appName string) error

func StopContainers

func StopContainers(ctx context.Context, cli *client.Client, logger *slog.Logger, appName, ignoreDeploymentID string) (stoppedIDs []string, err error)

func StopContainersByDeploymentID

func StopContainersByDeploymentID(ctx context.Context, cli *client.Client, logger *slog.Logger, appName, deploymentID string) (stoppedIDs []string, err error)

func StreamContainerLogs

func StreamContainerLogs(ctx context.Context, cli *client.Client, containerID string, tail int) (<-chan LogLine, error)

Types

type ContainerRunResult

type ContainerRunResult struct {
	ID           string
	DeploymentID string
	ReplicaID    int
}

func RunContainer

func RunContainer(ctx context.Context, cli *client.Client, deploymentID, imageRef string, targetConfig config.TargetConfig) ([]ContainerRunResult, error)

type HealthCheckResult

type HealthCheckResult struct {
	IP  string // Container IP address on the haloy network (only set on success)
	Err error  // nil if healthy
}

HealthCheckResult contains the result of a container health check.

func HealthCheckContainer

func HealthCheckContainer(ctx context.Context, cli *client.Client, logger *slog.Logger, containerID string, containerInfo container.InspectResponse) HealthCheckResult

HealthCheckContainer performs health checks on a container and returns its IP address on success. It accepts a pre-fetched container.InspectResponse but will re-inspect if needed. The function checks: 1. Container is running (and stable, not in restart loop) 2. Docker health status (if configured) 3. HTTP health check endpoint (if no Docker healthcheck) 4. Container has a valid IP on the haloy network

type ImagePrunePlan

type ImagePrunePlan struct {
	AppName              string
	Keep                 int
	RunningDeploymentIDs []string
	Tags                 []ImagePruneTag
}

func PlanImagePrune

func PlanImagePrune(ctx context.Context, cli *client.Client, appName, ignoreDeploymentID string, deploymentsToKeep int) (ImagePrunePlan, error)

type ImagePruneTag

type ImagePruneTag struct {
	Tag          string
	DeploymentID string
	ImageID      string
}

type LogLine

type LogLine struct {
	ContainerID string `json:"containerId"`
	Line        string `json:"line"`
}

type RemoveContainersResult

type RemoveContainersResult struct {
	ID           string
	DeploymentID string
}

Jump to

Keyboard shortcuts

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