diff --git a/.gitignore b/.gitignore index 3690b3d..717c14c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,14 @@ # __pycache__ directories in any path **/__pycache__ +BUILD + +# the copied +hubmap-auth/src/BUILD +hubmap-auth/src/VERSION + # log files in any path **/*.log # hubmap-auth app.cfg -hubmap-auth/src/instance/app.cfg \ No newline at end of file +hubmap-auth/src/instance/app.cfg diff --git a/README.md b/README.md index 598a217..d48a196 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ The Docker daemon binds to a Unix socket instead of a TCP port. By default that sudo usermod -aG docker $USER ```` -The log out and log back in so that your group membership is re-evaluated. If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect. +Then log out and log back in so that your group membership is re-evaluated. If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect. Note: the following instructions with docker commands are based on managing Docker as a non-root user. @@ -112,13 +112,12 @@ To see the usage of this script: It outputs: ```` -Usage: ./hubmap-docker.sh [-vhN] [localhost|dev|test|stage|prod] [build|start|stop|check|config] +Usage: ./hubmap-docker.sh [-vh] [localhost|dev|test|stage|prod] [build|start|stop|check|config] -v verbose -h help - -N use --no-cache for build ```` -The `hubmap-docker.sh` basically takes two arguments: deployment environment (localhost|dev|test|stage|prod) and the option (build|start|stop|check|config). In addition, you can also use `-v` to see the verbose output and `-h` for the usage help tip. The `--no-cache` is used with `build` to avoid the docker cache when creating images. +The `hubmap-docker.sh` basically takes two arguments: deployment environment (localhost|dev|test|stage|prod) and the option (build|start|stop|check|config). In addition, you can also use `-v` to see the verbose output and `-h` for the usage help tip. Before we go ahead to start building the docker images, we can do a check to see if all the required configuration files are in place: @@ -211,13 +210,40 @@ nginx -s reload * Reloading is safer than restarting because if a syntax error is noticed in a config file, it will not proceed with the reload and your server remains running. * If there is a syntax error in a config file and you restart, it's possible the server will not restart correctly. +## Rebuild `hubmap-auth` image individually + +You may only need to rebuild the `hubmap-auth` image while keeping other HuBMAP docker images unchanged. We first need to export the version environment variable by sourcing the script: + +```` +source ./hubmap-auth-docker.sh dev build +```` + +To start up the hubmap-auth container: + +```` +source ./hubmap-auth-docker.sh dev start +```` + +And stop the running container by: + +```` +source ./hubmap-auth-docker.sh dev stop +```` + +You can also stop the running container and remove it by: + +```` +source ./hubmap-auth-docker.sh dev down +```` + ## Update base image The `entity-api`, `uuid-api`, `ingest-api`, and `hubmap-auth` docker images are based on the `hubmap/api-base-image:latest` image. If you need to update the base image, go to the `api-base-image` directory and recrerate it with: ```` -docker build -t hubmap/api-base-image:latest +cd api-base-image +docker build -t hubmap/api-base-image:latest . ```` Then publish it to the DockerHub: diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..afa2b35 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.8.0 \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index e35f9cc..d8e7a40 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -20,6 +20,9 @@ services: # 8443 is used by ingest-api running on another machine - "8443:8443" volumes: + # Mount the VERSION file and BUILD file + - "./VERSION:/usr/src/app/src/VERSION" + - "./BUILD:/usr/src/app/src/BUILD" # Mount the source code to container - "./hubmap-auth/src/:/usr/src/app/src" # Mount conf.d-test to the nginx conf.d on container diff --git a/docker-compose.localhost.yml b/docker-compose.localhost.yml index e9300fb..e255904 100644 --- a/docker-compose.localhost.yml +++ b/docker-compose.localhost.yml @@ -27,11 +27,15 @@ services: # search-api - "8686:8686" volumes: + # Mount the VERSION file and BUILD file + - "./VERSION:/usr/src/app/src/VERSION" + - "./BUILD:/usr/src/app/src/BUILD" # Mount the source code to container - "./hubmap-auth/src/:/usr/src/app/src" # Mount conf.d-localhost to the nginx conf.d on container - "./nginx/conf.d-localhost:/etc/nginx/conf.d" # Mount the static files - - "/hubmap-data:/usr/src/assets" + - "/hubmap-data:/hubmap-data" # Mount the API endpoints json file for API endpoints lookup - "./api_endpoints.localhost.json:/usr/src/app/api_endpoints.json" + diff --git a/docker-compose.yml b/docker-compose.yml index 2fd03e7..9989f7e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,9 +10,16 @@ services: # The commons github branch to be used during image build (default to master if not set or null) - COMMONS_BRANCH=${COMMONS_BRANCH:-master} # Build the image with name and tag - image: hubmap-auth:1.7 + # Exit with an error message containing err if HUBMAP_AUTH_VERSION is unset or empty in the environment + image: hubmap-auth:${HUBMAP_AUTH_VERSION:?err} hostname: hubmap-auth container_name: hubmap-auth + healthcheck: + test: ["CMD", "curl", "--fail", "http://localhost:8080"] + interval: 1m30s + timeout: 10s + retries: 3 + start_period: 40s networks: - gateway_hubmap volumes: diff --git a/hubmap-auth-docker.sh b/hubmap-auth-docker.sh new file mode 100755 index 0000000..778a6da --- /dev/null +++ b/hubmap-auth-docker.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +# Print a new line and the banner +echo +echo "==================== HUBMAP-AUTH ====================" + +# Set the version environment variable for the docker build +# Version number is from the VERSION file +# Also remove newlines and leading/trailing slashes if present in that VERSION file +# Note: the BUILD and VERSION files are in the same dir as this script, this is different from other APIs +function export_version() { + export HUBMAP_AUTH_VERSION=$(tr -d "\n\r" < VERSION | xargs) + echo "HUBMAP_AUTH_VERSION: $HUBMAP_AUTH_VERSION" +} + +# Generate the build version based on git branch name and short commit hash and write into BUILD file +# Note: the BUILD and VERSION files are in the same dir as this script, this is different from other APIs +function generate_build_version() { + GIT_BRANCH_NAME=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') + GIT_SHORT_COMMIT_HASH=$(git rev-parse --short HEAD) + # Clear the old BUILD version and write the new one + truncate -s 0 BUILD + # Note: echo to file appends newline + echo $GIT_BRANCH_NAME:$GIT_SHORT_COMMIT_HASH >> BUILD + # Remmove the trailing newline character + truncate -s -1 BUILD + + echo "BUILD(git branch name:short commit hash): $GIT_BRANCH_NAME:$GIT_SHORT_COMMIT_HASH" +} + +# This function sets DIR to the directory in which this script itself is found. +# Thank you https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself +function get_dir_of_this_script () { + SCRIPT_SOURCE="${BASH_SOURCE[0]}" + while [ -h "$SCRIPT_SOURCE" ]; do # resolve $SCRIPT_SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" >/dev/null 2>&1 && pwd )" + SCRIPT_SOURCE="$(readlink "$SCRIPT_SOURCE")" + [[ $SCRIPT_SOURCE != /* ]] && SCRIPT_SOURCE="$DIR/$SCRIPT_SOURCE" # if $SCRIPT_SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + done + DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" >/dev/null 2>&1 && pwd )" + echo 'DIR of script:' $DIR +} + +if [[ "$1" != "localhost" && "$1" != "dev" && "$1" != "test" && "$1" != "stage" && "$1" != "prod" ]]; then + echo "Unknown build environment '$1', specify one of the following: localhost|dev|test|stage|prod" +else + if [[ "$2" != "check" && "$2" != "config" && "$2" != "build" && "$2" != "start" && "$2" != "stop" && "$2" != "down" ]]; then + echo "Unknown command '$2', specify one of the following: check|config|build|start|stop|down" + else + # Always show the script dir + get_dir_of_this_script + + # Always export and show the version + export_version + + # Always show the build in case branch changed or new commits + generate_build_version + + # Print empty line + echo + + if [ "$2" = "check" ]; then + # Bash array + config_paths=( + 'hubmap-auth/src/instance/app.cfg' + ) + + for pth in "${config_paths[@]}"; do + if [ ! -e $pth ]; then + echo "Missing file (relative path to DIR of script) :$pth" + exit -1 + fi + done + + echo 'Checks complete, all good :)' + elif [ "$2" = "config" ]; then + docker-compose -f docker-compose.yml -f docker-compose.$1.yml -p gateway config + elif [ "$2" = "build" ]; then + # Only mount the VERSION file and BUILD file for localhost and dev + # On test/stage/prod, copy the VERSION file and BUILD file to image + if [[ "$1" != "localhost" && "$1" != "dev" ]]; then + cp VERSION hubmap-auth/src + cp BUILD hubmap-auth/src + fi + + docker-compose -f docker-compose.yml -f docker-compose.$1.yml -p gateway build + elif [ "$2" = "start" ]; then + docker-compose -f docker-compose.yml -f docker-compose.$1.yml -p gateway up -d + elif [ "$2" = "stop" ]; then + docker-compose -f docker-compose.yml -f docker-compose.$1.yml -p gateway stop + elif [ "$2" = "down" ]; then + docker-compose -f docker-compose.yml -f docker-compose.$1.yml -p gateway down + fi + fi +fi diff --git a/hubmap-auth/src/app.py b/hubmap-auth/src/app.py index 5ca3731..c765f96 100644 --- a/hubmap-auth/src/app.py +++ b/hubmap-auth/src/app.py @@ -7,6 +7,7 @@ import functools import re import os +from pathlib import Path from urllib.parse import urlparse, parse_qs # HuBMAP commons @@ -260,12 +261,14 @@ def status_request(target_url): # Dict of API status data def get_status_data(): # Some constants + GATEWAY = 'gateway' + VERSION = 'version' + BUILD = 'build' UUID_API = 'uuid_api' ENTITY_API = 'entity_api' INGEST_API = 'ingest_api' SEARCH_API = 'search_api' FILE_ASSETS = 'file_assets' - API_AUTH = 'api_auth' MYSQL_CONNECTION = 'mysql_connection' NEO4J_CONNECTION = 'neo4j_connection' @@ -274,8 +277,16 @@ def get_status_data(): FILE_ASSETS_STATUS = 'file_assets_status' # All API services have api_auth status (meaning the gateway's API auth is working) + # We won't get other status if api_auth fails # Add additional API-specific status to the dict when API auth check passes + # Gateway version and build are parsed from VERSION and BUILD files directly + # instead of making API calls. So they alwasy present status_data = { + GATEWAY: { + # Use strip() to remove leading and trailing spaces, newlines, and tabs + VERSION: (Path(__file__).parent / 'VERSION').read_text().strip(), + BUILD: (Path(__file__).parent / 'BUILD').read_text().strip() + }, UUID_API: { API_AUTH: False }, @@ -301,6 +312,14 @@ def get_status_data(): # Then parse the response json to determine if neo4j connection is working response_json = uuid_api_response.json() + if VERSION in response_json: + # Set version + status_data[UUID_API][VERSION] = response_json[VERSION] + + if BUILD in response_json: + # Set build + status_data[UUID_API][BUILD] = response_json[BUILD] + if MYSQL_CONNECTION in response_json: # Add the mysql connection status status_data[UUID_API][MYSQL_CONNECTION] = response_json[MYSQL_CONNECTION] @@ -313,6 +332,14 @@ def get_status_data(): # Then parse the response json to determine if neo4j connection is working response_json = entity_api_response.json() + if VERSION in response_json: + # Set version + status_data[ENTITY_API][VERSION] = response_json[VERSION] + + if BUILD in response_json: + # Set build + status_data[ENTITY_API][BUILD] = response_json[BUILD] + if NEO4J_CONNECTION in response_json: # Add the neo4j connection status status_data[ENTITY_API][NEO4J_CONNECTION] = response_json[NEO4J_CONNECTION] @@ -325,6 +352,14 @@ def get_status_data(): # Then parse the response json to determine if neo4j connection is working response_json = ingest_api_response.json() + if VERSION in response_json: + # Set version + status_data[INGEST_API][VERSION] = response_json[VERSION] + + if BUILD in response_json: + # Set build + status_data[INGEST_API][BUILD] = response_json[BUILD] + if NEO4J_CONNECTION in response_json: # Add the neo4j connection status status_data[INGEST_API][NEO4J_CONNECTION] = response_json[NEO4J_CONNECTION] @@ -337,6 +372,14 @@ def get_status_data(): # Then parse the response json to determine if elasticsearch cluster is connected response_json = search_api_response.json() + if VERSION in response_json: + # Set version + status_data[SEARCH_API][VERSION] = response_json[VERSION] + + if BUILD in response_json: + # Set build + status_data[SEARCH_API][BUILD] = response_json[BUILD] + if ELASTICSEARCH_CONNECTION in response_json: # Add the elasticsearch connection status status_data[SEARCH_API][ELASTICSEARCH_CONNECTION] = response_json[ELASTICSEARCH_CONNECTION] diff --git a/hubmap-auth/src/templates/status.html b/hubmap-auth/src/templates/status.html index ab6a23a..3d02331 100644 --- a/hubmap-auth/src/templates/status.html +++ b/hubmap-auth/src/templates/status.html @@ -15,10 +15,33 @@
+{% if data.gateway %} + +

