Skip to content
Open
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
240 changes: 84 additions & 156 deletions docker/up.sh
Original file line number Diff line number Diff line change
@@ -1,175 +1,103 @@
#!/bin/bash
#
# Copyright 2018-2023 contributors to the Marquez project
# SPDX-License-Identifier: Apache-2.0
#
# Usage: $ ./up.sh [FLAGS] [ARG...]

set -e

# Version of Marquez
readonly VERSION=0.51.1
# Build version of Marquez
readonly BUILD_VERSION=0.51.1

title() {
echo -e "\033[1m${1}\033[0m"
}
#!/usr/bin/env bash

usage() {
echo "usage: ./$(basename -- ${0}) [FLAGS] [ARG...]"
echo "A script used to run Marquez via Docker"
echo
title "EXAMPLES:"
echo " # Build image from source"
echo " $ ./up.sh --build"
echo
echo " # Build image from source, then seed HTTP API server with metadata"
echo " $ ./up.sh --build --seed"
echo
echo " # Use tagged image"
echo " ./up.sh --tag X.Y.X"
echo
echo " # Use tagged image, then seed HTTP API server with metadata"
echo " ./up.sh --tag X.Y.X --seed"
echo
echo " # Set HTTP API server port"
echo " ./up.sh --api-port 9000"
echo
echo " # Set database port"
echo " ./up.sh --db-port 2345"
echo
title "ARGUMENTS:"
echo " -a, --api-port int API port (default: 5000)"
echo " -m, --api-admin-port int API admin port (default: 5001)"
echo " -w, --web-port int web port (default: 3000)"
echo " -p, --db-port int database port (default: 5432)"
echo " -e, --search-port int search port (default: 9200)"
echo " -t, --tag string docker image tag (default: ${VERSION})"
echo " --args string docker arguments"
echo
title "FLAGS:"
echo " -b, --build build images from source"
echo " -s, --seed seed HTTP API server with metadata"
echo " -d, --detach run in the background"
echo " --no-web don't start the web UI"
echo " --no-search don't start search"
echo " --no-volumes don't create volumes"
echo " -h, --help show help for script"
echo
}
# SPDX-License-Identifier: Apache-2.0
# Launch Marquez locally using Docker Compose
# Usage: ./up.sh [FLAGS]

# Change working directory to project root
project_root=$(git rev-parse --show-toplevel)
cd "${project_root}/"
set -euo pipefail

# Base docker compose file
compose_files="-f docker-compose.yml"
# Default versions and ports
VERSION="0.51.1"
TAG="${VERSION}"
BUILD="false"
SEED="false"
DETACH="false"
NO_WEB="false"
NO_SEARCH="false"
NO_VOLUMES="false"

# Default args
API_PORT=5000
API_ADMIN_PORT=5001
WEB_PORT=3000
DB_PORT=5432
SEARCH_PORT=9200
NO_WEB="false"
NO_SEARCH="false"
NO_VOLUMES="false"
TAG="${VERSION}"
BUILD="false"
compose_args="-V --force-recreate --remove-orphans"
# Parse args
while [ $# -gt 0 ]; do
case $1 in
-a|'--api-port')
shift
API_PORT="${1}"
;;
-m|'--api-admin-port')
shift
API_ADMIN_PORT="${1}"
;;
-w|'--web-port')
shift
WEB_PORT="${1}"
;;
-d|'--db-port')
shift
DB_PORT="${1}"
;;
-e|'--search-port')
shift
SEARCH_PORT="${1}"
;;
-t|'--tag')
shift
TAG="${1}"
;;
--args)
shift
compose_args+=" ${1}"
;;
-b|'--build')
BUILD='true'
TAG="${BUILD_VERSION}"
;;
-s|'--seed')
SEED='true'
;;
-d|'--detach') DETACH='true' ;;
--no-web) NO_WEB='true' ;;
--no-search) NO_SEARCH='true' ;;
--no-volumes) NO_VOLUMES='true' ;;
-h|'--help')
usage
exit 0
;;
*) usage
exit 1
;;
esac
shift
done

# Enable detach mode to run containers in background
if [[ "${DETACH}" = "true" ]]; then
compose_args+=" --detach"
fi
COMPOSE_FILES="-f docker-compose.yml"
COMPOSE_ARGS="--remove-orphans"

