dockerutil

package module
v0.0.0-...-4736132 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: GPL-3.0 Imports: 23 Imported by: 2

README

this module handles docker compose management for my transliteration libraries. I think of it as an internal pkg and therefore I recommend not using except if you want to fork it.

Documentation

Overview

Package dockerutil provides reusable Docker container management functionality for transliteration services.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotInitialized is returned when operations are attempted before initialization
	ErrNotInitialized = errors.New("project not initialized, was Init() called?")

	// logger internal to the library:
	Logger = zerolog.Nop()
)
View Source
var (
	// docker's logger:
	// never disable this logger at it is monitored for init message.
	// To hide logs pass level zerolog.Disabled in LogConfig to NewContainerLogConsumer.
	DockerLogger    zerolog.Logger
	DockerLogBuffer bytes.Buffer
)

Functions

func DockerBackendName

func DockerBackendName() string

func EngineIsReachable

func EngineIsReachable() error

EngineIsReachable verifies if Docker daemon is running and accessible Returns nil if Docker is reachable, otherwise returns an error with details

func FindComposeFile

func FindComposeFile(dirPath string) (string, error)

FindComposeFile searches for a Docker Compose file in the specified directory following the official Compose specification naming scheme. It returns the full path to the first matching file found and nil error if successful, or empty string and error if no compose file is found or if there's an error accessing the directory.

func GetConfigDir

func GetConfigDir(projectName string) (string, error)

GetConfigDir returns the platform-specific configuration directory

func SetLogOutput

func SetLogOutput(output LogOutput)

SetLogOutput configures where Docker logs are written

Types

type Config

type Config struct {
	ProjectName      string
	ComposeFile      string
	RemoteRepo       string
	RequiredServices []string
	LogConsumer      LogConsumer
	Timeout          Timeout
}

Config holds configuration options for DockerManager

type ContainerLogConsumer

type ContainerLogConsumer struct {
	Prefix      string
	ShowService bool
	ShowType    bool
	Level       zerolog.Level
	InitChan    chan struct{}
	FailedChan  chan error
	InitMessage string // Message that indicates initialization is complete
}

ContainerLogConsumer implements log consumption for Docker containers

func NewContainerLogConsumer

func NewContainerLogConsumer(config LogConfig) *ContainerLogConsumer

NewContainerLogConsumer creates a new log consumer with the specified configuration

func (*ContainerLogConsumer) Close

func (l *ContainerLogConsumer) Close()

Close closes the initialization and failure channels

func (*ContainerLogConsumer) Err

func (l *ContainerLogConsumer) Err(containerName, message string)

Err handles stderr messages from containers

func (*ContainerLogConsumer) GetInitChan

func (l *ContainerLogConsumer) GetInitChan() chan struct{}

func (*ContainerLogConsumer) Log

func (l *ContainerLogConsumer) Log(containerName, message string)

Log handles stdout messages from containers

func (*ContainerLogConsumer) Register

func (l *ContainerLogConsumer) Register(container string)

Register handles container registration events

func (*ContainerLogConsumer) Status

func (l *ContainerLogConsumer) Status(container, msg string)

Status handles container status messages

type DockerManager

type DockerManager struct {
	Timeout Timeout
	// contains filtered or unexported fields
}

DockerManager handles Docker container lifecycle management

func NewDockerManager

func NewDockerManager(ctx context.Context, cfg Config) (*DockerManager, error)

NewDockerManager creates a new Docker service manager instance

func (*DockerManager) Close

func (dm *DockerManager) Close() error

Close implements io.Closer

func (*DockerManager) Down

func (dm *DockerManager) Down() error

func (*DockerManager) GetClient

func (dm *DockerManager) GetClient() (*client.Client, error)

GetClient returns the underlying Docker client

func (*DockerManager) Init

func (dm *DockerManager) Init() error

Init builds and up the containers

func (*DockerManager) InitQuiet

func (dm *DockerManager) InitQuiet() error

InitQuiet initializes with reduced logging

func (*DockerManager) InitRecreate

func (dm *DockerManager) InitRecreate() error

InitRecreate remove existing containers, builds and up new containers

func (*DockerManager) InitRecreateNoCache

func (dm *DockerManager) InitRecreateNoCache() error

InitRecreateNoCache remove existing containers and downloads the lastest version of dependencies then builds and up the containers

func (*DockerManager) Status

func (dm *DockerManager) Status() (string, error)

Status returns the current status of containers

func (*DockerManager) Stop

func (dm *DockerManager) Stop() error

Stop stops all running containers

type GitManager

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

GitManager handles Git repository operations

func NewGitManager

func NewGitManager(repoURL, localPath string) *GitManager

NewGitManager creates a new Git manager instance

func (*GitManager) CheckIfUpdateNeeded

func (gm *GitManager) CheckIfUpdateNeeded() (bool, error)

CheckIfUpdateNeeded checks if the local repository needs updating

func (*GitManager) EnsureRepoExists

func (gm *GitManager) EnsureRepoExists() error

EnsureRepo ensures the repository exists

type LogConfig

type LogConfig struct {
	Prefix      string
	ShowService bool
	ShowType    bool
	LogLevel    zerolog.Level
	InitMessage string
}

LogConfig holds configuration for the log consumer

type LogConsumer

type LogConsumer interface {
	Log(containerName, message string)
	Err(containerName, message string)
	Status(container, msg string)
	Register(container string)
	GetInitChan() chan struct{}
}

LogConsumer defines the interface for consuming Docker container logs

type LogOutput

type LogOutput int
const (
	LogToNowhere LogOutput = iota
	LogToStdout
	LogToBuffer
	LogToBoth
)

type Timeout

type Timeout struct {
	Create   time.Duration
	Recreate time.Duration
	// until containers reached the running|healthy state
	Start time.Duration
}

Jump to

Keyboard shortcuts

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