2019-07-05 16:12:22 -04:00
|
|
|
package repo
|
|
|
|
|
|
|
|
|
|
import (
|
2019-06-29 15:33:24 -04:00
|
|
|
"fmt"
|
2019-07-05 16:12:22 -04:00
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
|
|
|
"github.com/dokku/dokku/plugins/config"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// PurgeCache deletes the contents of the build cache stored in the repository
|
|
|
|
|
func PurgeCache(appName string) error {
|
2020-11-01 15:51:41 -05:00
|
|
|
cacheDir := strings.Join([]string{common.AppRoot(appName), "cache"}, "/")
|
|
|
|
|
cacheHostDir := strings.Join([]string{common.AppHostRoot(appName), "cache"}, "/")
|
2019-07-05 16:12:22 -04:00
|
|
|
dokkuGlobalRunArgs := common.MustGetEnv("DOKKU_GLOBAL_RUN_ARGS")
|
|
|
|
|
image := config.GetWithDefault(appName, "DOKKU_IMAGE", os.Getenv("DOKKU_IMAGE"))
|
|
|
|
|
if info, _ := os.Stat(cacheDir); info != nil && info.IsDir() {
|
2019-07-19 15:50:55 -04:00
|
|
|
dockerLabelArgs := fmt.Sprintf("--label=com.dokku.app-name=%s", appName)
|
2019-07-05 16:12:22 -04:00
|
|
|
purgeCacheCmd := common.NewShellCmd(strings.Join([]string{
|
|
|
|
|
common.DockerBin(),
|
2019-05-29 04:05:24 -04:00
|
|
|
"container",
|
|
|
|
|
"run", "--rm", dockerLabelArgs, dokkuGlobalRunArgs,
|
2019-07-05 16:12:22 -04:00
|
|
|
"-v", strings.Join([]string{cacheHostDir, ":/cache"}, ""), image,
|
|
|
|
|
`find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} ;`}, " "))
|
|
|
|
|
purgeCacheCmd.Execute()
|
|
|
|
|
err := os.MkdirAll(cacheDir, 0644)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|