Gateway

+ +{% if data.gateway.version %} +

Version: {{ data.gateway.version }}

+{% endif %} + +{% if data.gateway.build %} +

Build: {{ data.gateway.build }}

+{% endif %} + +{% endif %} + + {% if data.uuid_api %}

UUID API

+{% if data.uuid_api.version %} +

Version: {{ data.uuid_api.version }}

+{% endif %} + +{% if data.uuid_api.build %} +

Build: {{ data.uuid_api.build }}

+{% endif %} + {% if data.uuid_api.api_auth %}

API Auth: {{ data.uuid_api.api_auth }}

{% endif %} @@ -34,6 +57,14 @@

UUID API

Entity API

+{% if data.entity_api.version %} +

Version: {{ data.entity_api.version }}

+{% endif %} + +{% if data.entity_api.build %} +

Build: {{ data.entity_api.build }}

+{% endif %} + {% if data.entity_api.api_auth %}

API Auth: {{ data.entity_api.api_auth }}

{% endif %} @@ -49,6 +80,14 @@

Entity API

Ingest API

+{% if data.ingest_api.version %} +

Version: {{ data.ingest_api.version }}

+{% endif %} + +{% if data.ingest_api.build %} +

Build: {{ data.ingest_api.build }}

+{% endif %} + {% if data.ingest_api.api_auth %}

