(ctx context.Context, containers []containerd.Container, opt RemoveOptions)
| 64 | } |
| 65 | |
| 66 | func (c *Composer) removeContainers(ctx context.Context, containers []containerd.Container, opt RemoveOptions) error { |
| 67 | args := []string{"rm", "-f"} |
| 68 | if opt.Volumes { |
| 69 | args = append(args, "-v") |
| 70 | } |
| 71 | |
| 72 | var rmWG sync.WaitGroup |
| 73 | for _, container := range containers { |
| 74 | container := container |
| 75 | rmWG.Add(1) |
| 76 | go func() { |
| 77 | defer rmWG.Done() |
| 78 | info, _ := container.Info(ctx, containerd.WithoutRefreshedMetadata) |
| 79 | // if not `Stop`, check status and skip running container |
| 80 | if !opt.Stop { |
| 81 | cStatus := formatter.ContainerStatus(ctx, container) |
| 82 | if strings.HasPrefix(cStatus, "Up") { |
| 83 | log.G(ctx).Warnf("Removing container %s failed: container still running.", info.Labels[labels.Name]) |
| 84 | return |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | log.G(ctx).Infof("Removing container %s", info.Labels[labels.Name]) |
| 89 | if err := c.runNerdctlCmd(ctx, append(args, container.ID())...); err != nil { |
| 90 | log.G(ctx).Warn(err) |
| 91 | } |
| 92 | }() |
| 93 | } |
| 94 | rmWG.Wait() |
| 95 | |
| 96 | return nil |
| 97 | } |
| 98 | |
| 99 | func (c *Composer) removeContainersFromParsedServices(ctx context.Context, containers map[string]serviceparser.Container) { |
| 100 | var rmWG sync.WaitGroup |
no test coverage detected