Documentation
¶
Index ¶
- func ContainerNetworkIP(containerInfo container.InspectResponse, networkName string) (string, error)
- func EnsureImageUpToDate(ctx context.Context, cli *client.Client, logger *slog.Logger, ...) error
- func EnsureVolumes(ctx context.Context, cli *client.Client, logger *slog.Logger, appName string, ...) error
- func ExecInContainer(ctx context.Context, cli *client.Client, containerID string, cmd []string) (stdout, stderr string, exitCode int, err error)
- func GetAppContainers(ctx context.Context, cli *client.Client, listAll bool, appName string) ([]container.Summary, error)
- func GetContainerLogs(ctx context.Context, cli *client.Client, containerID string, tailLines int) (string, error)
- func LoadImageFromTar(ctx context.Context, cli *client.Client, tarPath string) error
- func NewClient(ctx context.Context) (*client.Client, error)
- func PruneImages(ctx context.Context, cli *client.Client, logger *slog.Logger) (uint64, error)
- func PushImage(ctx context.Context, cli *client.Client, imageRef string, ...) error
- func RemoveContainers(ctx context.Context, cli *client.Client, logger *slog.Logger, ...) (removedIDs []string, err error)
- func RemoveImages(ctx context.Context, cli *client.Client, logger *slog.Logger, ...) error
- func RemoveVolumes(ctx context.Context, cli *client.Client, logger *slog.Logger, appName string) error
- func StopContainers(ctx context.Context, cli *client.Client, logger *slog.Logger, ...) (stoppedIDs []string, err error)
- func StreamContainerLogs(ctx context.Context, cli *client.Client, containerID string, tail int) (<-chan LogLine, error)
- type ContainerRunResult
- type HealthCheckResult
- type LogLine
- type RemoveContainersResult
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 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 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 PruneImages ¶
PruneImages removes dangling (unused) Docker images and returns the amount of space reclaimed.
func RemoveContainers ¶
func RemoveImages ¶
func RemoveImages(ctx context.Context, cli *client.Client, logger *slog.Logger, appName, ignoreDeploymentID string, deploymentsToKeep int) error
RemoveImages removes extra (duplicate) image tags for a given app, keeping only the newest N tags based on the deploymentID. Running containers reference the image by digest; if an image is in use we allow removal of duplicate tags as long as at least one tag is preserved.
func RemoveVolumes ¶
func StopContainers ¶
Types ¶
type ContainerRunResult ¶
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