From 58234de5f91d6cd33a8826c518a13bb8db62b773 Mon Sep 17 00:00:00 2001 From: Martynov Maxim Date: Thu, 28 Mar 2024 14:47:53 +0300 Subject: [PATCH] Improve down.sh script Signed-off-by: Martynov Maxim --- docker/down.sh | 35 ++++++++++++++++++++--------------- docker/up.sh | 12 ++++++------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/docker/down.sh b/docker/down.sh index e8ee59b4b5..08271c30cd 100755 --- a/docker/down.sh +++ b/docker/down.sh @@ -3,7 +3,7 @@ # Copyright 2018-2023 contributors to the Marquez project # SPDX-License-Identifier: Apache-2.0 # -# Usage: $ ./down.sh +# Usage: $ ./down.sh [FLAGS] set -e @@ -12,9 +12,20 @@ title() { } usage() { - echo "usage: ./$(basename -- ${0})" + echo "usage: ./$(basename -- ${0}) [FLAGS]" echo "A script used to bring down Marquez when run via Docker" echo + title "EXAMPLES:" + echo " # Stop and remove all containers" + echo " $ ./down.sh" + echo + echo " # Stop and remove all containers, remove volumes" + echo " $ ./down.sh -v" + echo + title "FLAGS:" + echo " -v, --volumes remove created volumes" + echo " -h, --help show help for script" + echo } # Change working directory to project root @@ -22,6 +33,8 @@ project_root=$(git rev-parse --show-toplevel) cd "${project_root}/" compose_files="-f docker-compose.yml" + +# Default args compose_args="--remove-orphans" # Parse args @@ -31,22 +44,14 @@ while [ $# -gt 0 ]; do usage exit 0 ;; + -v|'--volumes') + compose_args+=" -v" + ;; esac shift done # We can ignore the tag and port(s) when cleaning up running # containers and volumes -TAG=any - -API_PORT=${RANDOM} -API_ADMIN_PORT=${RANDOM} -WEB_PORT=${RANDOM} -TAG=${RANDOM} - -docker compose $compose_files down $compose_args - -docker volume rm marquez_data && \ - docker volume rm marquez_db-backup && \ - docker volume rm marquez_db-conf && \ - docker volume rm marquez_db-init +API_PORT=${RANDOM} API_ADMIN_PORT=${RANDOM} WEB_PORT=${RANDOM} TAG=${RANDOM} \ + docker compose $compose_files down $compose_args diff --git a/docker/up.sh b/docker/up.sh index cfbe0946c7..8853a7116b 100755 --- a/docker/up.sh +++ b/docker/up.sh @@ -50,7 +50,7 @@ usage() { echo " --no-web don't start the web UI" echo " --no-volumes don't create volumes" echo " -h, --help show help for script" - exit 1 + echo } # Change working directory to project root @@ -68,7 +68,7 @@ NO_WEB="false" NO_VOLUMES="false" TAG="${VERSION}" BUILD="false" -ARGS="-V --force-recreate --remove-orphans" +compose_args="-V --force-recreate --remove-orphans" # Parse args while [ $# -gt 0 ]; do case $1 in @@ -90,7 +90,7 @@ while [ $# -gt 0 ]; do ;; --args) shift - ARGS+=" ${1}" + compose_args+=" ${1}" ;; -b|'--build') BUILD='true' @@ -115,7 +115,7 @@ done # Enable detach mode to run containers in background if [[ "${DETACH}" = "true" ]]; then - ARGS+=" --detach" + compose_args+=" --detach" fi # Enable starting HTTP API server with sample metadata @@ -126,7 +126,7 @@ fi # Enable building from source if [[ "${BUILD}" = "true" ]]; then compose_files+=" -f docker-compose.dev.yml" - ARGS+=" --build" + compose_args+=" --build" fi # Enable web UI @@ -143,4 +143,4 @@ fi # Run docker compose cmd with overrides DOCKER_SCAN_SUGGEST="false" API_PORT=${API_PORT} API_ADMIN_PORT=${API_ADMIN_PORT} WEB_PORT=${WEB_PORT} TAG=${TAG} \ - docker --log-level ERROR compose $compose_files up $ARGS + docker --log-level ERROR compose $compose_files up $compose_args