Merge pull request #3153 from plotly/separate-data-root-for-docker-binds
Allow specifying a separate DOKKU_HOST_ROOT
This commit is contained in:
8 files changed
+39
-8
No files matched your search
@@ -27,6 +27,7 @@ if [[ -d $DOKKU_ROOT/.dokkurc ]]; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
export DOKKU_HOST_ROOT=${DOKKU_HOST_ROOT:=$DOKKU_ROOT}
|
||||||
|
|
||||||
export DOKKU_DISTRO
|
export DOKKU_DISTRO
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ execute_script() {
|
|||||||
COMMAND+=" fi "
|
COMMAND+=" fi "
|
||||||
|
|
||||||
local CACHE_DIR="$DOKKU_ROOT/$APP/cache"
|
local CACHE_DIR="$DOKKU_ROOT/$APP/cache"
|
||||||
|
local CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$APP/cache"
|
||||||
[[ -d $CACHE_DIR ]] || mkdir -p "$CACHE_DIR"
|
[[ -d $CACHE_DIR ]] || mkdir -p "$CACHE_DIR"
|
||||||
|
|
||||||
local DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG")
|
local DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG")
|
||||||
@@ -66,7 +67,7 @@ execute_script() {
|
|||||||
DOKKU_APP_SHELL="$(config_get "$APP" DOKKU_APP_SHELL || echo "$DOKKU_APP_SHELL")"
|
DOKKU_APP_SHELL="$(config_get "$APP" DOKKU_APP_SHELL || echo "$DOKKU_APP_SHELL")"
|
||||||
[[ -z "$DOKKU_APP_SHELL" ]] && DOKKU_APP_SHELL="/bin/bash"
|
[[ -z "$DOKKU_APP_SHELL" ]] && DOKKU_APP_SHELL="/bin/bash"
|
||||||
|
|
||||||
id=$(docker run "$DOKKU_GLOBAL_RUN_ARGS" -e DOKKU_TRACE="$DOKKU_TRACE" --label=dokku_phase_script="${PHASE_SCRIPT_KEY}" -d -v "$CACHE_DIR:/cache" "${ARG_ARRAY[@]}" "$IMAGE" "$DOKKU_APP_SHELL" -c "$COMMAND")
|
id=$(docker run "$DOKKU_GLOBAL_RUN_ARGS" -e DOKKU_TRACE="$DOKKU_TRACE" --label=dokku_phase_script="${PHASE_SCRIPT_KEY}" -d -v "$CACHE_HOST_DIR:/cache" "${ARG_ARRAY[@]}" "$IMAGE" "$DOKKU_APP_SHELL" -c "$COMMAND")
|
||||||
if test "$(docker wait "$id")" -eq 0; then
|
if test "$(docker wait "$id")" -eq 0; then
|
||||||
dokku_container_log_verbose_quiet "$id"
|
dokku_container_log_verbose_quiet "$id"
|
||||||
if [[ "$PHASE_SCRIPT_KEY" != "postdeploy" ]];then
|
if [[ "$PHASE_SCRIPT_KEY" != "postdeploy" ]];then
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|||||||
apps_pre_delete() {
|
apps_pre_delete() {
|
||||||
declare desc="apps pre-delete plugin trigger"
|
declare desc="apps pre-delete plugin trigger"
|
||||||
local trigger="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 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"
|
verify_app_name "$APP"
|
||||||
|
|
||||||
if ! is_image_herokuish_based "$IMAGE"; then
|
if ! is_image_herokuish_based "$IMAGE"; then
|
||||||
@@ -13,7 +13,7 @@ apps_pre_delete() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -d $CACHE_DIR ]]; then
|
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
|
docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$CACHE_HOST_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ apps_clone_cmd() {
|
|||||||
[[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
[[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||||
[[ -d "$DOKKU_ROOT/$NEW_APP" ]] && dokku_log_fail "Name is already taken"
|
[[ -d "$DOKKU_ROOT/$NEW_APP" ]] && dokku_log_fail "Name is already taken"
|
||||||
local NEW_CACHE_DIR="$DOKKU_ROOT/$NEW_APP/cache"
|
local NEW_CACHE_DIR="$DOKKU_ROOT/$NEW_APP/cache"
|
||||||
|
local NEW_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$NEW_APP/cache"
|
||||||
|
|
||||||
apps_create "$NEW_APP"
|
apps_create "$NEW_APP"
|
||||||
pushd "$DOKKU_ROOT/$OLD_APP/." > /dev/null
|
pushd "$DOKKU_ROOT/$OLD_APP/." > /dev/null
|
||||||
@@ -26,7 +27,7 @@ apps_clone_cmd() {
|
|||||||
popd > /dev/null 2>&1 || pushd "/tmp" > /dev/null
|
popd > /dev/null 2>&1 || pushd "/tmp" > /dev/null
|
||||||
|
|
||||||
if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then
|
if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then
|
||||||
docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$NEW_CACHE_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$NEW_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
||||||
fi
|
fi
|
||||||
rm -rf "$NEW_CACHE_DIR"
|
rm -rf "$NEW_CACHE_DIR"
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ apps_rename_cmd() {
|
|||||||
local OLD_APP="$2"
|
local OLD_APP="$2"
|
||||||
local NEW_APP="$3"
|
local NEW_APP="$3"
|
||||||
local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache"
|
local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache"
|
||||||
|
local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache"
|
||||||
|
|
||||||
if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR"; then
|
if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR"; then
|
||||||
docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$OLD_CACHE_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
||||||
fi
|
fi
|
||||||
rm -rf "$OLD_CACHE_DIR"
|
rm -rf "$OLD_CACHE_DIR"
|
||||||
apps_create "$NEW_APP"
|
apps_create "$NEW_APP"
|
||||||
|
|||||||
@@ -447,6 +447,7 @@ dokku_build() {
|
|||||||
verify_app_name "$APP"
|
verify_app_name "$APP"
|
||||||
|
|
||||||
local DOKKU_APP_CACHE_DIR="$DOKKU_ROOT/$APP/cache"
|
local DOKKU_APP_CACHE_DIR="$DOKKU_ROOT/$APP/cache"
|
||||||
|
local DOKKU_APP_HOST_CACHE_DIR="$DOKKU_HOST_ROOT/$APP/cache"
|
||||||
|
|
||||||
eval "$(config_export app "$APP")"
|
eval "$(config_export app "$APP")"
|
||||||
pushd "$TMP_WORK_DIR" &> /dev/null
|
pushd "$TMP_WORK_DIR" &> /dev/null
|
||||||
@@ -465,7 +466,7 @@ dokku_build() {
|
|||||||
declare -a ARG_ARRAY
|
declare -a ARG_ARRAY
|
||||||
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
cid=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d -v $DOKKU_APP_CACHE_DIR:/cache -e CACHE_PATH=/cache "${ARG_ARRAY[@]}" $IMAGE /build)
|
cid=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d -v $DOKKU_APP_HOST_CACHE_DIR:/cache -e CACHE_PATH=/cache "${ARG_ARRAY[@]}" $IMAGE /build)
|
||||||
docker attach "$cid"
|
docker attach "$cid"
|
||||||
test "$(docker wait "$cid")" -eq 0
|
test "$(docker wait "$cid")" -eq 0
|
||||||
docker commit "$cid" "$IMAGE" > /dev/null
|
docker commit "$cid" "$IMAGE" > /dev/null
|
||||||
@@ -959,4 +960,4 @@ suppress_output() {
|
|||||||
return "$exit_code"
|
return "$exit_code"
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -21,11 +21,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cacheDir := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName, "cache"}, "/")
|
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")
|
dokkuGlobalRunArgs := common.MustGetEnv("DOKKU_GLOBAL_RUN_ARGS")
|
||||||
image := common.GetDeployingAppImageName(appName, "", "")
|
image := common.GetDeployingAppImageName(appName, "", "")
|
||||||
if info, _ := os.Stat(cacheDir); info != nil && info.IsDir() {
|
if info, _ := os.Stat(cacheDir); info != nil && info.IsDir() {
|
||||||
purgeCacheCmd := common.NewShellCmd(strings.Join([]string{"docker run --rm", dokkuGlobalRunArgs,
|
purgeCacheCmd := common.NewShellCmd(strings.Join([]string{"docker run --rm", dokkuGlobalRunArgs,
|
||||||
"-v", strings.Join([]string{cacheDir, ":/cache"}, ""), image,
|
"-v", strings.Join([]string{cacheHostDir, ":/cache"}, ""), image,
|
||||||
`find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} ;`}, " "))
|
`find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} ;`}, " "))
|
||||||
purgeCacheCmd.Execute()
|
purgeCacheCmd.Execute()
|
||||||
err := os.MkdirAll(cacheDir, 0644)
|
err := os.MkdirAll(cacheDir, 0644)
|
||||||
|
|||||||
@@ -70,3 +70,28 @@ teardown() {
|
|||||||
echo "status: "$status
|
echo "status: "$status
|
||||||
assert_output "herokuish"
|
assert_output "herokuish"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "(build-env) DOKKU_ROOT cache bind is used by default" {
|
||||||
|
deploy_app
|
||||||
|
|
||||||
|
BUILD_CID=$(docker ps -a |grep $TEST_APP |grep /bin/bash | awk '{print $1}')
|
||||||
|
run /bin/bash -c "docker inspect --format '{{ .HostConfig.Binds }}' $BUILD_CID | tr -d '[]' | cut -f1 -d:"
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_output "$DOKKU_ROOT/$TEST_APP/cache"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "(build-env) DOKKU_HOST_ROOT cache bind is used if set" {
|
||||||
|
TMP_ROOT=$(mktemp -d)
|
||||||
|
mkdir -p $DOKKU_ROOT/.dokkurc
|
||||||
|
echo export DOKKU_HOST_ROOT="$TMP_ROOT" > $DOKKU_ROOT/.dokkurc/HOST_ROOT
|
||||||
|
DOKKU_HOST_ROOT="$TMP_ROOT" deploy_app
|
||||||
|
|
||||||
|
BUILD_CID=$(docker ps -a |grep $TEST_APP |grep /bin/bash | awk '{print $1}')
|
||||||
|
run /bin/bash -c "docker inspect --format '{{ .HostConfig.Binds }}' $BUILD_CID | tr -d '[]' | cut -f1 -d:"
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_output "$TMP_ROOT/$TEST_APP/cache"
|
||||||
|
|
||||||
|
rm -rf $TMP_ROOT $DOKKU_ROOT/.dokkurc/HOST_ROOT
|
||||||
|
}
|
||||||
Reference in new issue
Block a user