Add core storage plugin to manage docker bind mounts [ci skip]

This commit is contained in:
Justin Clark
2016-01-13 12:00:28 -08:00
parent 8c01fa8480
commit 84df69b387
7 changed files with 163 additions and 0 deletions

50
plugins/storage/commands Executable file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
[[ " storage storage:list storage:mount storage:unmount storage:help help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/storage/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/docker-options/functions"
case "$1" in
storage:list)
# List all bound mounts
passed_phases="deploy"
[[ ! $2 ]] && dokku_log_fail "storage:list requires an app to list."
verify_app_name "$2" && APP="$2"
echo "$APP volume bind-mounts:"
get_bind_mounts "$(get_phase_file_path "$passed_phases")"
;;
storage:mount)
# Add bind-mount, redeploy app if running
passed_phases=(deploy run)
[[ -z $3 || $4 ]] && dokku_log_fail "storage:mount requires an app and a two paths devided by colon."
verify_app_name "$2" && APP="$2"
verify_paths "$3" && MOUNT_PATH="$3"
check_if_path_exists "$MOUNT_PATH" "$(get_phase_file_path "${passed_phases[@]}")" && dokku_log_fail "Mount path already exists."
add_passed_docker_option passed_phases[@] "-v $MOUNT_PATH"
;;
storage:unmount)
# Remove bind-mount, restart app if running
passed_phases=(deploy run)
[[ -z $3 || $4 ]] && dokku_log_fail "storage:unmount requires an app and a two paths devided by colon."
verify_app_name "$2" && APP="$2"
verify_paths "$3" && MOUNT_PATH="$3"
check_if_path_exists "$MOUNT_PATH" "$(get_phase_file_path "${passed_phases[@]}")" || dokku_log_fail "Mount path does not exist."
remove_passed_docker_option passed_phases[@] "-v $MOUNT_PATH"
;;
help | storage:help)
cat<<EOF
storage:list <app>, List bind mounts for app's container(s) (host:container)
storage:mount <app> <host-dir:container-dir>, Create a new bind mount
storage:unmount <app> <host-dir:container-dir>, Remove an existing bind mount
EOF
;;
*)
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
;;
esac

18
plugins/storage/functions Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
verify_paths() {
echo "$1" | grep -qe '^/.*\:/' || dokku_log_fail "Storage path must be two valid paths devided by colon."
}
check_if_path_exists() {
local -r passed_path=$1
local -r phase_file_path=$2
[[ -r "$phase_file_path" ]] && grep -qe "^-v $passed_path" "$phase_file_path"
}
get_bind_mounts() {
local -r phase_file_path=$1
[[ -r "$phase_file_path" ]] && sed -e '/^-v/!d' -e 's/^-v/ /' < "$phase_file_path"
}

5
plugins/storage/install Normal file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
mkdir -p /var/lib/dokku/data/storage
chown dokku:dokku /var/lib/dokku/data/storage

View File

@@ -0,0 +1,4 @@
[plugin]
description = "dokku core storage plugin"
version = "0.5.0"
[plugin.config]