Making docker scripts more robust

This commit is contained in:
Sahil Ahuja 2025-03-08 03:26:21 +05:30
parent efbb720adf
commit bd24e8ffa0
3 changed files with 7 additions and 5 deletions

View File

@ -4,6 +4,6 @@
set -x
docker compose \
-f fab/d/docker-compose.yaml \
--project-name ${REPO_NAME} \
-p ${REPO_NAME} \
--project-directory ${REPO_FOLDER} \
down

View File

@ -26,9 +26,10 @@ if [ "$ALREADY_RUNNING" -eq 0 ];
then
echo "Service already running, only opening shell"
else
echo "Service not running, starting service"
docker compose \
-f fab/d/docker-compose.yaml \
--project-name ${REPO_NAME} \
-p ${REPO_NAME} \
--project-directory ${REPO_FOLDER} \
up -d
fi
@ -36,6 +37,7 @@ fi
echo "Connecting to docker shell and running command $COMMAND..."
docker compose \
-f fab/d/docker-compose.yaml \
--project-name ${REPO_NAME} \
-p ${REPO_NAME} \
--project-directory ${REPO_FOLDER} \
exec $REPO_NAME $COMMAND

View File

@ -7,7 +7,7 @@
NETWORK_EXISTS=0
#This is necessary instead of using $? (previous command exit code) as we are set -e mode,
#which exists the script on any error
docker network ls | grep ${PARENT_PROJECT} || NETWORK_EXISTS=1
docker network ls | grep " ${PARENT_PROJECT} " || NETWORK_EXISTS=1
#0 if already exists, 1 if doesn't exist (0=no error)
if [ "$NETWORK_EXISTS" -eq 0 ];