mirror of
https://github.com/dokku/dokku.git
synced 2025-12-16 03:57:43 +01:00
The ls command is what is referenced in the --help output for the subcommands, so we should just use that everywhere.
74 lines
1.4 KiB
Go
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
|
|
}
|