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.
This commit is contained in:
Jose Diaz-Gonzalez
2019-07-05 16:07:13 -04:00
parent 39f3f598a5
commit 33423a0508
2 changed files with 4 additions and 7 deletions

View File

@@ -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
}

View File

@@ -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(),