Implement repo:gc and repo:purge-cache

These are helper plugins that mimic the repo plugin: https://github.com/heroku/heroku-repo

The following commands will remain unimplemented:

- `clone`: not useful for the host client to clone
- `download`: currently not possible for us to "host" a tarball of the repo
- `reset`: we still store files in the repo (though we shouldn't) so we cannot easily reinitialize the repository.

Also fixes a potential race condition if two separate processes create an application's `$CACHE_DIR`.

Closes #1570
This commit is contained in:
Jose Diaz-Gonzalez
2016-03-30 02:38:29 -04:00
committed by Michael Hobbs
parent 0c58aeaa52
commit 2c1f32199a
5 changed files with 71 additions and 1 deletions

15
plugins/repo/subcommands/gc Executable file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
repo_gc() {
declare desc="runs 'git gc --agressive' against the application's repo"
local cmd="repo:gc"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
local APP="$2"; local APP_DIR="$DOKKU_ROOT/$APP"
verify_app_name "$APP"
GIT_DIR="$APP_DIR" git gc --aggressive
}
repo_gc "$@"

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
repo_purge_cache() {
declare desc="deletes the contents of the build cache stored in the repository"
local cmd="repo:purge-cache"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
local APP="$2";
verify_app_name "$APP"
local IMAGE=$(get_app_image_name "$APP"); local CACHE_DIR="$DOKKU_ROOT/$APP/cache"
if [[ -d $CACHE_DIR ]]; then
docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$CACHE_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true
mkdir -p "$CACHE_DIR" || true
fi
}
repo_purge_cache "$@"