From f37474a68c18438891e482829a7dcc826652405c Mon Sep 17 00:00:00 2001 From: Joey Hafner Date: Tue, 10 Oct 2023 15:52:02 -0700 Subject: [PATCH] Iterate on docker-stacks --- fighter/scripts/docker-stacks.sh | 73 +++++++------------------------- 1 file changed, 15 insertions(+), 58 deletions(-) diff --git a/fighter/scripts/docker-stacks.sh b/fighter/scripts/docker-stacks.sh index 432dca7..0619345 100644 --- a/fighter/scripts/docker-stacks.sh +++ b/fighter/scripts/docker-stacks.sh @@ -1,65 +1,25 @@ -# takes a docker-compose.yml file path and returns a boolean to represent -# whether that stack depends on an smb share under the `/mnt/nas` path -function check_nas { - if [ docker-compose config | grep -q /mnt/nas ]; then - docker-compose config | grep -q /mnt/nas # this returns 0 if `/mnt/nas` is present in the config - MATCH=$? - if [ $MATCH == 0]; then - return true - fi -} - -# takes a docker-compose.yml file path and returns a boolean to represent -# whether that stack passes a docker-compose config lint -function lint { - docker-compose config > /dev/null 2>&1 - return $? -} - -function compose_config { - docker-compose config -} - -# takes a docker-compose.yml file path and shuts it down -function compose_down { - docker-compose down -} - -# takes a docker-compose.yml file path and brings it up -function compose_up { - if [ "$FORCERECREATE" = true ]; then - docker-compose up --force-recreate -d - elif [ "$FORCERECREATE" = false ]; then - docker-compose up -d - else - echo "Bad variable value: \$FORCERECREATE=$FORCERECREATE" - fi -} - function main { - #echo "\$ARGS is $ARGS" STACKS_DIRECTORY="/home/admin/homelab/fighter/config" while [[ $# -gt 0 ]]; do - #echo "case is $1" case $1 in - # global flags are parsed first + # parse global flags -n|--nas-only) NAS_ONLY=true; shift ;; -l|--lint) LINT=true; shift ;; -p|--path) STACKS_DIRECTORY="$2"; shift; shift ;; -v|--verbose) VERBOSE=true; shift ;; - # commands are parsed with nested parsing for subcommand flags - up*) COMMAND="up"; shift; + # parse command + up*) COMMAND="docker-compose up -d"; shift; while [[ $# -gt 0 ]]; do case $1 in - -f|--force-recreate) FORCE_RECREATE=true; shift;; + -f|--force-recreate) COMMAND="$COMMAND --force-recreate"; shift;; *) echo "Unrecognized option '$1' for '$COMMAND'"; exit 1;; esac done ;; - down*) COMMAND="down"; shift; + down*) COMMAND="docker-compose down"; shift; while [[ $# -gt 0 ]]; do case $1 in - -o|--remove-orphans) REMOVE_ORPHANS=true; shift;; + -o|--remove-orphans) COMMAND="$COMMAND --remove-orphans"; shift;; *) echo "Unrecognized option '$1' for '$COMMAND'"; exit 1;; esac done @@ -67,7 +27,7 @@ function main { config*) COMMAND="config"; shift; while [[ $# -gt 0 ]]; do case $1 in - -n|--no-interpolate) NO_INTERPOLATE=true; shift;; + -n|--no-interpolate) COMMAND="$COMMAND --no-interpolate"; shift;; *) echo "Unrecognized option '$1' for '$COMMAND'"; exit 1;; esac done @@ -81,23 +41,20 @@ function main { if [ $NAS_ONLY ] || [ $LINT ]; then TMP=$(docker-compose config) PASS=$? + if [ $PASS != 0 ]; then + echo "ERROR: $stack failed to lint" + continue + fi if [ $NAS_ONLY ]; then echo $TMP | grep -q /mnt/nas NAS_DEPENDENT=$? - if [ $NAS_DEPENDENT ]; then - echo "\$NAS_DEPENDENT is $NAS_DEPENDENT for $stack" + if [ $NAS_DEPENDENT == 1 ]; then + continue fi fi fi - case $COMMAND in - up) echo "$COMMAND at $PWD" - ;; - down) echo "$COMMAND at $PWD" - ;; - config) echo "$COMMAND at $PWD" - ;; - *) echo "Unrecognized command '$COMMAND'" ;; - esac + + echo "${PWD} $COMMAND" done }