From 1cc718832ae02f267aa99c2ac53598d0c912c4e0 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 24 Oct 2024 00:50:24 +0200 Subject: [PATCH] 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. --- src/octojoom | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/octojoom b/src/octojoom index f64516a..5b18f31 100755 --- a/src/octojoom +++ b/src/octojoom @@ -1959,7 +1959,20 @@ function joomla__TRuST__down() { "Take Down Containers" 8 112; then # get all zip files for yml in "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"*/*.yml; do - docker-compose --file "${yml}" down + # 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 + } done fi } @@ -1974,7 +1987,20 @@ function openssh__TRuST__down() { "Take Down Containers" 8 112; then # get all zip files for yml in "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"*/*.yml; do - docker-compose --file "${yml}" down + # 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 + } done fi }