Documentation
¶
Index ¶
- Constants
- func ApplyResourceLimits(hostConfig *container.HostConfig, config ResourceConfig) error
- func BuildImageName(repository, tag string) string
- func ContainerHasLabel(labels map[string]string, key, value string) bool
- func CreateEnvVars(envMap map[string]string) []string
- func CreatePortBindings(bindings []PortBinding) nat.PortMap
- func CreateRestartPolicy(policy string) container.RestartPolicy
- func CreateVolumeMounts(volumes map[string]string) []string
- func DisableTraefikLabels() map[string]string
- func ExtractInstanceName(labels map[string]string) string
- func FormatCPUQuota(quota, period int64) string
- func FormatContainerID(id string) string
- func FormatMemoryBytes(bytes int64) string
- func GenerateContainerName(instanceName string) string
- func GenerateDokuManagedLabels(instanceName, serviceType, version string) map[string]string
- func GenerateTCPRouterLabels(config TCPRouterLabels) map[string]string
- func GenerateTraefikLabels(config TraefikLabels) map[string]string
- func GenerateTraefikLabelsForDashboard(domain string, useTLS bool) map[string]string
- func GenerateTraefikLabelsForService(instanceName, domain string, port int, useTLS bool) map[string]string
- func GenerateVolumeName(instanceName, volumeType string) string
- func GetContainerState(state string) string
- func GetImageRepository(image string) string
- func GetImageTag(image string) string
- func IsDokuContainer(labels map[string]string) bool
- func IsHealthy(status string) bool
- func MergeLabels(labelMaps ...map[string]string) map[string]string
- func NormalizeImageName(image string) string
- func ParseCPUString(cpu string) (quota int64, period int64, err error)
- func ParseContainerName(containerName string) string
- func ParseEnvVars(envVars []string) map[string]string
- func ParseMemoryString(mem string) (int64, error)
- func SanitizeContainerName(name string) string
- type Client
- func (c *Client) Close() error
- func (c *Client) ContainerCreate(config *container.Config, hostConfig *container.HostConfig, ...) (string, error)
- func (c *Client) ContainerExists(containerName string) (bool, error)
- func (c *Client) ContainerInspect(containerID string) (types.ContainerJSON, error)
- func (c *Client) ContainerList(all bool) ([]types.Container, error)
- func (c *Client) ContainerLogs(containerID string, follow bool) (io.ReadCloser, error)
- func (c *Client) ContainerRemove(containerID string, force bool) error
- func (c *Client) ContainerRestart(containerID string, timeout *int) error
- func (c *Client) ContainerStart(containerID string) error
- func (c *Client) ContainerStats(containerID string) (types.ContainerStats, error)
- func (c *Client) ContainerStop(containerID string, timeout *int) error
- func (c *Client) ImageExists(imageName string) (bool, error)
- func (c *Client) ImageList() ([]image.Summary, error)
- func (c *Client) ImagePull(imageName string) error
- func (c *Client) ImageRemove(imageID string, force bool) error
- func (c *Client) IsDockerAvailable() bool
- func (c *Client) ListContainersByLabel(ctx context.Context, labelKey, labelValue string) ([]types.Container, error)
- func (c *Client) ListVolumesByLabel(ctx context.Context, labelKey, labelValue string) ([]*volume.Volume, error)
- func (c *Client) NetworkConnect(networkID, containerID string) error
- func (c *Client) NetworkCreate(networkName string, options types.NetworkCreate) (string, error)
- func (c *Client) NetworkDisconnect(networkID, containerID string, force bool) error
- func (c *Client) NetworkExists(networkName string) (bool, error)
- func (c *Client) NetworkInspect(networkID string) (types.NetworkResource, error)
- func (c *Client) NetworkList() ([]types.NetworkResource, error)
- func (c *Client) NetworkRemove(networkID string) error
- func (c *Client) Ping() error
- func (c *Client) RemoveContainer(ctx context.Context, containerID string) error
- func (c *Client) RemoveNetwork(ctx context.Context, networkID string) error
- func (c *Client) RemoveVolume(ctx context.Context, volumeName string) error
- func (c *Client) StopContainer(ctx context.Context, containerID string) error
- func (c *Client) Version() (types.Version, error)
- func (c *Client) VolumeCreate(volumeName string, labels map[string]string) (*volume.Volume, error)
- func (c *Client) VolumeExists(volumeName string) (bool, error)
- func (c *Client) VolumeInspect(volumeName string) (*volume.Volume, error)
- func (c *Client) VolumeList() ([]*volume.Volume, error)
- func (c *Client) VolumeRemove(volumeName string, force bool) error
- type NetworkManager
- func (nm *NetworkManager) ConnectContainer(networkName, containerID string) error
- func (nm *NetworkManager) CreateBridgeNetwork(name, subnet, gateway string) (string, error)
- func (nm *NetworkManager) DisconnectContainer(networkName, containerID string, force bool) error
- func (nm *NetworkManager) EnsureDokuNetwork(networkName, subnet, gateway string) error
- func (nm *NetworkManager) GetConnectedContainers(networkName string) ([]string, error)
- func (nm *NetworkManager) GetNetworkByName(name string) (*types.NetworkResource, error)
- func (nm *NetworkManager) GetNetworkInfo(networkName string) (types.NetworkResource, error)
- func (nm *NetworkManager) IsNetworkHealthy(networkName string) (bool, error)
- func (nm *NetworkManager) ListDokuNetworks() ([]types.NetworkResource, error)
- func (nm *NetworkManager) RemoveDokuNetwork(networkName string) error
- type PortBinding
- type ResourceConfig
- type TCPRouterLabels
- type TraefikLabels
Constants ¶
const ( DefaultNetworkName = "doku-network" DefaultNetworkSubnet = "172.20.0.0/16" DefaultNetworkGateway = "172.20.0.1" )
Variables ¶
This section is empty.
Functions ¶
func ApplyResourceLimits ¶
func ApplyResourceLimits(hostConfig *container.HostConfig, config ResourceConfig) error
ApplyResourceLimits applies resource limits to container host config
func BuildImageName ¶
BuildImageName constructs a full image name with tag
func ContainerHasLabel ¶
ContainerHasLabel checks if a container has a specific label
func CreateEnvVars ¶
CreateEnvVars converts a map to Docker environment variable format
func CreatePortBindings ¶
func CreatePortBindings(bindings []PortBinding) nat.PortMap
CreatePortBindings creates Docker port bindings from PortBinding configs
func CreateRestartPolicy ¶
func CreateRestartPolicy(policy string) container.RestartPolicy
CreateRestartPolicy creates a container restart policy
func CreateVolumeMounts ¶
CreateVolumeMounts creates volume mount configuration
func DisableTraefikLabels ¶
DisableTraefikLabels returns labels that disable Traefik for a container
func ExtractInstanceName ¶
ExtractInstanceName extracts the Doku instance name from container labels
func FormatCPUQuota ¶
FormatCPUQuota converts Docker CPU quota/period to human-readable cores
func FormatContainerID ¶
FormatContainerID shortens a container ID for display
func FormatMemoryBytes ¶
FormatMemoryBytes converts bytes to human-readable format
func GenerateContainerName ¶
GenerateContainerName generates a Docker container name with doku prefix
func GenerateDokuManagedLabels ¶
GenerateDokuManagedLabels generates common labels for Doku-managed containers
func GenerateTCPRouterLabels ¶
func GenerateTCPRouterLabels(config TCPRouterLabels) map[string]string
GenerateTCPRouterLabels generates Traefik TCP router labels
func GenerateTraefikLabels ¶
func GenerateTraefikLabels(config TraefikLabels) map[string]string
GenerateTraefikLabels generates Docker labels for Traefik routing
func GenerateTraefikLabelsForDashboard ¶
GenerateTraefikLabelsForDashboard generates labels for Traefik dashboard
func GenerateTraefikLabelsForService ¶
func GenerateTraefikLabelsForService(instanceName, domain string, port int, useTLS bool) map[string]string
GenerateTraefikLabelsForService generates labels for a standard service
func GenerateVolumeName ¶
GenerateVolumeName generates a Docker volume name
func GetContainerState ¶
GetContainerState returns a simplified container state
func GetImageRepository ¶
GetImageRepository extracts repository from image name e.g., "postgres:14" -> "postgres"
func GetImageTag ¶
GetImageTag extracts tag from image name e.g., "postgres:14" -> "14"
func IsDokuContainer ¶
IsDokuContainer checks if a container is managed by Doku
func MergeLabels ¶
MergeLabels merges multiple label maps into one
func NormalizeImageName ¶
NormalizeImageName normalizes an image name e.g., "postgres" -> "postgres:latest", "postgres:14" -> "postgres:14"
func ParseCPUString ¶
ParseCPUString converts CPU strings like "0.5", "1", "2" to Docker CPU quota and period Docker uses CPUPeriod (default 100000) and CPUQuota to represent CPU limits For example, 0.5 CPUs = CPUQuota 50000 with CPUPeriod 100000
func ParseContainerName ¶
ParseContainerName extracts instance name from container name e.g., "doku-postgres-14" -> "postgres-14"
func ParseEnvVars ¶
ParseEnvVars converts Docker environment variable format to map
func ParseMemoryString ¶
ParseMemoryString converts memory strings like "512m", "1g" to bytes
func SanitizeContainerName ¶
SanitizeContainerName ensures container name is valid
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Docker SDK client
func (*Client) ContainerCreate ¶
func (c *Client) ContainerCreate(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (string, error)
ContainerCreate creates a new container
func (*Client) ContainerExists ¶
ContainerExists checks if a container exists
func (*Client) ContainerInspect ¶
func (c *Client) ContainerInspect(containerID string) (types.ContainerJSON, error)
ContainerInspect returns detailed information about a container
func (*Client) ContainerList ¶
ContainerList lists all containers
func (*Client) ContainerLogs ¶
ContainerLogs retrieves logs from a container
func (*Client) ContainerRemove ¶
ContainerRemove removes a container
func (*Client) ContainerRestart ¶
ContainerRestart restarts a container
func (*Client) ContainerStart ¶
ContainerStart starts a container
func (*Client) ContainerStats ¶
func (c *Client) ContainerStats(containerID string) (types.ContainerStats, error)
ContainerStats returns resource usage statistics for a container
func (*Client) ContainerStop ¶
ContainerStop stops a container
func (*Client) ImageExists ¶
ImageExists checks if an image exists locally
func (*Client) ImageRemove ¶
ImageRemove removes an image
func (*Client) IsDockerAvailable ¶
IsDockerAvailable checks if Docker is available and running
func (*Client) ListContainersByLabel ¶
func (c *Client) ListContainersByLabel(ctx context.Context, labelKey, labelValue string) ([]types.Container, error)
ListContainersByLabel lists containers with a specific label
func (*Client) ListVolumesByLabel ¶
func (c *Client) ListVolumesByLabel(ctx context.Context, labelKey, labelValue string) ([]*volume.Volume, error)
ListVolumesByLabel lists volumes with a specific label
func (*Client) NetworkConnect ¶
NetworkConnect connects a container to a network
func (*Client) NetworkCreate ¶
NetworkCreate creates a new network
func (*Client) NetworkDisconnect ¶
NetworkDisconnect disconnects a container from a network
func (*Client) NetworkExists ¶
NetworkExists checks if a network exists
func (*Client) NetworkInspect ¶
func (c *Client) NetworkInspect(networkID string) (types.NetworkResource, error)
NetworkInspect returns detailed information about a network
func (*Client) NetworkList ¶
func (c *Client) NetworkList() ([]types.NetworkResource, error)
NetworkList lists all networks
func (*Client) NetworkRemove ¶
NetworkRemove removes a network
func (*Client) RemoveContainer ¶
RemoveContainer removes a container by name or ID
func (*Client) RemoveNetwork ¶
RemoveNetwork removes a network by name or ID
func (*Client) RemoveVolume ¶
RemoveVolume removes a volume by name
func (*Client) StopContainer ¶
StopContainer stops a container by name or ID
func (*Client) VolumeCreate ¶
VolumeCreate creates a new volume
func (*Client) VolumeExists ¶
VolumeExists checks if a volume exists
func (*Client) VolumeInspect ¶
VolumeInspect returns detailed information about a volume
func (*Client) VolumeList ¶
VolumeList lists all volumes
type NetworkManager ¶
type NetworkManager struct {
// contains filtered or unexported fields
}
NetworkManager manages Docker networks for Doku
func NewNetworkManager ¶
func NewNetworkManager(client *Client) *NetworkManager
NewNetworkManager creates a new network manager
func (*NetworkManager) ConnectContainer ¶
func (nm *NetworkManager) ConnectContainer(networkName, containerID string) error
ConnectContainer connects a container to a network
func (*NetworkManager) CreateBridgeNetwork ¶
func (nm *NetworkManager) CreateBridgeNetwork(name, subnet, gateway string) (string, error)
CreateBridgeNetwork creates a bridge network with custom subnet and gateway
func (*NetworkManager) DisconnectContainer ¶
func (nm *NetworkManager) DisconnectContainer(networkName, containerID string, force bool) error
DisconnectContainer disconnects a container from a network
func (*NetworkManager) EnsureDokuNetwork ¶
func (nm *NetworkManager) EnsureDokuNetwork(networkName, subnet, gateway string) error
EnsureDokuNetwork ensures the Doku network exists
func (*NetworkManager) GetConnectedContainers ¶
func (nm *NetworkManager) GetConnectedContainers(networkName string) ([]string, error)
GetConnectedContainers returns a list of containers connected to a network
func (*NetworkManager) GetNetworkByName ¶
func (nm *NetworkManager) GetNetworkByName(name string) (*types.NetworkResource, error)
GetNetworkByName retrieves a network by name
func (*NetworkManager) GetNetworkInfo ¶
func (nm *NetworkManager) GetNetworkInfo(networkName string) (types.NetworkResource, error)
GetNetworkInfo returns information about a network
func (*NetworkManager) IsNetworkHealthy ¶
func (nm *NetworkManager) IsNetworkHealthy(networkName string) (bool, error)
IsNetworkHealthy checks if the network is healthy
func (*NetworkManager) ListDokuNetworks ¶
func (nm *NetworkManager) ListDokuNetworks() ([]types.NetworkResource, error)
ListDokuNetworks lists all networks managed by Doku
func (*NetworkManager) RemoveDokuNetwork ¶
func (nm *NetworkManager) RemoveDokuNetwork(networkName string) error
RemoveDokuNetwork removes the Doku network
type PortBinding ¶
PortBinding creates a port binding configuration
type ResourceConfig ¶
type ResourceConfig struct {
MemoryLimit string // e.g., "512m", "1g"
MemoryReserve string
CPULimit string // e.g., "0.5", "1.0", "2"
CPUReserve string
}
ResourceConfig holds resource limit configuration
type TCPRouterLabels ¶
type TCPRouterLabels struct {
Enabled bool
RouterName string
ServiceName string
EntryPoint string
Port int
HostSNI string // For TLS passthrough
}
TCPRouterLabels generates Traefik labels for TCP routing (for databases, etc.)
type TraefikLabels ¶
type TraefikLabels struct {
Enabled bool
RouterName string
ServiceName string
Subdomain string
Domain string
Port int
EntryPoint string // "web" for HTTP, "websecure" for HTTPS
TLS bool
Priority int
PathPrefix string
CustomRules []string
}
TraefikLabels holds Traefik routing configuration