mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
feat(pre-deploy): add support for pre-deploy hook containers in service management, sync *all* containers to store
This commit is contained in:
+24
-17
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user