mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-10 03:30:40 +00:00
Clean out untagged Docker images after build
This commit is contained in:
parent
4023d44674
commit
2bf7ebf219
24
main.go
24
main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -228,6 +229,29 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Remove untagged images, if any
|
||||
var outbuf bytes.Buffer
|
||||
cmd = exec.Command("sh", "-c", "docker images | grep '^<none>' | awk '{print $3}'")
|
||||
cmd.Stdout = &outbuf
|
||||
cmd.Stderr = os.Stderr
|
||||
trace(cmd)
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if outbuf.Len() > 0 {
|
||||
images := strings.Split(strings.TrimSpace(outbuf.String()), "\n")
|
||||
cmd = exec.Command("docker", append([]string{"rmi"}, images...)...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
trace(cmd)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Save to tarred image repository
|
||||
if len(vargs.Save.File) != 0 {
|
||||
// if the destination directory does not exist, create it
|
||||
|
Loading…
Reference in New Issue
Block a user