mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Merge pull request #3607 from dokku/herokuish-cache-purge
Purge cache using herokuish image
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
apps_pre_delete() {
|
||||
declare desc="apps pre-delete plugin trigger"
|
||||
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
|
||||
fi
|
||||
}
|
||||
|
||||
apps_pre_delete "$@"
|
||||
@@ -3,7 +3,7 @@ include ../../common.mk
|
||||
GO_ARGS ?= -a
|
||||
|
||||
SUBCOMMANDS = subcommands/gc subcommands/purge-cache
|
||||
|
||||
TRIGGERS = triggers/pre-delete
|
||||
build-in-docker: clean
|
||||
docker run --rm \
|
||||
-v $$PWD/../..:$(GO_REPO_ROOT) \
|
||||
@@ -11,7 +11,8 @@ build-in-docker: clean
|
||||
$(BUILD_IMAGE) \
|
||||
bash -c "GO_ARGS='$(GO_ARGS)' make -j4 build" || exit $$?
|
||||
|
||||
build: commands subcommands
|
||||
build: commands subcommands triggers
|
||||
$(MAKE) triggers-copy
|
||||
|
||||
commands: **/**/commands.go
|
||||
go build $(GO_ARGS) -o commands src/commands/commands.go
|
||||
@@ -22,7 +23,15 @@ subcommands/%: src/subcommands/*/%.go
|
||||
go build $(GO_ARGS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -rf commands subcommands
|
||||
rm -rf commands subcommands triggers pre-delete
|
||||
|
||||
src-clean:
|
||||
rm -rf .gitignore src triggers vendor Makefile *.go glide.*
|
||||
|
||||
triggers: $(TRIGGERS)
|
||||
|
||||
triggers/%: src/triggers/*/%.go
|
||||
go build $(GO_ARGS) -o $@ $<
|
||||
|
||||
triggers-copy:
|
||||
cp triggers/* .
|
||||
|
||||
36
plugins/repo/repo.go
Normal file
36
plugins/repo/repo.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"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 {
|
||||
err := common.VerifyAppName(appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -2,10 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/repo"
|
||||
)
|
||||
|
||||
// deletes the contents of the build cache stored in the repository
|
||||
@@ -15,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 := common.GetDeployingAppImageName(appName, "", "")
|
||||
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