Add conditional handling for environment files in docker-compose

Modified the script to conditionally check for the presence of environment files associated with each Docker image before bringing the containers down. This ensures that if an environment file exists, it is used with docker-compose, providing a more flexible and robust container management process.
This commit is contained in:
Llewellyn van der Merwe 2024-10-24 00:50:24 +02:00
parent 7837d8ecd4
commit 1cc718832a
Signed by: Llewellyn
GPG Key ID: A9201372263741E7

View File

@ -1959,7 +1959,20 @@ function joomla__TRuST__down() {
"Take Down Containers" 8 112; then "Take Down Containers" 8 112; then
# get all zip files # get all zip files
for yml in "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"*/*.yml; do for yml in "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"*/*.yml; do
# get the vdm_container value
vdm_container="${yml%/docker-compose.yml}"
# check if image has its own env file also
evn_file=''
# check if image has its own env file also
# shellcheck disable=SC2015
[ -f "${vdm_container}/.env" ] && evn_file="${vdm_container}/.env" || {
[ -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" ] && evn_file="${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
}
# make sure the docker image is started
# shellcheck disable=SC2015
[ ${#evn_file} -ge 1 ] && docker-compose --env-file "${evn_file}" --file "${yml}" down || {
docker-compose --file "${yml}" down docker-compose --file "${yml}" down
}
done done
fi fi
} }
@ -1974,7 +1987,20 @@ function openssh__TRuST__down() {
"Take Down Containers" 8 112; then "Take Down Containers" 8 112; then
# get all zip files # get all zip files
for yml in "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"*/*.yml; do for yml in "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"*/*.yml; do
# get the vdm_container value
vdm_container="${yml%/docker-compose.yml}"
# check if image has its own env file also
evn_file=''
# check if image has its own env file also
# shellcheck disable=SC2015
[ -f "${vdm_container}/.env" ] && evn_file="${vdm_container}/.env" || {
[ -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" ] && evn_file="${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
}
# make sure the docker image is started
# shellcheck disable=SC2015
[ ${#evn_file} -ge 1 ] && docker-compose --env-file "${evn_file}" --file "${yml}" down || {
docker-compose --file "${yml}" down docker-compose --file "${yml}" down
}
done done
fi fi
} }