Files
dokku/plugins/builder/functions.go
Jose Diaz-Gonzalez 4436bb2023 chore: standardize on ls subcommand when interacting with the docker binary
The ls command is what is referenced in the --help output for the subcommands, so we should just use that everywhere.
2023-08-05 10:58:57 -04:00

74 lines
1.4 KiB
Go

package builder
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
"github.com/dokku/dokku/plugins/common"
)
func listImagesByAppLabel(appName string) ([]string, error) {
command := []string{
common.DockerBin(),
"image",
"ls",
"--quiet",
"--filter",
fmt.Sprintf("label=com.dokku.app-name=%v", appName),
}
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 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
}