mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-25 09:10:39 +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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"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
|
// Save to tarred image repository
|
||||||
if len(vargs.Save.File) != 0 {
|
if len(vargs.Save.File) != 0 {
|
||||||
// if the destination directory does not exist, create it
|
// if the destination directory does not exist, create it
|
||||||
|
Loading…
Reference in New Issue
Block a user