Merge pull request #12821 from trikimiki/fix-chown-for-docker-desktop

Docker Compose: rewrite host volume related scripts, add option to skip chown
This commit is contained in:
Andrew Shvayka 2025-03-12 12:33:16 +02:00 committed by GitHub
commit 1658660715
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 71 additions and 23 deletions

View File

@ -143,7 +143,6 @@ function additionalComposeEdqsArgs() {
function permissionList() {
PERMISSION_LIST="
799 799 tb-node/log
799 799 tb-transports/coap/log
799 799 tb-transports/lwm2m/log
799 799 tb-transports/http/log
799 799 tb-transports/mqtt/log
@ -200,29 +199,77 @@ function permissionList() {
}
function checkFolders() {
CREATE=false
SKIP_CHOWN=false
for i in "$@"
do
case $i in
--create)
CREATE=true
shift
;;
--skipChown)
SKIP_CHOWN=true
shift
;;
*)
# unknown option
;;
esac
done
EXIT_CODE=0
PERMISSION_LIST=$(permissionList) || exit $?
set -e
while read -r USR GRP DIR
do
if [ -z "$DIR" ]; then # skip empty lines
IS_EXIST_CHECK_PASSED=false
IS_OWNER_CHECK_PASSED=false
# skip empty lines
if [ -z "$DIR" ]; then
continue
fi
MESSAGE="Checking user ${USR} group ${GRP} dir ${DIR}"
if [[ -d "$DIR" ]] &&
[[ $(ls -ldn "$DIR" | awk '{print $3}') -eq "$USR" ]] &&
[[ $(ls -ldn "$DIR" | awk '{print $4}') -eq "$GRP" ]]
then
MESSAGE="$MESSAGE OK"
# checks section
echo "Checking if dir ${DIR} exists..."
if [[ -d "$DIR" ]]; then
echo "> OK"
IS_EXIST_CHECK_PASSED=true
if [ "$SKIP_CHOWN" = false ]; then
echo "Checking user ${USR} group ${GRP} ownership for dir ${DIR}..."
if [[ $(ls -ldn "$DIR" | awk '{print $3}') -eq "$USR" ]] && [[ $(ls -ldn "$DIR" | awk '{print $4}') -eq "$GRP" ]]; then
echo "> OK"
IS_OWNER_CHECK_PASSED=true
else
echo "...ownership check failed"
if [ "$CREATE" = false ]; then
EXIT_CODE=1
fi
fi
fi
else
if [ "$1" = "--create" ]; then
echo "Create and chown: user ${USR} group ${GRP} dir ${DIR}"
mkdir -p "$DIR" && sudo chown -R "$USR":"$GRP" "$DIR"
else
echo "$MESSAGE FAILED"
echo "...does not exist"
if [ "$CREATE" = false ]; then
EXIT_CODE=1
fi
fi
# create/chown section
if [ "$CREATE" = true ]; then
if [ "$IS_EXIST_CHECK_PASSED" = false ]; then
echo "...will create dir ${DIR}"
if [ "$SKIP_CHOWN" = false ]; then
echo "...will change ownership to user ${USR} group ${GRP} for dir ${DIR}"
mkdir -p "$DIR" && sudo chown -R "$USR":"$GRP" "$DIR" && echo "> OK"
else
mkdir -p "$DIR" && echo "> OK"
fi
elif [ "$IS_OWNER_CHECK_PASSED" = false ] && [ "$SKIP_CHOWN" = false ]; then
echo "...will change ownership to user ${USR} group ${GRP} for dir ${DIR}"
sudo chown -R "$USR":"$GRP" "$DIR" && echo "> OK"
fi
fi
done < <(echo "$PERMISSION_LIST")
return $EXIT_CODE
}

View File

@ -17,5 +17,12 @@
set -e
source compose-utils.sh
checkFolders || exit $?
echo "OK"
if checkFolders "$@" ; then
echo "------"
echo "All checks have passed"
else
CHECK_EXIT_CODE=$?
echo "------"
echo "Some checks did not pass - check the output"
exit $CHECK_EXIT_CODE
fi

View File

@ -20,7 +20,7 @@ version: '3.0'
services:
zookeeper:
restart: always
image: "zookeeper:3.8.0"
image: "zookeeper:3.8.1"
ports:
- "2181"
environment:

View File

@ -17,4 +17,4 @@
set -e
source compose-utils.sh
checkFolders --create
checkFolders --create "$@"

View File

@ -53,8 +53,6 @@ ADDITIONAL_COMPOSE_EDQS_ARGS=$(additionalComposeEdqsArgs) || exit $?
ADDITIONAL_STARTUP_SERVICES=$(additionalStartupServices) || exit $?
checkFolders --create || exit $?
if [ ! -z "${ADDITIONAL_STARTUP_SERVICES// }" ]; then
COMPOSE_ARGS="\

View File

@ -31,8 +31,6 @@ ADDITIONAL_COMPOSE_MONITORING_ARGS=$(additionalComposeMonitoringArgs) || exit $?
ADDITIONAL_COMPOSE_EDQS_ARGS=$(additionalComposeEdqsArgs) || exit $?
checkFolders --create || exit $?
COMPOSE_ARGS="\
-f docker-compose.yml ${ADDITIONAL_CACHE_ARGS} ${ADDITIONAL_COMPOSE_ARGS} ${ADDITIONAL_COMPOSE_QUEUE_ARGS} ${ADDITIONAL_COMPOSE_MONITORING_ARGS} ${ADDITIONAL_COMPOSE_EDQS_ARGS} \
up -d"

View File

@ -46,8 +46,6 @@ ADDITIONAL_COMPOSE_EDQS_ARGS=$(additionalComposeEdqsArgs) || exit $?
ADDITIONAL_STARTUP_SERVICES=$(additionalStartupServices) || exit $?
checkFolders --create || exit $?
COMPOSE_ARGS_PULL="\
-f docker-compose.yml ${ADDITIONAL_CACHE_ARGS} ${ADDITIONAL_COMPOSE_ARGS} ${ADDITIONAL_COMPOSE_QUEUE_ARGS}
${ADDITIONAL_COMPOSE_EDQS_ARGS} \