forked from krystal/guvnor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
purge.go
41 lines (35 loc) · 794 Bytes
/
purge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package guvnor
import (
"context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"go.uber.org/zap"
)
func (e *Engine) Purge(ctx context.Context) error {
e.log.Debug("purging all containers owned by guvnor")
listToShutdown, err := e.docker.ContainerList(ctx, types.ContainerListOptions{
All: true,
Filters: filters.NewArgs(
filters.Arg("label", managedLabel),
),
})
if err != nil {
return err
}
for _, containerToShutdown := range listToShutdown {
e.log.Debug("purging container",
zap.String("container", containerToShutdown.ID),
)
err = e.docker.ContainerRemove(
ctx,
containerToShutdown.ID,
types.ContainerRemoveOptions{
Force: true,
},
)
if err != nil {
return err
}
}
return e.state.Purge()
}