docker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RuntimeMessages = map[RuntimeStatus]string{
	RuntimeHealthy: "Docker is running",

	RuntimeNotInstalled: `Docker is not installed.

InfraKit requires Docker Desktop (or a compatible container engine) to run services.

To install:
  macOS/Windows: https://docker.com/products/docker-desktop
  Linux: https://docs.docker.com/engine/install/

After installing, run: infrakit doctor`,

	RuntimeNotRunning: `Docker is installed but not running.

Start Docker Desktop and wait until it shows "Running", then retry.

On macOS, you can start it with:
  open -a Docker

Run 'infrakit doctor' to verify once started.`,

	RuntimeMisconfigured: `Docker is installed but not accessible.

This is usually a permissions issue. Common fixes:
  - On Linux: Add your user to the 'docker' group
  - Check DOCKER_HOST environment variable
  - Verify Docker socket permissions

Run 'infrakit doctor' for detailed diagnostics.`,
}

RuntimeMessages contains user-friendly messages for each runtime status. Messages are designed to be actionable and non-technical.

Functions

func GetServiceByName

func GetServiceByName(name string) (*config.Service, error)

GetServiceByName returns a service by name with platform overrides applied. This ensures containers are started with the correct platform-specific settings. Supports common aliases and variations (e.g., "postgres" → "PostgreSQL").

func RequireDocker

func RequireDocker() error

RequireDocker checks if Docker is available and returns an error if not. Use this at the start of CLI commands that need Docker. Returns nil if Docker is healthy, otherwise returns an error with user-friendly message.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the Docker client

func NewClient

func NewClient() (*Client, error)

NewClient creates a new Docker client

func (*Client) CheckAllUpdates

func (c *Client) CheckAllUpdates(ctx context.Context) ([]UpdateInfo, error)

CheckAllUpdates checks all enabled services for updates

func (*Client) CheckForUpdates

func (c *Client) CheckForUpdates(ctx context.Context, svc config.Service) (*UpdateInfo, error)

CheckForUpdates checks if a service has an update available

func (*Client) Close

func (c *Client) Close() error

Close closes the Docker client

func (*Client) ExecInContainer

func (c *Client) ExecInContainer(ctx context.Context, containerName string, cmd []string) error

ExecInContainer executes a command in a running container

func (*Client) GetAllStatuses

func (c *Client) GetAllStatuses(ctx context.Context) ([]ServiceStatus, error)

GetAllStatuses returns the status of all enabled services

func (*Client) GetContainerLogs

func (c *Client) GetContainerLogs(ctx context.Context, containerName string, opts LogOptions) (string, error)

GetContainerLogs retrieves logs from a container

func (*Client) GetContainerLogsStream

func (c *Client) GetContainerLogsStream(ctx context.Context, containerName string, opts LogOptions) (io.ReadCloser, error)

GetContainerLogsStream returns a reader for streaming logs

func (*Client) GetContainerStats

func (c *Client) GetContainerStats(ctx context.Context, containerName string) (*ContainerStats, error)

GetContainerStats retrieves resource usage statistics for a container

func (*Client) GetServiceStatus

func (c *Client) GetServiceStatus(ctx context.Context, svc config.Service) (*ServiceStatus, error)

GetServiceStatus returns the status of a service

func (*Client) GetVolumesInfo

func (c *Client) GetVolumesInfo(ctx context.Context) ([]VolumeInfo, uint64)

GetVolumesInfo returns detailed info about Docker volumes used by InfraKit services

func (*Client) GetVolumesSize

func (c *Client) GetVolumesSize(ctx context.Context) uint64

GetVolumesSize returns the total size of Docker volumes used by InfraKit services

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) DockerInfo

Ping checks if Docker daemon is running and returns info

func (*Client) StartService

func (c *Client) StartService(ctx context.Context, svc config.Service) error

StartService starts a service

func (*Client) StartSharedServices

func (c *Client) StartSharedServices(ctx context.Context) error

StartSharedServices starts all shared services

func (*Client) StopService

func (c *Client) StopService(ctx context.Context, svc config.Service) error

StopService stops a service

func (*Client) StopSharedServices

func (c *Client) StopSharedServices(ctx context.Context) error

StopSharedServices stops all shared services

type ContainerStats

type ContainerStats struct {
	ContainerName string  `json:"containerName"`
	Status        string  `json:"status"` // "running", "stopped", "not_created"
	CPUPercent    float64 `json:"cpuPercent"`
	MemoryUsage   uint64  `json:"memoryUsage"` // bytes
	MemoryLimit   uint64  `json:"memoryLimit"` // bytes
	MemoryPercent float64 `json:"memoryPercent"`
	DiskRead      uint64  `json:"diskRead"`  // bytes
	DiskWrite     uint64  `json:"diskWrite"` // bytes
	NetworkRx     uint64  `json:"networkRx"` // bytes
	NetworkTx     uint64  `json:"networkTx"` // bytes
	PIDs          uint64  `json:"pids"`      // number of processes
	Uptime        string  `json:"uptime"`    // human readable uptime
	StartedAt     string  `json:"startedAt"` // ISO timestamp
}

ContainerStats contains resource usage statistics for a container

