MCPcopy
hub / github.com/basecamp/once / Destroy

Method Destroy

internal/docker/application.go:220–251  ·  view source on GitHub ↗
(ctx context.Context, destroyVolumes bool)

Source from the content-addressed store, hash-verified

218}
219
220func (a *Application) Destroy(ctx context.Context, destroyVolumes bool) error {
221 containers, err := a.namespace.client.ContainerList(ctx, container.ListOptions{All: true})
222 if err != nil {
223 return err
224 }
225
226 for _, c := range containers {
227 for _, name := range c.Names {
228 name = strings.TrimPrefix(name, "/")
229 if a.namespace.containerAppName(name) == a.Settings.Name {
230 if err := a.namespace.client.ContainerRemove(ctx, c.ID, container.RemoveOptions{Force: true}); err != nil {
231 return fmt.Errorf("removing container: %w", err)
232 }
233 break
234 }
235 }
236 }
237
238 if destroyVolumes {
239 vol, err := FindVolume(ctx, a.namespace, a.Settings.Name)
240 if err != nil && !errors.Is(err, ErrVolumeNotFound) {
241 return fmt.Errorf("getting volume: %w", err)
242 }
243 if vol != nil {
244 if err := vol.Destroy(ctx); err != nil {
245 return err
246 }
247 }
248 }
249
250 return nil
251}
252
253// Private
254

Callers 4

runMethod · 0.95
runInstallMethod · 0.95
RemoveMethod · 0.95
RestoreMethod · 0.95

Calls 3

FindVolumeFunction · 0.85
containerAppNameMethod · 0.80
ContainerListMethod · 0.65

Tested by

no test coverage detected