2021-07-10 00:48:47 -04:00
|
|
|
package builder
|
|
|
|
|
|
|
|
|
|
import (
|
2024-02-13 01:09:24 -05:00
|
|
|
"fmt"
|
2021-07-10 00:48:47 -04:00
|
|
|
"os"
|
|
|
|
|
"path"
|
2023-07-01 03:22:01 -04:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
2021-07-10 00:48:47 -04:00
|
|
|
)
|
|
|
|
|
|
2023-07-01 03:22:01 -04:00
|
|
|
func listImagesByImageRepo(imageRepo string) ([]string, error) {
|
2024-02-13 01:09:24 -05:00
|
|
|
result, err := common.CallExecCommand(common.ExecCommandInput{
|
|
|
|
|
Command: common.DockerBin(),
|
|
|
|
|
Args: []string{"image", "ls", "--quiet", imageRepo},
|
|
|
|
|
})
|
2023-07-01 03:22:01 -04:00
|
|
|
if err != nil {
|
2024-02-13 01:09:24 -05:00
|
|
|
return []string{}, fmt.Errorf("Unable to list images: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if result.ExitCode != 0 {
|
|
|
|
|
return []string{}, fmt.Errorf("Unable to list images: %s", result.StderrContents())
|
2023-07-01 03:22:01 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-13 01:09:24 -05:00
|
|
|
output := strings.Split(result.StdoutContents(), "\n")
|
2023-07-01 03:22:01 -04:00
|
|
|
return output, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 00:48:47 -04:00
|
|
|
func removeAllContents(basePath string) error {
|
2023-12-22 01:59:22 +08:00
|
|
|
dir, err := os.ReadDir(basePath)
|
2021-07-10 00:48:47 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, d := range dir {
|
|
|
|
|
os.RemoveAll(path.Join([]string{basePath, d.Name()}...))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|