Documentation
¶
Overview ¶
Package dockerutil provides reusable Docker container management functionality for transliteration services.
Index ¶
- Variables
- func DockerBackendName() string
- func EngineIsReachable() error
- func FindComposeFile(dirPath string) (string, error)
- func GetConfigDir(projectName string) (string, error)
- func SetLogOutput(output LogOutput)
- type Config
- type ContainerLogConsumer
- func (l *ContainerLogConsumer) Close()
- func (l *ContainerLogConsumer) Err(containerName, message string)
- func (l *ContainerLogConsumer) GetInitChan() chan struct{}
- func (l *ContainerLogConsumer) Log(containerName, message string)
- func (l *ContainerLogConsumer) Register(container string)
- func (l *ContainerLogConsumer) Status(container, msg string)
- type DockerManager
- func (dm *DockerManager) Close() error
- func (dm *DockerManager) Down() error
- func (dm *DockerManager) GetClient() (*client.Client, error)
- func (dm *DockerManager) Init() error
- func (dm *DockerManager) InitQuiet() error
- func (dm *DockerManager) InitRecreate() error
- func (dm *DockerManager) InitRecreateNoCache() error
- func (dm *DockerManager) Status() (string, error)
- func (dm *DockerManager) Stop() error
- type GitManager
- type LogConfig
- type LogConsumer
- type LogOutput
- type Timeout
Constants ¶
This section is empty.
Variables ¶
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() )
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 ¶
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 ¶
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) 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