MCPcopy
hub / github.com/spacecloud-io/space-cloud / DockerStop

Function DockerStop

space-cli/cmd/modules/operations/stop.go:16–67  ·  view source on GitHub ↗

DockerStop stops the services which have been started

(clusterName string)

Source from the content-addressed store, hash-verified

14
15// DockerStop stops the services which have been started
16func DockerStop(clusterName string) error {
17
18 ctx := context.Background()
19
20 // Create a docker client
21 docker, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
22 if err != nil {
23 return utils.LogError("Unable to initialize docker client", err)
24 }
25
26 containers, err := utils.GetContainers(ctx, docker, clusterName, model.ServiceContainers)
27 if err != nil {
28 _ = utils.LogError(fmt.Sprintf("Unable to list containers - %s", err.Error()), nil)
29 return err
30 }
31
32 for _, container := range containers {
33 // First stop the container
34 if err := docker.ContainerStop(ctx, container.ID, nil); err != nil {
35 return utils.LogError(fmt.Sprintf("Unable to stop container (%s)", container.ID), err)
36 }
37 }
38
39 argsSC := filters.Arg("label", "app=space-cloud")
40 argsNetwork := filters.Arg("network", utils.GetNetworkName(clusterName))
41 scContainers, err := docker.ContainerList(ctx, types.ContainerListOptions{Filters: filters.NewArgs(argsNetwork, argsSC), All: true})
42 if err != nil {
43 return utils.LogError("Unable to list space-cloud core containers", err)
44 }
45
46 for _, container := range scContainers {
47 // First stop the container
48 if err := docker.ContainerStop(ctx, container.ID, nil); err != nil {
49 return utils.LogError(fmt.Sprintf("Unable to stop container (%s)", container.ID), err)
50 }
51 }
52
53 argsAddOns := filters.Arg("label", "app=addon")
54 argsNetwork = filters.Arg("network", utils.GetNetworkName(clusterName))
55 addOnContainers, err := docker.ContainerList(ctx, types.ContainerListOptions{Filters: filters.NewArgs(argsNetwork, argsAddOns), All: true})
56 if err != nil {
57 return utils.LogError("Unable to list space-cloud core containers", err)
58 }
59
60 for _, container := range addOnContainers {
61 // First stop the container
62 if err := docker.ContainerStop(ctx, container.ID, nil); err != nil {
63 return utils.LogError(fmt.Sprintf("Unable to stop container (%s)", container.ID), err)
64 }
65 }
66 return nil
67}

Callers 1

actionStopFunction · 0.85

Calls 1

ErrorMethod · 0.65

Tested by

no test coverage detected