From 33423a0508ffcdc0ac3cb966c9bd4a7371013d50 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 5 Jul 2019 16:07:13 -0400 Subject: [PATCH] feat: purge cache using herokuish image In some cases, the cache directory may exist but there may be no app image to use for cache purging. This may be the case if the app was never deployed. Instead of failing, we can simply use the configured herokuish image for clearing cache, as that image is the base image for anything that would have modified cache. --- plugins/apps/pre-delete | 8 ++------ plugins/repo/src/subcommands/purge-cache/purge-cache.go | 3 ++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/apps/pre-delete b/plugins/apps/pre-delete index 92a2ae159..24f924071 100755 --- a/plugins/apps/pre-delete +++ b/plugins/apps/pre-delete @@ -8,17 +8,13 @@ apps_pre_delete() { local trigger="apps_pre_delete" local APP="$1" local IMAGE_TAG="$2" - local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") local CACHE_DIR="$DOKKU_ROOT/$APP/cache" local CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$APP/cache" verify_app_name "$APP" - if ! is_image_herokuish_based "$IMAGE"; then - return - fi - if [[ -d $CACHE_DIR ]]; then - "$DOCKER_BIN" run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$CACHE_HOST_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true + DOKKU_IMAGE="$(config_get "$APP" DOKKU_IMAGE || echo "$DOKKU_IMAGE")" + "$DOCKER_BIN" run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$CACHE_HOST_DIR:/cache" "$DOKKU_IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true fi } diff --git a/plugins/repo/src/subcommands/purge-cache/purge-cache.go b/plugins/repo/src/subcommands/purge-cache/purge-cache.go index a1cf19728..2b5732b7e 100644 --- a/plugins/repo/src/subcommands/purge-cache/purge-cache.go +++ b/plugins/repo/src/subcommands/purge-cache/purge-cache.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/dokku/dokku/plugins/common" + "github.com/dokku/dokku/plugins/config" ) // deletes the contents of the build cache stored in the repository @@ -23,7 +24,7 @@ func main() { 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 := common.GetDeployingAppImageName(appName, "", "") + 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(),