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:
1 parent
0c58aeaa52
commit
2c1f32199a
5 files changed
+71
-1
No files matched your search
@@ -19,7 +19,7 @@ dokku_build_cmd() {
|
|||||||
local id=$(tar -c . | docker run "$DOKKU_GLOBAL_RUN_ARGS" -i -a stdin "$DOKKU_IMAGE" /bin/bash -c "mkdir -p /app && tar -xC /app")
|
local id=$(tar -c . | docker run "$DOKKU_GLOBAL_RUN_ARGS" -i -a stdin "$DOKKU_IMAGE" /bin/bash -c "mkdir -p /app && tar -xC /app")
|
||||||
test "$(docker wait "$id")" -eq 0
|
test "$(docker wait "$id")" -eq 0
|
||||||
docker commit "$id" "$IMAGE" > /dev/null
|
docker commit "$id" "$IMAGE" > /dev/null
|
||||||
[[ -d $CACHE_DIR ]] || mkdir "$CACHE_DIR"
|
[[ -d $CACHE_DIR ]] || mkdir -p "$CACHE_DIR"
|
||||||
plugn trigger pre-build-buildpack "$APP"
|
plugn trigger pre-build-buildpack "$APP"
|
||||||
|
|
||||||
local DOCKER_ARGS=$(: | plugn trigger docker-args-build "$APP" "$IMAGE_SOURCE_TYPE")
|
local DOCKER_ARGS=$(: | plugn trigger docker-args-build "$APP" "$IMAGE_SOURCE_TYPE")
|
||||||
|
|||||||
Executable
+31
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
[[ " help repo:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
|
||||||
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
help | repo:help)
|
||||||
|
help_content_func () {
|
||||||
|
declare desc="return repo plugin help content"
|
||||||
|
cat<<help_content
|
||||||
|
repo:gc <app>, Runs 'git gc --agressive' against the application's repo
|
||||||
|
repo:purge-cache <app>, Deletes the contents of the build cache stored in the repository
|
||||||
|
help_content
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $1 = "repo:help" ]] ; then
|
||||||
|
echo -e 'Usage: dokku repo[:COMMAND]'
|
||||||
|
echo ''
|
||||||
|
echo "Runs commands that interact with the app's repo"
|
||||||
|
echo ''
|
||||||
|
echo 'Additional commands:'
|
||||||
|
help_content_func | sort | column -c2 -t -s,
|
||||||
|
else
|
||||||
|
help_content_func
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
[plugin]
|
||||||
|
description = "dokku core repo plugin"
|
||||||
|
version = "0.5.3"
|
||||||
|
[plugin.config]
|
||||||
Executable
+15
@@ -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 "$@"
|
||||||
Executable
+20
@@ -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 "$@"
|
||||||
Reference in new issue
Block a user