Files
tiny-forge/internal/docker/client.go
T
alexei.dolgolyov 791cd4d6af
Build / build (push) Successful in 12m20s
feat: rename Docker Watcher to Tinyforge
Rebrand the project as Tinyforge to reflect its evolution from a Docker
container watcher into a self-hosted mini CI/deployment platform.

Rename covers: Go module path, Docker labels, DB/config filenames,
JWT issuer, Dockerfile binary, docker-compose, CI workflows, frontend
i18n, README with static sites docs, and all code comments.
2026-04-12 21:30:39 +03:00

51 lines
1.1 KiB
Go

package docker
import (
"context"
"fmt"
"github.com/moby/moby/client"
)
// Labels applied to all containers managed by Tinyforge.
const (
LabelProject = "tinyforge.project"
LabelStage = "tinyforge.stage"
LabelInstanceID = "tinyforge.instance-id"
)
// Client wraps the Docker Engine API client.
type Client struct {
api client.APIClient
}
// New creates a new Docker client connected to the default Docker socket.
func New() (*Client, error) {
api, err := client.NewClientWithOpts(
client.FromEnv,
client.WithAPIVersionNegotiation(),
)
if err != nil {
return nil, fmt.Errorf("create docker client: %w", err)
}
return &Client{api: api}, nil
}
// Close releases resources held by the Docker client.
func (c *Client) Close() error {
if err := c.api.Close(); err != nil {
return fmt.Errorf("close docker client: %w", err)
}
return nil
}
// Ping checks connectivity to the Docker daemon.
func (c *Client) Ping(ctx context.Context) error {
_, err := c.api.Ping(ctx, client.PingOptions{})
if err != nil {
return fmt.Errorf("ping docker daemon: %w", err)
}
return nil
}