Use docker volumes instead of bind mount for app data

This commit is contained in:
Girish Ramakrishnan
2018-09-13 13:55:49 -07:00
parent a0fd60408b
commit a46e208c63
9 changed files with 193 additions and 147 deletions
-32
View File
@@ -1,32 +0,0 @@
#!/bin/bash
set -eu -o pipefail
if [[ ${EUID} -ne 0 ]]; then
echo "This script should be run as root." > /dev/stderr
exit 1
fi
if [[ $# -eq 0 ]]; then
echo "No arguments supplied"
exit 1
fi
if [[ "$1" == "--check" ]]; then
echo "OK"
exit 0
fi
if [[ "${BOX_ENV}" == "cloudron" ]]; then
readonly app_data_dir="${HOME}/appsdata/$1"
mkdir -p "${app_data_dir}/data"
# only the top level ownership is changed because containers own the subdirectores
# and will chown them as necessary
chown yellowtent:yellowtent "${app_data_dir}"
chown yellowtent:yellowtent "${app_data_dir}/data"
else
readonly app_data_dir="${HOME}/.cloudron_test/appsdata/$1"
mkdir -p "${app_data_dir}/data"
chown ${SUDO_USER}:${SUDO_USER} "${app_data_dir}"
fi
@@ -20,18 +20,13 @@ fi
# this script is called from redis addon as well!
appid="$1"
rmdir="$2"
subdir="$2"
if [[ "${BOX_ENV}" == "cloudron" ]]; then
readonly app_data_dir="${HOME}/appsdata/${appid}"
readonly volume_dir="${HOME}/appsdata/${appid}/${subdir}"
else
readonly app_data_dir="${HOME}/.cloudron_test/appsdata/${appid}"
readonly volume_dir="${HOME}/.cloudron_test/appsdata/${appid}/${subdir}"
fi
# the approach below ensures symlinked contents are also deleted
rm -rf "${volume_dir}"
find -H "${app_data_dir}" -mindepth 1 -delete || true # -H means resolve symlink in args
if [[ "${rmdir}" == "true" ]]; then
rm -rf "${app_data_dir}"
fi