docker

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package docker provides Docker API client functionality for service discovery.

It handles:

  • Container discovery on the roji network
  • Docker Compose project detection
  • Backend extraction from container metadata
  • Event monitoring for dynamic updates

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	ContainerID   string
	ContainerName string
	ServiceName   string // docker-compose service name
	ProjectName   string // docker-compose project name
	Host          string // Container IP in the shared network
	Port          int
	Hostname      string              // The hostname to route to this backend
	PathPrefix    string              // Optional path prefix
	Warning       string              // Warning message (e.g., "no port exposed")
	Network       string              // Docker network name this container was found on
	MockRoutes    []*config.MockRoute // Mock responses defined via labels
	BasicAuth     *config.BasicAuth   // Basic authentication (optional)
}

Backend represents a proxied service

type Client

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

Client wraps the Docker client for container discovery

func NewClient

func NewClient(networks []string, baseDomain string) (*Client, error)

NewClient creates a new Docker client wrapper

func NewClientWithAPI

func NewClientWithAPI(api DockerAPI, networks []string, baseDomain string) *Client

NewClientWithAPI creates a new client with a custom DockerAPI implementation This is useful for testing with mock implementations

func (*Client) BaseDomain

func (c *Client) BaseDomain() string

BaseDomain returns the base domain for hostnames

func (*Client) Close

func (c *Client) Close() error

Close closes the Docker client

func (*Client) ComposeDown added in v0.9.0

func (c *Client) ComposeDown(ctx context.Context, workingDir, configFiles string) (string, error)

ComposeDown runs "docker compose down" for the given project.

func (*Client) ComposeLogs added in v0.9.0

func (c *Client) ComposeLogs(ctx context.Context, workingDir, configFiles string) (io.ReadCloser, error)

ComposeLogs runs "docker compose logs -f" and returns a reader for the log stream.

func (*Client) ComposeRestart added in v0.9.0

func (c *Client) ComposeRestart(ctx context.Context, workingDir, configFiles string) (string, error)

ComposeRestart runs "docker compose restart" for the given project.

func (*Client) ComposeUp added in v0.9.0

func (c *Client) ComposeUp(ctx context.Context, workingDir, configFiles string) (string, error)

ComposeUp runs "docker compose up -d" for the given project.

func (*Client) DiscoverBackends

func (c *Client) DiscoverBackends(ctx context.Context) ([]*Backend, error)

DiscoverBackends finds all containers connected to any of the watched networks

func (*Client) DiscoverProjects added in v0.4.0

func (c *Client) DiscoverProjects(ctx context.Context) (map[string]*ProjectInfo, error)

DiscoverProjects finds all docker-compose projects on any of the watched networks

func (*Client) DockerClient

func (c *Client) DockerClient() DockerAPI

DockerClient returns the underlying Docker API client (for event watching)

func (*Client) GetBackend

func (c *Client) GetBackend(ctx context.Context, containerID string) (*Backend, error)

GetBackend gets a single backend by container ID

func (*Client) GetProjectBackends

func (c *Client) GetProjectBackends(ctx context.Context, projectName string) ([]*Backend, error)

GetProjectBackends gets all backends for a specific project across all watched networks

func (*Client) GetProjectInfo added in v0.4.0

func (c *Client) GetProjectInfo(ctx context.Context, containerID string) (*ProjectInfo, error)

GetProjectInfo extracts project metadata from a container

func (*Client) Networks added in v0.6.0

func (c *Client) Networks() []string

Networks returns the network names being watched

func (*Client) RestartContainer added in v0.6.0

func (c *Client) RestartContainer(ctx context.Context, containerID string) error

RestartContainer restarts a container by ID

type ContainerEvent

type ContainerEvent struct {
	Type        EventType
	ContainerID string
}

ContainerEvent represents a container start/stop event

type DockerAPI

DockerAPI defines the interface for Docker API operations This interface allows for mocking in tests

type EventType

type EventType int

EventType represents the type of container event

const (
	EventStart EventType = iota
	EventStop
)

type ProjectInfo added in v0.4.0

type ProjectInfo struct {
	Name        string   // Project name from com.docker.compose.project
	WorkingDir  string   // Working directory from com.docker.compose.project.working_dir
	ConfigFiles string   // Config files from com.docker.compose.project.config_files
	Services    []string // List of service names in this project
}

ProjectInfo contains docker-compose project metadata

type Watcher

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

Watcher watches for container events on the shared network

func NewWatcher

func NewWatcher(client *Client) *Watcher

NewWatcher creates a new container watcher

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context) <-chan ContainerEvent

Watch starts watching for container events and returns a channel of events. Automatically reconnects if the connection is lost.

Jump to

Keyboard shortcuts

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