github.com/turingchain2020/turingchain@v1.1.21/build/docker-compose-down.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -e
     4  set -o pipefail
     5  #set -o verbose
     6  #set -o xtrace
     7  
     8  export COMPOSE_PROJECT_NAME="$1"
     9  
    10  DAPP=""
    11  if [ -n "${2}" ]; then
    12      DAPP=$2
    13  fi
    14  if [ -n "${DAPP}" ]; then
    15      DAPP_COMPOSE_FILE="docker-compose-${DAPP}.yml"
    16      if [ -e "$DAPP_COMPOSE_FILE" ]; then
    17          export COMPOSE_FILE="docker-compose.yml:${DAPP_COMPOSE_FILE}"
    18      fi
    19  
    20  fi
    21  
    22  echo "=========== # down docker-compose ============="
    23  echo "=========== # env setting ============="
    24  echo "DAPP=$DAPP"
    25  echo "COMPOSE_FILE=$COMPOSE_FILE"
    26  echo "COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME"
    27  
    28  ####################
    29  
    30  function down() {
    31      echo "=========== # docker-compose ps ============="
    32      docker-compose ps
    33      # shellchk not recommend the first way
    34      # remains=( $(docker-compose ps -q | awk '{print $1}') )
    35      mapfile -t remains < <(docker-compose ps -q | awk '{print $1}')
    36      # shellcheck disable=SC2154
    37      num=${#remains[@]}
    38      echo "container num=$num"
    39      if [ "$num" -gt 0 ]; then
    40          # remove exsit container
    41          echo "=========== # docker-compose down ============="
    42          docker-compose down --rmi local
    43      fi
    44  
    45  }
    46  
    47  # run script
    48  down