(ctx context.Context, destroyVolumes bool)
| 218 | } |
| 219 | |
| 220 | func (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 |
no test coverage detected