refactor: use only a single implementation for cache purging
This change moves cache clearing into the repo plugin, and standardizes on a single way of clearing the cache.
This commit is contained in:
@@ -2,11 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
"github.com/dokku/dokku/plugins/repo"
|
||||
)
|
||||
|
||||
// deletes the contents of the build cache stored in the repository
|
||||
@@ -16,25 +14,9 @@ func main() {
|
||||
if appName == "" {
|
||||
common.LogFail("Please specify an app to run the command on")
|
||||
}
|
||||
err := common.VerifyAppName(appName)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
cacheDir := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName, "cache"}, "/")
|
||||
cacheHostDir := strings.Join([]string{common.MustGetEnv("DOKKU_HOST_ROOT"), appName, "cache"}, "/")
|
||||
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() {
|
||||
purgeCacheCmd := common.NewShellCmd(strings.Join([]string{
|
||||
common.DockerBin(),
|
||||
"run --rm", dokkuGlobalRunArgs,
|
||||
"-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 {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
err := repo.PurgeCache(appName)
|
||||
if err != nil {
|
||||
common.LogWarn(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
19
plugins/repo/src/triggers/pre-delete/pre-delete.go
Normal file
19
plugins/repo/src/triggers/pre-delete/pre-delete.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/repo"
|
||||
)
|
||||
|
||||
// destroys the buildpacks property for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
|
||||
err := repo.PurgeCache(appName)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user