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 ¶
- type Backend
- type Client
- func (c *Client) BaseDomain() string
- func (c *Client) Close() error
- func (c *Client) ComposeDown(ctx context.Context, workingDir, configFiles string) (string, error)
- func (c *Client) ComposeLogs(ctx context.Context, workingDir, configFiles string) (io.ReadCloser, error)
- func (c *Client) ComposeRestart(ctx context.Context, workingDir, configFiles string) (string, error)
- func (c *Client) ComposeUp(ctx context.Context, workingDir, configFiles string) (string, error)
- func (c *Client) DiscoverBackends(ctx context.Context) ([]*Backend, error)
- func (c *Client) DiscoverProjects(ctx context.Context) (map[string]*ProjectInfo, error)
- func (c *Client) DockerClient() DockerAPI
- func (c *Client) GetBackend(ctx context.Context, containerID string) (*Backend, error)
- func (c *Client) GetProjectBackends(ctx context.Context, projectName string) ([]*Backend, error)
- func (c *Client) GetProjectInfo(ctx context.Context, containerID string) (*ProjectInfo, error)
- func (c *Client) Networks() []string
- func (c *Client) RestartContainer(ctx context.Context, containerID string) error
- type ContainerEvent
- type DockerAPI
- type EventType
- type ProjectInfo
- type Watcher
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 NewClientWithAPI ¶
NewClientWithAPI creates a new client with a custom DockerAPI implementation This is useful for testing with mock implementations
func (*Client) BaseDomain ¶
BaseDomain returns the base domain for hostnames
func (*Client) ComposeDown ¶ added in v0.9.0
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
ComposeUp runs "docker compose up -d" for the given project.
func (*Client) DiscoverBackends ¶
DiscoverBackends finds all containers connected to any of the watched networks
func (*Client) DiscoverProjects ¶ added in v0.4.0
DiscoverProjects finds all docker-compose projects on any of the watched networks
func (*Client) DockerClient ¶
DockerClient returns the underlying Docker API client (for event watching)
func (*Client) GetBackend ¶
GetBackend gets a single backend by container ID
func (*Client) GetProjectBackends ¶
GetProjectBackends gets all backends for a specific project across all watched networks
func (*Client) GetProjectInfo ¶ added in v0.4.0
GetProjectInfo extracts project metadata from a container
type ContainerEvent ¶
ContainerEvent represents a container start/stop event
type DockerAPI ¶
type DockerAPI interface {
ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
ContainerRestart(ctx context.Context, containerID string, options container.StopOptions) error
Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error)
Close() error
}
DockerAPI defines the interface for Docker API operations This interface allows for mocking in tests
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 ¶
NewWatcher creates a new container watcher