Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve down.sh script #2778

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions docker/down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -12,16 +12,29 @@ 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
project_root=$(git rev-parse --show-toplevel)
cd "${project_root}/"

compose_files="-f docker-compose.yml"

# Default args
compose_args="--remove-orphans"

# Parse args
Expand All @@ -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
12 changes: 6 additions & 6 deletions docker/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -90,7 +90,7 @@ while [ $# -gt 0 ]; do
;;
--args)
shift
ARGS+=" ${1}"
compose_args+=" ${1}"
;;
-b|'--build')
BUILD='true'
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Loading