API Auth: {{ data.ingest_api.api_auth }}

{% endif %} @@ -61,7 +100,17 @@

Ingest API

{% if data.search_api %} +

Search API

+ +{% if data.search_api.version %} +

Version: {{ data.search_api.version }}

+{% endif %} + +{% if data.search_api.build %} +

Build: {{ data.search_api.build }}

+{% endif %} + {% if data.search_api.api_auth %}

API Auth: {{ data.search_api.api_auth }}

diff --git a/hubmap-docker.sh b/hubmap-docker.sh index 66009ed..b5bc648 100755 --- a/hubmap-docker.sh +++ b/hubmap-docker.sh @@ -1,99 +1,43 @@ #!/bin/bash +# Print the banner +echo +echo '# # ###### # # # ###### ######' +echo '# # # # # # ## ## # # # # # # #### #### # # ###### #####' +echo '# # # # # # # # # # # # # # # # # # # # # # # # #' +echo '####### # # ###### # # # # # ###### # # # # # #### ##### # #' +echo '# # # # # # # # ####### # # # # # # # # # #####' +echo '# # # # # # # # # # # # # # # # # # # # # #' +echo '# # #### ###### # # # # # ###### #### #### # # ###### # #' +echo + +# This function sets DIR to the directory in which this script itself is found. +# Thank you https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself function get_dir_of_this_script () { - # This function sets DIR to the directory in which this script itself is found. - # Thank you https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself SCRIPT_SOURCE="${BASH_SOURCE[0]}" while [ -h "$SCRIPT_SOURCE" ]; do # resolve $SCRIPT_SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" >/dev/null 2>&1 && pwd )" - SCRIPT_SOURCE="$(readlink "$SCRIPT_SOURCE")" - [[ $SCRIPT_SOURCE != /* ]] && SCRIPT_SOURCE="$DIR/$SCRIPT_SOURCE" # if $SCRIPT_SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" >/dev/null 2>&1 && pwd )" + SCRIPT_SOURCE="$(readlink "$SCRIPT_SOURCE")" + [[ $SCRIPT_SOURCE != /* ]] && SCRIPT_SOURCE="$DIR/$SCRIPT_SOURCE" # if $SCRIPT_SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located done DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" >/dev/null 2>&1 && pwd )" - } - -function absent_or_newer () { - if [ \( -e $1 \) -a \( $2 -nt $1 \) ]; then - echo "$1 is out of date" - exit -1 - fi -} - -function echo_help () { - echo "Usage: $0 [-vhN] [localhost|dev|test|stage|prod] [build|start|stop|check|config]" - echo " -v verbose" - echo " -h help" - echo " -N use --no-cache for build" -} - -# Command line parsing. See for ex. https://sookocheff.com/post/bash/parsing-bash-script-arguments-with-shopts/ -# and https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux -unameOut="$(uname -s)" -case "${unameOut}" in - Linux*) machine=Linux;; - Darwin*) machine=Mac;; - CYGWIN*) machine=Cygwin;; - MINGW*) machine=MinGw;; - *) machine="UNKNOWN:${unameOut}" -esac -BUILD_OPTS= -VERBOSE= -if [ "$machine" = 'Mac' ] ; then - options=$(getopt vhN "$@") -else - options=$(getopt -o vhN -- "$@") -fi -[ $? -eq 0 ] || { - echo "Incorrect option provided" - echo_help - exit 1 } -eval set -- "$options" -while true; do - case "$1" in - -N|--no-cache) - BUILD_OPTS+="--no-cache" - ;; - -v) - VERBOSE=1 - ;; - -h) - echo_help - exit 0 - ;; - --) - shift - break - ;; - esac - shift -done -if [ -n "$VERBOSE" ] ; then - echo 'BUILD_OPTS' $BUILD_OPTS - echo '$1' $1 - echo '$2' $2 -fi if [[ "$1" != "localhost" && "$1" != "dev" && "$1" != "test" && "$1" != "stage" && "$1" != "prod" ]]; then - echo "Unknown build environment '$1', specify one of the following: 'localhost', 'dev', 'test', 'stage', or 'prod'" + echo "Unknown build environment '$1', specify one of the following: localhost|dev|test|stage|prod" exit 255 fi -if [[ "$2" != "build" && "$2" != "start" && "$2" != "stop" && "$2" != "check" && "$2" != "config" ]]; then - echo "Unknown command '$2', specify 'build' or 'start' or 'stop' or 'check' or 'config' as the second argument" +if [[ "$2" != "check" && "$2" != "config" && "$2" != "build" && "$2" != "start" && "$2" != "stop" && "$2" != "down" ]]; then + echo "Unknown command '$2', specify one of the following: check|config|build|start|stop|down" exit 255 fi # set DIR to be the directory of the current script get_dir_of_this_script -if [ -n "$VERBOSE" ] ; then - echo 'DIR is ' $DIR -fi +echo 'DIR of script:' $DIR -# set some environment variables which may be used by the docker-compose scripts -if [ -e $DIR/../ingest-pipeline/build_number ] ; then - export INGEST_PIPELINE_BUILD_NUM=`cat $DIR/../ingest-pipeline/build_number` -fi +# Use the current user UID and GID to run processes in containers for localhost build if [ "$1" = "localhost" ]; then if [ -z "$HOST_UID" ] ; then log_name=`logname` @@ -103,184 +47,39 @@ if [ "$1" = "localhost" ]; then log_name=`logname` export HOST_GID=`id -g $log_name` fi -fi -if [ -n "$VERBOSE" ] ; then - echo 'INGEST_PIPELINE_BUILD_NUM is ' $INGEST_PIPELINE_BUILD_NUM - echo 'HOST_UID is ' $HOST_UID - echo 'HOST_GID is ' $HOST_GID -fi - -if [ "$2" = "build" ]; then - # First create the shared docker network - cd $DIR - docker network create gateway_hubmap - - # Build images for gateway since this is the current dir - docker-compose -f docker-compose.yml -f docker-compose.$1.yml build $BUILD_OPTS - - cd $DIR/../uuid-api/docker - ./docker-setup.sh - docker-compose -f docker-compose.yml -f docker-compose.$1.yml build $BUILD_OPTS - - cd $DIR/../entity-api/docker - ./docker-setup.sh - docker-compose -f docker-compose.yml -f docker-compose.$1.yml build $BUILD_OPTS - - cd $DIR/../search-api/docker - ./docker-setup.sh - docker-compose -f docker-compose.yml -f docker-compose.$1.yml build $BUILD_OPTS - - # Only have ingest-api and ingest-ui on the same host machine for localhost environment - # dev, test, or prod deployment has ingest-api on a separate machine - cd $DIR/../ingest-ui/docker - ./docker-setup-ingest-ui.sh - docker-compose -f docker-compose-ingest-ui.$1.yml build $BUILD_OPTS - - # Also build ingest-api and ingest-pipeline for localhost only - if [ "$1" = "localhost" ]; then - cd $DIR/../ingest-ui/docker - ./docker-setup-ingest-api.$1.sh - docker-compose -f docker-compose-ingest-api.$1.yml build $BUILD_OPTS - cd $DIR/../ingest-pipeline/docker - ./docker-setup.$1.sh - docker-compose -f docker-compose.yml -f docker-compose.$1.yml build $BUILD_OPTS - fi - -elif [ "$2" = "start" ]; then - - # Spin up the containers for each project - cd $DIR/../uuid-api/docker - docker-compose -p uuid-api -f docker-compose.yml -f docker-compose.$1.yml up -d - - cd $DIR/../entity-api/docker - docker-compose -p entity-api -f docker-compose.yml -f docker-compose.$1.yml up -d - - cd $DIR/../search-api/docker - docker-compose -p search-api -f docker-compose.yml -f docker-compose.$1.yml up -d - - # Only have ingest-api and ingest-ui on the same host machine for localhost environment - # dev, test, or prod deployment has ingest-api on a separate machine - cd $DIR/../ingest-ui/docker - docker-compose -p ingest-ui -f docker-compose-ingest-ui.$1.yml up -d - - # Also start the ingest-api and ingest-pipeline for localhost only - if [ "$1" = "localhost" ]; then - cd $DIR/../ingest-ui/docker - docker-compose -p ingest-api -f docker-compose-ingest-api.$1.yml up -d - cd $DIR/../ingest-pipeline/docker - ./docker-setup.$1.sh - docker-compose -p ingest-pipeline -f docker-compose.yml -f docker-compose.$1.yml up -d - fi - - # The last one is gateway since nginx conf files require - # entity-api, uuid-api, ingest-ui, ingest-api, and ingest-pipeline to be running - # before starting the gateway service - cd $DIR - docker-compose -p gateway -f docker-compose.yml -f docker-compose.$1.yml up -d - -elif [ "$2" = "stop" ]; then - # Stop the gateway first - cd $DIR - docker-compose -p gateway -f docker-compose.yml -f docker-compose.$1.yml stop - - # Stop each service + echo 'HOST_UID:' $HOST_UID + echo 'HOST_GID:' $HOST_GID +fi - # Only have ingest-api and ingest-ui on the same host machine for localhost environment - # dev, test, or prod deployment has ingest-api on a separate machine - cd $DIR/../ingest-ui/docker - docker-compose -p ingest-ui -f docker-compose-ingest-ui.$1.yml stop +# Create the docker network "gateway_hubmap" if doesn't exists +docker network inspect gateway_hubmap >/dev/null 2>&1 || docker network create gateway_hubmap - # Also stop the ingest-api and ingest-pipeline containers for localhost only - if [ "$1" = "localhost" ]; then - cd $DIR/../ingest-ui/docker - docker-compose -p ingest-api -f docker-compose-ingest-api.$1.yml stop - cd $DIR/../ingest-pipeline/docker - docker-compose -p ingest-pipeline -f docker-compose.yml -f docker-compose.$1.yml stop - fi +# Direct the execution to individual script for each project +cd $DIR/../uuid-api/docker +./uuid-api-docker.sh $1 $2 - cd $DIR/../uuid-api/docker - docker-compose -p uuid-api -f docker-compose.yml -f docker-compose.$1.yml stop +cd $DIR/../entity-api/docker +./entity-api-docker.sh $1 $2 - cd $DIR/../entity-api/docker - docker-compose -p entity-api -f docker-compose.yml -f docker-compose.$1.yml stop +cd $DIR/../search-api/docker +./search-api-docker.sh $1 $2 - cd $DIR/../search-api/docker - docker-compose -p search-api -f docker-compose.yml -f docker-compose.$1.yml stop -elif [ "$2" = "config" ]; then - # Stop the gateway first - cd $DIR - echo '###### GATEWAY ########' - docker-compose -p gateway -f docker-compose.yml -f docker-compose.$1.yml config +# Only have ingest-api and ingest-ui on the same host machine for localhost environment +# dev/test/staage/prod deployment has ingest-api on a separate machine - # Stop each service +cd $DIR/../ingest-ui/docker +./ingest-ui-docker.sh $1 $2 - # Only have ingest-api and ingest-ui on the same host machine for localhost environment - # dev, test, or prod deployment has ingest-api on a separate machine +# Also start the ingest-api and ingest-pipeline for localhost only +if [ "$1" = "localhost" ]; then cd $DIR/../ingest-ui/docker - echo '###### INGEST-UI ########' - docker-compose -p ingest-ui -f docker-compose-ingest-ui.$1.yml config - - # Also stop the ingest-api and ingest-pipeline containers for localhost only - if [ "$1" = "localhost" ]; then - cd $DIR/../ingest-ui/docker - echo '###### INGEST-API ########' - docker-compose -p ingest-api -f docker-compose-ingest-api.$1.yml config - cd $DIR/../ingest-pipeline/docker - echo '###### INGEST-PIPELINE ########' - docker-compose -p ingest-pipeline -f docker-compose.yml -f docker-compose.$1.yml config - fi + ./ingest-api-docker.sh $1 $2 - cd $DIR/../uuid-api/docker - echo '###### UUID-API ########' - docker-compose -p uuid-api -f docker-compose.yml -f docker-compose.$1.yml config - - cd $DIR/../entity-api/docker - echo '###### ENTITY-API ########' - docker-compose -p entity-api -f docker-compose.yml -f docker-compose.$1.yml config - - cd $DIR/../search-api/docker - echo '###### SEARCH-API ########' - docker-compose -p search-api -f docker-compose.yml -f docker-compose.$1.yml config -elif [ "$2" = "check" ]; then - # Bash array - config_paths=( - '../gateway/hubmap-auth/src/instance/app.cfg' - '../uuid-api/src/instance/app.cfg' - '../entity-api/src/instance/app.cfg' - '../search-api/src/instance/app.cfg' - '../ingest-ui/src/ingest-ui/.env' - ) - - # Add ingest-api and ingest-pipeline configs to the array for localhost only - if [ "$1" = "localhost" ]; then - config_paths+=( - '../ingest-ui/src/ingest-api/instance/app.cfg' - '../ingest-pipeline/src/ingest-pipeline/instance/app.cfg' - ) - fi - - cd $DIR - for pth in "${config_paths[@]}"; do - if [ ! -e $pth ]; then - echo "Missing $pth" - exit -1 - fi - done - - # The `absent_or_newer` checks if the copied src at docker/some-api/src directory exists - # and if the source src directory is newer. - # If both conditions are true `absent_or_newer` writes an error message - # and causes hubmap-docker.sh to exit with an error code. - absent_or_newer ../uuid-api/docker/uuid-api/src ../uuid-api/src - absent_or_newer ../entity-api/docker/entity-api/src ../entity-api/src - absent_or_newer ../search-api/docker/search-api/src ../search-api/src - absent_or_newer ../ingest-ui/docker/ingest-ui/src ../ingest-ui/src/ingest-ui - - # Also check the ingest-api for localhost and dev only - if [ "$1" = "localhost" ]; then - absent_or_newer ../ingest-ui/docker/ingest-api/src ../ingest-ui/src/ingest-api - fi - - echo 'Checks complete, all good :)' + cd $DIR/../ingest-pipeline/docker + ./ingest-pipeline-docker.sh $1 $2 fi + +# The last one is gateway since nginx conf files require all proxied services to be running prior to the nignx start +cd $DIR +./hubmap-auth-docker.sh $1 $2