feat: add storage directory mode and removal flags
`storage:create` and `storage:set` accept a `--mode` flag that sets the octal permissions of a docker-local host directory, and `storage:destroy` accepts a `--destroy-host-dir` flag that removes the directory along with its contents. A docker-local entry also honors `--reclaim-policy Delete` at destroy time now, matching how that policy governs a k3s PersistentVolume. Both are limited to the default `/var/lib/dokku/data/storage/<name>` location, the same restriction `--chown` already carries. `storage:set` applies `--chown` and `--mode` to the directory rather than only recording them.
This commit is contained in:
27
plugins/storage/bin/chmod-storage-dir
Executable file
27
plugins/storage/bin/chmod-storage-dir
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
main() {
|
||||
declare desc="chmods a storage directory"
|
||||
declare DIRECTORY="$1" MODE="$2"
|
||||
|
||||
if [[ -z "$DIRECTORY" ]]; then
|
||||
echo " ! Please specify a directory to chmod" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! "$DIRECTORY" =~ ^[A-Za-z0-9\\_-]+$ ]]; then
|
||||
echo " ! Directory can only contain the following set of characters: [A-Za-z0-9_-]" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! "$MODE" =~ ^[0-7]{3,4}$ ]]; then
|
||||
echo " ! Unsupported directory mode. Value must be a 3 or 4 digit octal mode, such as 0755" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
chmod "$MODE" "${DOKKU_LIB_ROOT}/data/storage/$DIRECTORY"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
33
plugins/storage/bin/destroy-storage-dir
Executable file
33
plugins/storage/bin/destroy-storage-dir
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
main() {
|
||||
declare desc="removes a storage directory and its contents"
|
||||
declare DIRECTORY="$1"
|
||||
|
||||
if [[ -z "$DIRECTORY" ]]; then
|
||||
echo " ! Please specify a directory to destroy" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! "$DIRECTORY" =~ ^[A-Za-z0-9\\_-]+$ ]]; then
|
||||
echo " ! Directory can only contain the following set of characters: [A-Za-z0-9_-]" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local storage_path="${DOKKU_LIB_ROOT}/data/storage/$DIRECTORY"
|
||||
|
||||
if [[ ! -e "$storage_path" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -d "$storage_path" ]]; then
|
||||
echo " ! $storage_path exists but is not a directory" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf "$storage_path"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user