2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-22 10:10:12 +00:00
vinyldns/bin/docker-up-api-server.sh

59 lines
1.8 KiB
Bash
Raw Normal View History

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-07-27 10:18:29 -04:00
DIR=$( cd $(dirname $0) ; pwd -P )
set -a # Required in order to source docker/.env
# Source customizable env files
source "$DIR"/.env
source "$DIR"/../docker/.env
WORK_DIR="$DIR"/../target/scala-2.12
mkdir -p "$WORK_DIR"
2018-07-27 10:18:29 -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
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
cd "$DIR"
2018-07-27 10:18:29 -04:00
fi
cp -f "$DIR"/../modules/api/target/scala-2.12/vinyldns.jar "$WORK_DIR"/docker/api
2018-07-27 10:18:29 -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
echo "Waiting for API to be ready at ${VINYLDNS_API_URL} ..."
2018-07-27 10:18:29 -04:00
DATA=""
RETRY=40
while [ "$RETRY" -gt 0 ]
2018-07-27 10:18:29 -04:00
do
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
echo "Succeeded in connecting to VinylDNS API!"
2018-07-27 10:18:29 -04:00
break
else
echo "Retrying" >&2
2018-07-27 10:18:29 -04:00
let RETRY-=1
sleep 1
if [ "$RETRY" -eq 0 ]
2018-07-27 10:18:29 -04:00
then
echo "Exceeded retries waiting for VinylDNS API to be ready, failing"
2018-07-27 10:18:29 -04:00
exit 1
fi
fi
done