fix(pre-deploy): include hook containers in logs, ls, stop commands

This commit is contained in:
Pasha Sviderski
2026-04-08 19:16:42 +10:00
parent 043b85ab70
commit a844cc6f67
2 changed files with 7 additions and 6 deletions
+4 -3
View File
@@ -24,7 +24,8 @@ func (cli *Client) ServiceLogs(
return svc, nil, fmt.Errorf("inspect service: %w", err) return svc, nil, fmt.Errorf("inspect service: %w", err)
} }
if len(svc.Containers) == 0 { allContainers := append(svc.Containers, svc.HookContainers...)
if len(allContainers) == 0 {
return svc, nil, fmt.Errorf("no containers found for service: %s", serviceNameOrID) return svc, nil, fmt.Errorf("no containers found for service: %s", serviceNameOrID)
} }
@@ -35,8 +36,8 @@ func (cli *Client) ServiceLogs(
return svc, nil, fmt.Errorf("list machines: %w", err) return svc, nil, fmt.Errorf("list machines: %w", err)
} }
ctrStreams := make([]<-chan api.ServiceLogEntry, 0, len(svc.Containers)) ctrStreams := make([]<-chan api.ServiceLogEntry, 0, len(allContainers))
for _, ctr := range svc.Containers { for _, ctr := range allContainers {
// Skip containers not running on the specified machines. // Skip containers not running on the specified machines.
m := machines.FindByNameOrID(ctr.MachineID) m := machines.FindByNameOrID(ctr.MachineID)
if len(opts.Machines) > 0 && m == nil { if len(opts.Machines) > 0 && m == nil {
+3 -3
View File
@@ -287,8 +287,8 @@ func (cli *Client) StopService(ctx context.Context, id string, opts container.St
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
errCh := make(chan error) errCh := make(chan error)
// Stop all containers on all machines that belong to the service. // Stop all containers on all machines that belong to the service, including hook containers.
for _, mc := range svc.Containers { for _, mc := range append(svc.Containers, svc.HookContainers...) {
wg.Go(func() { wg.Go(func() {
err := cli.StopContainer(ctx, svc.ID, mc.Container.ID, opts) err := cli.StopContainer(ctx, svc.ID, mc.Container.ID, opts)
if err != nil { if err != nil {
@@ -378,7 +378,7 @@ func (cli *Client) ListServices(ctx context.Context) ([]api.Service, error) {
continue continue
} }
for _, ctr := range mc.Containers { for _, ctr := range append(mc.Containers, mc.HookContainers...) {
if _, ok := servicesByID[ctr.ServiceID()]; ok { if _, ok := servicesByID[ctr.ServiceID()]; ok {
continue continue
} }