diff --git a/Makefile b/Makefile index 63c188f42..e5d971fe7 100644 --- a/Makefile +++ b/Makefile @@ -142,7 +142,6 @@ restart-all: build-dss down-locally start-locally .PHONY: start-locally start-locally: build/dev/run_locally.sh up -d - build/dev/wait_for_local_dss.sh .PHONY: probe-locally probe-locally: diff --git a/build/dev/docker-compose_dss.yaml b/build/dev/docker-compose_dss.yaml index 3ce9dad1f..df0016dad 100644 --- a/build/dev/docker-compose_dss.yaml +++ b/build/dev/docker-compose_dss.yaml @@ -16,18 +16,21 @@ services: restart: always networks: - dss_sandbox_default_network + healthcheck: + test: curl -f 'http://localhost:8080/health?ready=1' || exit 1 + interval: 3m + start_period: 30s + start_interval: 5s local-dss-rid-bootstrapper: build: context: ../.. dockerfile: Dockerfile image: interuss-local/dss - volumes: - - local-dss-data:/var/local-dss-data - - $PWD/startup:/startup:ro - entrypoint: /startup/rid_bootstrapper.sh + command: /usr/bin/db-manager migrate --schemas_dir=/db-schemas/rid --db_version "latest" --cockroach_host local-dss-crdb depends_on: - - local-dss-crdb + local-dss-crdb: + condition: service_healthy networks: - dss_sandbox_default_network @@ -36,12 +39,10 @@ services: context: ../.. dockerfile: Dockerfile image: interuss-local/dss - volumes: - - local-dss-data:/var/local-dss-data - - $PWD/startup:/startup:ro - entrypoint: /startup/scd_bootstrapper.sh + entrypoint: /usr/bin/db-manager migrate --schemas_dir=/db-schemas/scd --db_version "latest" --cockroach_host local-dss-crdb depends_on: - - local-dss-crdb + local-dss-crdb: + condition: service_healthy networks: - dss_sandbox_default_network @@ -52,17 +53,23 @@ services: image: interuss-local/dss volumes: - $PWD/../test-certs:/var/test-certs:ro - - local-dss-data:/var/local-dss-data - - $PWD/startup:/startup:ro + - $PWD/startup/core_service.sh:/startup/core_service.sh:ro command: /startup/core_service.sh ${DEBUG_ON:-0} ports: - "4000:4000" - "8082:8082" depends_on: - - local-dss-rid-bootstrapper - - local-dss-scd-bootstrapper + local-dss-rid-bootstrapper: + condition: service_completed_successfully + local-dss-scd-bootstrapper: + condition: service_completed_successfully networks: - dss_sandbox_default_network + healthcheck: + test: wget -O - 'http://localhost/healthy' || exit 1 + interval: 3m + start_period: 30s + start_interval: 5s local-dss-dummy-oauth: build: @@ -74,6 +81,11 @@ services: - "8085:8085" networks: - dss_sandbox_default_network + healthcheck: + test: wget -O - 'http://localhost:8085/token?intended_audience=-&scope=-' || exit 1 + interval: 3m + start_period: 30s + start_interval: 5s networks: dss_sandbox_default_network: diff --git a/build/dev/startup/core_service.sh b/build/dev/startup/core_service.sh index 1e374a3e1..448417adb 100755 --- a/build/dev/startup/core_service.sh +++ b/build/dev/startup/core_service.sh @@ -3,8 +3,6 @@ # This startup script is meant to be invoked from within a Docker container # started by docker-compose_dss.yaml, not on a local system. -/startup/wait_for_bootstrapping.sh - DEBUG_ON=${1:-0} if [ "$DEBUG_ON" = "1" ]; then diff --git a/build/dev/startup/rid_bootstrapper.sh b/build/dev/startup/rid_bootstrapper.sh deleted file mode 100755 index f57dda68f..000000000 --- a/build/dev/startup/rid_bootstrapper.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -# This startup script is meant to be invoked from within a Docker container -# started by docker-compose_dss.yaml, not on a local system. - -if ls /var/local-dss-data/rid_bootstrap > /dev/null 2>&1; then - echo "RID DB is already set up; no need to run bootstrapper." - exit 0 -else - echo "Allowing time for CRDB node to come up..." - sleep 3 - - echo "Bootstrapping RID DB..." - /usr/bin/db-manager migrate \ - --schemas_dir /db-schemas/rid \ - --db_version "latest" \ - --cockroach_host local-dss-crdb - - echo "RID DB bootstrapping complete; notifying other containers..." - touch /var/local-dss-data/rid_bootstrap -fi diff --git a/build/dev/startup/scd_bootstrapper.sh b/build/dev/startup/scd_bootstrapper.sh deleted file mode 100755 index 187198dbf..000000000 --- a/build/dev/startup/scd_bootstrapper.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -# This startup script is meant to be invoked from within a Docker container -# started by docker-compose_dss.yaml, not on a local system. - -if ls /var/local-dss-data/scd_bootstrap > /dev/null 2>&1; then - echo "SCD DB is already set up; no need to run bootstrapper." - exit 0 -else - echo "Allowing time for CRDB node to come up..." - sleep 3 - - echo "Bootstrapping SCD DB..." - /usr/bin/db-manager migrate \ - --schemas_dir /db-schemas/scd \ - --db_version "latest" \ - --cockroach_host local-dss-crdb - - echo "SCD DB bootstrapping complete; notifying other containers..." - touch /var/local-dss-data/scd_bootstrap -fi diff --git a/build/dev/startup/wait_for_bootstrapping.sh b/build/dev/startup/wait_for_bootstrapping.sh deleted file mode 100755 index 8157b083b..000000000 --- a/build/dev/startup/wait_for_bootstrapping.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -# This startup script is meant to be invoked from within a Docker container -# started by docker-compose_dss.yaml, not on a local system. - -while [ ! -e /var/local-dss-data/rid_bootstrap ] || [ ! -e /var/local-dss-data/scd_bootstrap ]; do - echo "Waiting on DB bootstrapping..." - if [ ! -e /var/local-dss-data/rid_bootstrap ]; then - echo " RID pending." - fi - if [ ! -e /var/local-dss-data/scd_bootstrap ]; then - echo " SCD pending." - fi - sleep 3 -done -echo "DB bootstrap complete; starting core service..." diff --git a/build/dev/wait_for_local_dss.sh b/build/dev/wait_for_local_dss.sh deleted file mode 100755 index 65dfb32fa..000000000 --- a/build/dev/wait_for_local_dss.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -OAUTH_CONTAINER="dss_sandbox-local-dss-dummy-oauth-1" -CORE_SERVICE_CONTAINER="dss_sandbox-local-dss-core-service-1" -declare -a localhost_containers=("$OAUTH_CONTAINER" "$CORE_SERVICE_CONTAINER") - -# 2 minute timer to prevent infinite looping if a docker issue is present. -timeout_duration=120 - -# check to see if 2 minutes has elapsed which indicates a problem with the container(s) -check_timeout() { - local start_time="$1" - local error_message="$2" - current_time=$(date +%s) - elapsed_time=$((current_time-start_time)) - if ((elapsed_time >= timeout_duration)); then - echo "$error_message" - exit 1 - fi -} - -# start the timer -start_time=$(date +%s) -for container_name in "${localhost_containers[@]}"; do - last_message="" - while true; do - if [ "$( docker container inspect -f '{{.State.Status}}' "${container_name}" 2>/dev/null)" = "running" ]; then - break - fi - new_message="Waiting for ${container_name} container to start..." - if [ "${new_message}" = "${last_message}" ]; then - printf "." - else - printf '%s' "${new_message}" - last_message="${new_message}" - fi - check_timeout "$start_time" "Timeout reached. Container failed to start. Exiting." - sleep 3 - done - if [ -n "${last_message}" ]; then - echo "" - fi -done - -# reset the timer -start_time=$(date +%s) -last_message="" -while true; do - health_status="$( docker container inspect -f '{{.State.Health.Status}}' "${CORE_SERVICE_CONTAINER}" )" - if [ "${health_status}" = "healthy" ]; then - break - else - new_message="Waiting for ${CORE_SERVICE_CONTAINER} to be available (currently ${health_status})..." - if [ "${new_message}" = "${last_message}" ]; then - printf "." - else - printf '%s' "${new_message}" - last_message="${new_message}" - fi - check_timeout "$start_time" "Timeout reached. Container failed to become available. Exiting." - sleep 3 - fi -done -if [ -n "${last_message}" ]; then - echo "" -fi - -echo "Local DSS instance is now available."