# Enable starting HTTP API server with sample metadata
if [[ "${SEED}" = "true" ]]; then
compose_files+=" -f docker-compose.seed.yml"
fi
show_usage() {
cat <<EOF
Usage: ./up.sh [FLAGS] [OPTIONS]

# Enable building from source
if [[ "${BUILD}" = "true" ]]; then
compose_files+=" -f docker-compose.dev.yml"
compose_args+=" --build"
fi
Flags:
-b, --build Build Marquez from source
-s, --seed Seed the API with sample metadata
-d, --detach Run services in background
--no-web Disable the web UI
--no-search Disable the search container
--no-volumes Don't create Docker volumes
-h, --help Show this help message

# Enable web UI
if [[ "${NO_WEB}" = "false" ]]; then
compose_files+=" -f docker-compose.web.yml"
# Enable building web UI from source
[[ "${BUILD}" = "true" ]] && compose_files+=" -f docker-compose.web-dev.yml"
fi
Options:
-t, --tag <ver> Use specific image tag (default: ${VERSION})
-a, --api-port <port> API port (default: 5000)
-m, --admin-port <port> API admin port (default: 5001)
-w, --web-port <port> Web UI port (default: 3000)
-p, --db-port <port> DB port (default: 5432)
-e, --search-port <port> Search port (default: 9200)
EOF
}

# Enable search UI
if [[ "${NO_SEARCH}" = "false" ]]; then
compose_files+=" -f docker-compose.search.yml"
fi
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-a|--api-port) shift; API_PORT="$1" ;;
-m|--admin-port) shift; API_ADMIN_PORT="$1" ;;
-w|--web-port) shift; WEB_PORT="$1" ;;
-p|--db-port) shift; DB_PORT="$1" ;;
-e|--search-port) shift; SEARCH_PORT="$1" ;;
-t|--tag) shift; TAG="$1" ;;
-b|--build) BUILD="true"; TAG="dev" ;;
-s|--seed) SEED="true" ;;
-d|--detach) DETACH="true" ;;
--no-web) NO_WEB="true" ;;
--no-search) NO_SEARCH="true" ;;
--no-volumes) NO_VOLUMES="true" ;;
-h|--help) show_usage; exit 0 ;;
*) echo "Unknown option: $1"; show_usage; exit 1 ;;
esac
shift
done

# Create docker volumes for Marquez
if [[ "${NO_VOLUMES}" = "false" ]]; then
./docker/volumes.sh $(basename "$project_root")
# Set project root
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
cd "$PROJECT_ROOT"

# Compose overrides
[[ "$BUILD" == "true" ]] && COMPOSE_FILES+=" -f docker-compose.dev.yml" && COMPOSE_ARGS+=" --build"
[[ "$SEED" == "true" ]] && COMPOSE_FILES+=" -f docker-compose.seed.yml"
[[ "$NO_WEB" == "false" ]] && COMPOSE_FILES+=" -f docker-compose.web.yml"
[[ "$BUILD" == "true" && "$NO_WEB" == "false" ]] && COMPOSE_FILES+=" -f docker-compose.web-dev.yml"
[[ "$NO_SEARCH" == "false" ]] && COMPOSE_FILES+=" -f docker-compose.search.yml"
[[ "$DETACH" == "true" ]] && COMPOSE_ARGS+=" --detach"

# Create volumes if not disabled
if [[ "$NO_VOLUMES" == "false" && -f ./docker/volumes.sh ]]; then
./docker/volumes.sh "$(basename "$PROJECT_ROOT")"
fi

# Enable search in UI an API if search container is enabled
# Toggle search
SEARCH_ENABLED="true"
if [[ "${NO_SEARCH}" = "true" ]]; then
SEARCH_ENABLED="false"
fi
[[ "$NO_SEARCH" == "true" ]] && SEARCH_ENABLED="false"

# Launch
echo -e "\n🚀 Starting Marquez ${TAG}..."

# Run docker compose cmd with overrides
DOCKER_SCAN_SUGGEST="false" API_PORT=${API_PORT} API_ADMIN_PORT=${API_ADMIN_PORT} WEB_PORT=${WEB_PORT} POSTGRES_PORT=${DB_PORT} SEARCH_ENABLED=${SEARCH_ENABLED} SEARCH_PORT=${SEARCH_PORT} TAG=${TAG} \
docker --log-level ERROR compose $compose_files up $compose_args
export API_PORT=${API_PORT}
export API_ADMIN_PORT=${API_ADMIN_PORT}
export WEB_PORT=${WEB_PORT}
export POSTGRES_PORT=${DB_PORT}
export SEARCH_PORT=${SEARCH_PORT}
export SEARCH_ENABLED=${SEARCH_ENABLED}
export TAG=${TAG}
docker compose $COMPOSE_FILES up $COMPOSE_ARGS