Files
dokku/plugins/builder/functions.go
Jose Diaz-Gonzalez 64ff701cd8 fix: clean up local build images immediately after an image is released
In some cases, we might hold onto intermediate images until the next deploy. While these images are generally part of newer images - and are therefore cleaned up when the child images are no longer in use - they cruft up the 'docker image ls' output, causing some folks to believe Dokku is not cleaning up images.

Refs #6272
2023-10-14 22:36:31 -04:00

49 lines
859 B
Go

package builder
import (
"bytes"
"errors"
"io/ioutil"
"os"
"path"
"strings"
"github.com/dokku/dokku/plugins/common"
)
func listImagesByImageRepo(imageRepo string) ([]string, error) {
command := []string{
common.DockerBin(),
"image",
"ls",
"--quiet",
imageRepo,
}
var stderr bytes.Buffer
listCmd := common.NewShellCmd(strings.Join(command, " "))
listCmd.ShowOutput = false
listCmd.Command.Stderr = &stderr
b, err := listCmd.Output()
if err != nil {
return []string{}, errors.New(strings.TrimSpace(stderr.String()))
}
output := strings.Split(strings.TrimSpace(string(b[:])), "\n")
return output, nil
}
func removeAllContents(basePath string) error {
dir, err := ioutil.ReadDir(basePath)
if err != nil {
return err
}
for _, d := range dir {
os.RemoveAll(path.Join([]string{basePath, d.Name()}...))
}
return nil
}