652229c67f
Migrate Docker SDK from github.com/docker/docker (+incompatible) to github.com/moby/moby/client v0.3.0 + moby/moby/api v1.54.0 (proper Go modules). Adapt all container/image/network operations to the new moby API (Filters, ContainerListOptions, PullResponse, InspectResult, etc.). Add AsyncTriggerDeploy runDeploy method. Fix SvelteKit build: disable prerender, set strict=false for SPA, bump vite-plugin-svelte to v5 for vite 6 compat. Add .dockerignore to exclude .git, node_modules, plans.
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package docker
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/moby/moby/client"
|
|
)
|
|
|
|
// Labels applied to all containers managed by docker-watcher.
|
|
const (
|
|
LabelProject = "docker-watcher.project"
|
|
LabelStage = "docker-watcher.stage"
|
|
LabelInstanceID = "docker-watcher.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
|
|
}
|