2018-07-27 10:18:29 -04:00
|
|
|
#!/bin/bash
|
|
|
|
######################################################################
|
|
|
|
# Copies the contents of `docker` into target/scala-2.12
|
|
|
|
# to start up dependent services via docker compose. Once
|
|
|
|
# dependent services are started up, the fat jar built by sbt assembly
|
|
|
|
# is loaded into a docker container. The api will be available
|
|
|
|
# by default on port 9000
|
|
|
|
######################################################################
|
|
|
|
|
2018-09-17 11:18:37 -04:00
|
|
|
|
2018-07-27 10:18:29 -04:00
|
|
|
DIR=$( cd $(dirname $0) ; pwd -P )
|
2018-09-17 11:18:37 -04:00
|
|
|
|
|
|
|
set -a # Required in order to source docker/.env
|
|
|
|
# Source customizable env files
|
|
|
|
source "$DIR"/.env
|
|
|
|
source "$DIR"/../docker/.env
|
|
|
|
|
2018-08-17 16:59:45 -04:00
|
|
|
WORK_DIR="$DIR"/../target/scala-2.12
|
|
|
|
mkdir -p "$WORK_DIR"
|
2018-07-27 10:18:29 -04:00
|
|
|
|
2018-08-17 16:59:45 -04:00
|
|
|
echo "Copy all Docker to the target directory so we can start up properly and the Docker context is small..."
|
|
|
|
cp -af "$DIR"/../docker "$WORK_DIR"/
|
2018-07-27 10:18:29 -04:00
|
|
|
|
2018-08-17 16:59:45 -04:00
|
|
|
echo "Copy the vinyldns.jar to the API Docker folder so it is in context..."
|
|
|
|
if [[ ! -f "$DIR"/../modules/api/target/scala-2.12/vinyldns.jar ]]; then
|
|
|
|
echo "vinyldns.jar not found, building..."
|
|
|
|
cd "$DIR"/../
|
2018-07-27 10:18:29 -04:00
|
|
|
sbt api/clean api/assembly
|
2018-08-17 16:59:45 -04:00
|
|
|
cd "$DIR"
|
2018-07-27 10:18:29 -04:00
|
|
|
fi
|
2018-08-17 16:59:45 -04:00
|
|
|
cp -f "$DIR"/../modules/api/target/scala-2.12/vinyldns.jar "$WORK_DIR"/docker/api
|
2018-07-27 10:18:29 -04:00
|
|
|
|
2018-08-17 16:59:45 -04:00
|
|
|
echo "Starting API server and all dependencies in the background..."
|
|
|
|
docker-compose -f "$WORK_DIR"/docker/docker-compose-func-test.yml --project-directory "$WORK_DIR"/docker up --build -d api
|
2018-07-27 10:18:29 -04:00
|
|
|
|
2018-09-17 11:18:37 -04:00
|
|
|
echo "Waiting for API to be ready at ${VINYLDNS_API_URL} ..."
|
2018-07-27 10:18:29 -04:00
|
|
|
DATA=""
|
|
|
|
RETRY=40
|
2018-08-17 16:59:45 -04:00
|
|
|
while [ "$RETRY" -gt 0 ]
|
2018-07-27 10:18:29 -04:00
|
|
|
do
|
2018-09-17 11:18:37 -04:00
|
|
|
DATA=$(curl -I -s "${VINYLDNS_API_URL}/ping" -o /dev/null -w "%{http_code}")
|
2018-07-27 10:18:29 -04:00
|
|
|
if [ $? -eq 0 ]
|
|
|
|
then
|
2018-08-17 16:59:45 -04:00
|
|
|
echo "Succeeded in connecting to VinylDNS API!"
|
2018-07-27 10:18:29 -04:00
|
|
|
break
|
|
|
|
else
|
|
|
|
echo "Retrying Again" >&2
|
|
|
|
|
|
|
|
let RETRY-=1
|
|
|
|
sleep 1
|
|
|
|
|
2018-08-17 16:59:45 -04:00
|
|
|
if [ "$RETRY" -eq 0 ]
|
2018-07-27 10:18:29 -04:00
|
|
|
then
|
2018-08-17 16:59:45 -04:00
|
|
|
echo "Exceeded retries waiting for VinylDNS API to be ready, failing"
|
2018-07-27 10:18:29 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|