github.com/dnephin/dobi@v0.15.0/tasks/job/common.go (about) 1 package job 2 3 import ( 4 "fmt" 5 6 "github.com/dnephin/dobi/tasks/client" 7 "github.com/dnephin/dobi/tasks/context" 8 docker "github.com/fsouza/go-dockerclient" 9 log "github.com/sirupsen/logrus" 10 ) 11 12 // containerName returns the name of the container 13 func containerName(ctx *context.ExecuteContext, name string) string { 14 return fmt.Sprintf("%s-%s", ctx.Env.Unique(), name) 15 } 16 17 // removeContainer removes a container by ID, and logs a warning if the remove 18 // fails. 19 func removeContainer( 20 logger *log.Entry, 21 client client.DockerClient, 22 containerID string, 23 ) (bool, error) { 24 logger.Debug("Removing container") 25 err := client.RemoveContainer(docker.RemoveContainerOptions{ 26 ID: containerID, 27 RemoveVolumes: true, 28 Force: true, 29 }) 30 switch err.(type) { 31 case *docker.NoSuchContainer: 32 return false, nil 33 case nil: 34 return true, nil 35 } 36 logger.WithFields(log.Fields{"container": containerID}).Warnf( 37 "Failed to remove container: %s", err) 38 return false, err 39 }