docker

package
v0.0.0-...-a6ba8f7 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package docker provides Docker and Docker Compose operations.

Index

Constants

View Source
const BusyboxImage = "busybox:1.36.1-glibc"

Variables

This section is empty.

Functions

func ParseComposeLogLine

func ParseComposeLogLine(line string) string

ParseComposeLogLine parses Docker Compose structured log format and extracts the msg value Format: time="..." level="..." msg="..." [other fields] Returns the msg value if found, otherwise returns the original line

Types

type ComposeConfig

type ComposeConfig struct {
	Services map[string]Service `yaml:"services"`
}

ComposeConfig represents the structure of a Docker Compose file

func (*ComposeConfig) HasBuildServices

func (config *ComposeConfig) HasBuildServices() bool

HasBuildServices checks if any services in the config have build context

func (*ComposeConfig) ServicesWithVolumes

func (config *ComposeConfig) ServicesWithVolumes(p *ComposeProject) ([]ComposeService, error)

ServicesWithVolumes returns services that need volume permission fixing

type ComposeProject

type ComposeProject struct {
	// Name is the name of the Docker Compose project.
	Name string
	// WorkingDir is the directory where the Docker Compose files are located.
	WorkingDir string
	// ComposeFiles is a list of Docker Compose files for the project.
	ComposeFiles []string
	// ComposeOverride is optional Docker Compose override content
	ComposeOverride *string
	// Variables contains variables in KEY=value format
	Variables []string
	// Config holds configuration for docker commands and timeouts
	Config *config.Config
}

func NewComposeProject

func NewComposeProject(p *domain.Project, cfg *config.Config) (*ComposeProject, error)

func (*ComposeProject) Build

func (p *ComposeProject) Build() (string, string, error)

func (*ComposeProject) Down

func (p *ComposeProject) Down(removeVolumes bool) (string, string, error)

func (*ComposeProject) DownPiping

func (p *ComposeProject) DownPiping() error

func (*ComposeProject) DownStreaming

func (p *ComposeProject) DownStreaming(outputChan chan<- StreamMessage) error

func (*ComposeProject) GetConfig

func (p *ComposeProject) GetConfig() (string, string, error)

func (*ComposeProject) InitializeVolumeMounts

func (p *ComposeProject) InitializeVolumeMounts() error

InitializeVolumeMounts fixes volume mount point ownership using helper containers

func (*ComposeProject) Logs

func (p *ComposeProject) Logs() (string, string, error)

func (*ComposeProject) LogsPiping

func (p *ComposeProject) LogsPiping() error

func (*ComposeProject) Pull

func (p *ComposeProject) Pull() (string, string, error)

func (*ComposeProject) Status

func (p *ComposeProject) Status() (*ComposeStatus, error)

func (*ComposeProject) Up

func (p *ComposeProject) Up(startServices bool) (string, string, error)

func (*ComposeProject) UpPiping

func (p *ComposeProject) UpPiping(startServices bool) error

func (*ComposeProject) UpStreaming

func (p *ComposeProject) UpStreaming(startServices bool, outputChan chan<- StreamMessage) error

type ComposeProjectStatus

type ComposeProjectStatus int
const (
	ComposeProjectStatusUnknown ComposeProjectStatus = iota
	ComposeProjectStatusRunning
	ComposeProjectStatusStopped
	ComposeProjectStatusFailed
)

func ParseComposeProjectStatus

func ParseComposeProjectStatus(s string) (ComposeProjectStatus, error)

func (ComposeProjectStatus) String

func (s ComposeProjectStatus) String() string

type ComposeService

type ComposeService struct {
	Name    string
	User    *UserInfo
	Volumes []Volume // Volumes that need permission fixing
}

ComposeService represents a service with volume permission requirements

type ComposeStatus

type ComposeStatus struct {
	Status     ComposeProjectStatus
	Containers []ContainerInfo
	Uptime     string
}

type ContainerInfo

type ContainerInfo struct {
	Service    string `json:"Service"`
	Name       string `json:"Name"`
	State      string `json:"State"`
	Status     string `json:"Status"`
	RunningFor string `json:"RunningFor"`
	ExitCode   int    `json:"ExitCode"`
}

type DockerClient

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

DockerClient wraps Docker SDK operations

func NewDockerClient

func NewDockerClient() (*DockerClient, error)

NewDockerClient creates a new Docker client

func (*DockerClient) Close

func (dc *DockerClient) Close() error

Close closes the Docker client

func (*DockerClient) ContainerInspect

func (dc *DockerClient) ContainerInspect(containerID string) (container.InspectResponse, error)

ContainerInspect inspects a container

func (*DockerClient) ContainerList

func (dc *DockerClient) ContainerList(options container.ListOptions) ([]container.Summary, error)

ContainerList lists containers matching the given options

func (*DockerClient) GetImageUser

func (dc *DockerClient) GetImageUser(imageName string) (string, error)

GetImageUser inspects a Docker image to determine its default user

func (*DockerClient) PullImage

func (dc *DockerClient) PullImage(imageName string) error

PullImage pulls a Docker image

func (*DockerClient) RunContainerWithOutput

func (dc *DockerClient) RunContainerWithOutput(containerName, imageName, command string) (string, error)

RunContainerWithOutput runs a container and returns its stdout output

func (*DockerClient) RunVolumeChowningContainer

func (dc *DockerClient) RunVolumeChowningContainer(containerName, command string, mounts []mount.Mount) error

RunVolumeChowningContainer creates and runs a helper container for permission fixing

func (*DockerClient) VolumeRemove

func (dc *DockerClient) VolumeRemove(volumeName string, force bool) error

VolumeRemove removes a volume

type Service

type Service struct {
	Image   string      `yaml:"image,omitempty"`
	User    string      `yaml:"user,omitempty"`
	Volumes []Volume    `yaml:"volumes,omitempty"`
	Build   interface{} `yaml:"build,omitempty"`
}

Service represents a service in the Docker Compose file

func (*Service) GetUser

func (s *Service) GetUser(serviceName string, p *ComposeProject) (*UserInfo, error)

GetUser determines the user (UID:GID) that a service should run as

type StreamMessage

type StreamMessage struct {
	Type    string `json:"type"`    // "stdout", "stderr", "info", "success", "error"
	Content string `json:"content"` // the actual message content
}

StreamMessage represents a message in the streaming output

type UserInfo

type UserInfo struct {
	UID string
	GID string
}

UserInfo represents parsed user information

type Volume

type Volume struct {
	Type   string `yaml:"type"`
	Source string `yaml:"source"`
}

Volume represents a volume mount - we only care about the source path (host path)

Jump to

Keyboard shortcuts

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