mirror of
https://github.com/amir20/dozzle.git
synced 2026-08-07 11:24:44 +00:00
330e952ca4
Push container / Push branches and PRs (push) Has been cancelled
Deploy VitePress site to Pages / build (push) Has been cancelled
Deploy VitePress site to Pages / Deploy (push) Has been cancelled
Test / Typecheck (push) Has been cancelled
Test / JavaScript Tests (push) Has been cancelled
Test / Go Tests (push) Has been cancelled
Test / Go Staticcheck (push) Has been cancelled
Test / Integration Tests (push) Has been cancelled
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
94 lines
3.3 KiB
Go
94 lines
3.3 KiB
Go
package container_support
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
"github.com/amir20/dozzle/internal/agent"
|
|
"github.com/amir20/dozzle/internal/container"
|
|
"github.com/amir20/dozzle/types"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type agentService struct {
|
|
client *agent.Client
|
|
host atomic.Pointer[container.Host]
|
|
}
|
|
|
|
func NewAgentService(client *agent.Client) ClientService {
|
|
return &agentService{
|
|
client: client,
|
|
}
|
|
}
|
|
|
|
func (a *agentService) FindContainer(ctx context.Context, id string, labels container.ContainerLabels) (container.Container, error) {
|
|
return a.client.FindContainer(ctx, id, labels)
|
|
}
|
|
|
|
func (a *agentService) RawLogs(ctx context.Context, container container.Container, from time.Time, to time.Time, stdTypes container.StdType) (io.ReadCloser, error) {
|
|
return a.client.StreamRawBytes(ctx, container.ID, from, to, stdTypes)
|
|
}
|
|
|
|
func (a *agentService) LogsBetweenDates(ctx context.Context, container container.Container, from time.Time, to time.Time, stdTypes container.StdType) (<-chan *container.LogEvent, error) {
|
|
return a.client.LogsBetweenDates(ctx, container.ID, from, to, stdTypes)
|
|
}
|
|
|
|
func (a *agentService) StreamLogs(ctx context.Context, container container.Container, from time.Time, stdTypes container.StdType, events chan<- *container.LogEvent) error {
|
|
return a.client.StreamContainerLogs(ctx, container.ID, from, stdTypes, events)
|
|
}
|
|
|
|
func (a *agentService) ListContainers(ctx context.Context, labels container.ContainerLabels) ([]container.Container, error) {
|
|
log.Debug().Interface("labels", labels).Msg("Listing containers from agent")
|
|
return a.client.ListContainers(ctx, labels)
|
|
}
|
|
|
|
func (a *agentService) Host(ctx context.Context) (container.Host, error) {
|
|
host, err := a.client.Host(ctx)
|
|
if err != nil {
|
|
if cached := a.host.Load(); cached != nil {
|
|
h := *cached
|
|
h.Available = false
|
|
return h, err
|
|
}
|
|
return container.Host{Available: false}, err
|
|
}
|
|
|
|
a.host.Store(&host)
|
|
return host, nil
|
|
}
|
|
|
|
func (a *agentService) SubscribeStats(ctx context.Context, stats chan<- container.ContainerStat) {
|
|
go a.client.StreamStats(ctx, stats)
|
|
}
|
|
|
|
func (a *agentService) SubscribeEvents(ctx context.Context, events chan<- container.ContainerEvent) {
|
|
go a.client.StreamEvents(ctx, events)
|
|
}
|
|
|
|
func (d *agentService) SubscribeContainersStarted(ctx context.Context, containers chan<- container.Container) {
|
|
go d.client.StreamNewContainers(ctx, containers)
|
|
}
|
|
|
|
func (a *agentService) ContainerAction(ctx context.Context, container container.Container, action container.ContainerAction) error {
|
|
return a.client.ContainerAction(ctx, container.ID, action)
|
|
}
|
|
|
|
func (a *agentService) Attach(ctx context.Context, c container.Container, events container.ExecEventReader, stdout io.Writer) error {
|
|
panic("not implemented")
|
|
}
|
|
|
|
func (a *agentService) Exec(ctx context.Context, c container.Container, cmd []string, events container.ExecEventReader, stdout io.Writer) error {
|
|
return a.client.Exec(ctx, c.ID, cmd, events, stdout)
|
|
}
|
|
|
|
func (a *agentService) UpdateNotificationConfig(ctx context.Context, subscriptions []types.SubscriptionConfig, dispatchers []types.DispatcherConfig) error {
|
|
return a.client.UpdateNotificationConfig(ctx, subscriptions, dispatchers)
|
|
}
|
|
|
|
func (a *agentService) GetNotificationStats(ctx context.Context) ([]types.SubscriptionStats, error) {
|
|
return a.client.GetNotificationStats(ctx)
|
|
}
|