feat(pre-deploy): add support for pre-deploy hook containers in service management, sync *all* containers to store

This commit is contained in:
Pasha Sviderski
2026-04-08 19:16:28 +10:00
parent cef047221c
commit 1c8b77054a
11 changed files with 508 additions and 298 deletions
+24 -17
View File
@@ -109,7 +109,7 @@ func (cli *Client) InspectService(ctx context.Context, nameOrID string) (api.Ser
}
listCtx := metadata.NewOutgoingContext(ctx, md)
// List all service containers including stopped ones.
// List all service containers including stopped ones and deployment hooks.
opts := container.ListOptions{All: true}
machineContainers, err := cli.Docker.ListServiceContainers(listCtx, nameOrID, opts)
if err != nil {
@@ -146,16 +146,15 @@ func (cli *Client) InspectService(ctx context.Context, nameOrID string) (api.Ser
}
}
for _, ctr := range mc.Containers {
if ctr.ServiceID() == nameOrID || ctr.ServiceName() == nameOrID {
containers = append(containers, api.MachineServiceContainer{
MachineID: machineID,
Container: ctr,
})
// Collect both regular and hook containers for the service.
for _, ctr := range append(mc.Containers, mc.HookContainers...) {
containers = append(containers, api.MachineServiceContainer{
MachineID: machineID,
Container: ctr,
})
if ctr.ServiceID() == nameOrID {
foundByID = true
}
if ctr.ServiceID() == nameOrID {
foundByID = true
}
}
}
@@ -181,14 +180,22 @@ func (cli *Client) InspectService(ctx context.Context, nameOrID string) (api.Ser
}
}
svc = api.Service{
ID: containers[0].Container.ServiceID(),
Name: containers[0].Container.ServiceName(),
Mode: containers[0].Container.ServiceMode(),
Containers: containers,
// Partition containers into regular service containers and hook containers.
var serviceContainers, hookContainers []api.MachineServiceContainer
for _, mc := range containers {
if mc.Container.IsHook() {
hookContainers = append(hookContainers, mc)
} else {
serviceContainers = append(serviceContainers, mc)
}
}
if svc.Mode == "" {
svc.Mode = api.ServiceModeReplicated
svc = api.Service{
ID: containers[0].Container.ServiceID(),
Name: containers[0].Container.ServiceName(),
Mode: containers[0].Container.ServiceMode(),
Containers: serviceContainers,
HookContainers: hookContainers,
}
return svc, nil