type DockerInfo

type DockerInfo struct {
	Running       bool   `json:"running"`
	Version       string `json:"version,omitempty"`
	APIVersion    string `json:"apiVersion,omitempty"`
	OS            string `json:"os,omitempty"`
	Arch          string `json:"arch,omitempty"`
	Containers    int    `json:"containers,omitempty"`
	ContainersRun int    `json:"containersRunning,omitempty"`
	Error         string `json:"error,omitempty"`
}

DockerInfo contains Docker daemon information

func GetDockerStatus

func GetDockerStatus() DockerInfo

GetDockerStatus is a standalone function to check Docker status

type LogOptions

type LogOptions struct {
	Tail       string // Number of lines from the end (e.g., "100", "all")
	Since      string // Show logs since timestamp (e.g., "2021-01-01T00:00:00Z") or relative (e.g., "1h")
	Timestamps bool   // Show timestamps
}

LogOptions configures log retrieval

type RuntimeError

type RuntimeError struct {
	Health RuntimeHealth
}

RuntimeError wraps RuntimeHealth as an error for CLI use.

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

type RuntimeHealth

type RuntimeHealth struct {
	// Status is the high-level availability state.
	Status RuntimeStatus `json:"status"`

	// Message is a user-friendly explanation of the status.
	// For non-healthy states, includes actionable fix suggestions.
	Message string `json:"message,omitempty"`

	// Details contains technical information (e.g., underlying error).
	// Useful for debugging but not shown to end users by default.
	Details string `json:"details,omitempty"`

	// Info contains Docker daemon information when Status is RuntimeHealthy.
	// Nil for non-healthy states.
	Info *DockerInfo `json:"info,omitempty"`
}

RuntimeHealth contains the runtime availability status along with user-friendly messaging and technical details for debugging.

func CheckRuntime

func CheckRuntime() RuntimeHealth

CheckRuntime detects the Docker runtime availability and returns appropriate status with user-friendly messaging.

func (RuntimeHealth) IsHealthy

func (r RuntimeHealth) IsHealthy() bool

IsHealthy returns true if the runtime is available and ready.

type RuntimeStatus

type RuntimeStatus string

RuntimeStatus represents the availability state of the container runtime. Used to provide actionable feedback when Docker is unavailable.

const (
	// RuntimeHealthy indicates the Docker daemon is running and accessible.
	RuntimeHealthy RuntimeStatus = "healthy"

	// RuntimeNotInstalled indicates the Docker CLI was not found.
	// User needs to install Docker Desktop or a compatible engine.
	RuntimeNotInstalled RuntimeStatus = "not_installed"

	// RuntimeNotRunning indicates Docker is installed but the daemon is not running.
	// User needs to start Docker Desktop.
	RuntimeNotRunning RuntimeStatus = "not_running"

	// RuntimeMisconfigured indicates the daemon exists but is not accessible.
	// Usually a permissions issue (e.g., user not in docker group on Linux).
	RuntimeMisconfigured RuntimeStatus = "misconfigured"
)

type ServiceStatus

type ServiceStatus struct {
	Name              string                  `json:"name"`
	Icon              string                  `json:"icon,omitempty"`
	ContainerName     string                  `json:"containerName"`
	Status            string                  `json:"status"`            // "running", "stopped", "not_created" (raw Docker status)
	DisplayStatus     string                  `json:"displayStatus"`     // "running", "stopped", "not_installed", "not_added" (computed)
	DisplayStatusText string                  `json:"displayStatusText"` // Human-readable: "Running", "Stopped", "Not Installed", "Not Added"
	Ports             string                  `json:"ports"`
	PortsMap          map[string]string       `json:"portsMap,omitempty"` // hostPort -> containerPort mapping
	Description       string                  `json:"description"`
	AdminURL          string                  `json:"adminUrl,omitempty"`
	Embeddable        bool                    `json:"embeddable"`
	Category          string                  `json:"category"`
	DependsOn         string                  `json:"dependsOn,omitempty"`
	ConnectionInfo    *config.ConnectionInfo  `json:"connectionInfo,omitempty"`
	AppConfig         *config.AppConfigSchema `json:"appConfig,omitempty"` // App provisioning schema
	Enabled           bool                    `json:"enabled"`             // Whether service is enabled in my-services.yaml
}

ServiceStatus represents the status of a service

type UpdateInfo

type UpdateInfo struct {
	Name            string `json:"name"`
	Image           string `json:"image"`
	CurrentDigest   string `json:"currentDigest"`
	LatestDigest    string `json:"latestDigest"`
	CurrentCreated  string `json:"currentCreated"`
	LatestUpdated   string `json:"latestUpdated"`
	UpdateAvailable bool   `json:"updateAvailable"`
	Error           string `json:"error,omitempty"`
}

UpdateInfo represents version update information for a service

type VolumeInfo

type VolumeInfo struct {
	Name       string `json:"name"`
	MountPoint string `json:"mountPoint"`
	Size       uint64 `json:"size"`
	SizeHuman  string `json:"sizeHuman"`
	Service    string `json:"service,omitempty"`
}

VolumeInfo contains information about a Docker volume

Jump to

Keyboard shortcuts

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