diff --git a/docker/dev/_init_setup.sh b/docker/dev/_init_setup.sh index 1f523517..93d4c702 100755 --- a/docker/dev/_init_setup.sh +++ b/docker/dev/_init_setup.sh @@ -1,41 +1,36 @@ -#!/bin/bash +#!/usr/bin/env bash + +is_ready() { + curl -s --include --header "X-Project-ID: 000" \ + http://localhost:8888/v1.0/ping \ + | grep "204 No Content" \ + | wc -l \ + | sed 's/ //g' +} + +while [[ ! "$(is_ready)" = "1" ]]; do + echo "$(date) - Waiting for poppy-server to come online" + sleep 1 +done +echo "$(date) - Connected!" + # "Upsert" sni config python /poppy/scripts/providers/akamai/san_cert_info/cassandra/upsert_sni_cert_info.py --config-file /etc/poppy.conf -# Create a default flavor +# Create a default flavors curl --include \ --request POST \ --header "Content-Type: application/json" \ --header "X-Project-ID: 000" \ - --data-binary '{ - "id" : "cdn", - "limits": [{ - "origins": { - "min": 1, - "max": 5 - }, - "domains" : { - "min": 1, - "max": 5 - }, - "caching": { - "min": 3600, - "max": 604800, - "incr": 300 - } - }], - "providers" : [ - { - "provider" : "akamai", - "links": [ - { - "href": "http://www.akamai.com", - "rel": "provider_url" - } - ] - }, + --data-binary '{"id": "cdn", "limits": [{"origins": {"min": 1, "max": 5}, "domains": {"min": 1, "max": 5}, "caching": {"min": 3600, "max": 604800, "incr": 300}}], "providers": [{"provider": "akamai", "links": [{"href": "http://www.akamai.com", "rel": "provider_url"}]}]}' \ + "http://localhost:8888/v1.0/flavors" - ] -}' "http://localhost:8888/v1.0/flavors" +# Create a default flavors +curl --include \ + --request POST \ + --header "Content-Type: application/json" \ + --header "X-Project-ID: 000" \ + --data-binary '{"id": "flavor", "limits": [{"origins": {"min": 1, "max": 5}, "domains": {"min": 1, "max": 5}, "caching": {"min": 3600, "max": 604800, "incr": 300}}], "providers": [{"provider": "akamai", "links": [{"href": "http://www.akamai.com", "rel": "provider_url"}]}]}' \ + "http://localhost:8888/v1.0/flavors" diff --git a/init_docker.sh b/init_docker.sh index 6dbb5c25..10131be7 100755 --- a/init_docker.sh +++ b/init_docker.sh @@ -4,38 +4,89 @@ ## Use the '.env' file located in the root of the poppy repo to configure. WORKSPACE=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd); -REBUILD=1 -AUTORUN=1 -# copy the requirements so they can be cached within docker -{ - find "$WORKSPACE/requirements" -name "*.txt" -exec cat "{}" \; | grep -v "^-r" - cat "$WORKSPACE/doc/requirements.txt" - cat "$WORKSPACE/tests/test-requirements.txt" -} | sort | uniq | tee "$WORKSPACE/docker/dev/dev-requirements.txt" +NO_REBUILD=false +AUTO_RUN=false +RUN_POPPY=true +RUN_POPPY_DEPS=false +while getopts "iaeo" OPTION +do + case ${OPTION} in + i) + INIT_SETUP=true + echo "Initializing Development Environment" + ;; + a) + echo "Auto run enabled" + AUTO_RUN=true + ;; + e) + echo "Running init container setup script (sni_upsert, flavor creation, etc)" + echo "* poppy-server must be running *" + exec docker-compose -f "$WORKSPACE/docker-compose.yml" exec poppy-server init-poppy-setup + exit 0 + ;; + o) + echo "Run only Poppy Dependencies" + RUN_POPPY_DEPS=true + ;; + ?) + echo "Usage:" + echo "------" + echo " -i (Initialize Development Env) Populates config files with the values from the .env file" + echo " -a (AUTO_RUN) Start containers automatically" + echo " -e (RUN Poppy-server Init Script... runs scripts such as sni_upsert, flavor creation, etc)" + echo " -o (Only Run Dependencies) Like '-p' but will not start the poppy-server or poppy-worker services" + exit 0 + ;; + esac +done - find "$WORKSPACE/requirements" -name "*.txt" -exec cat "{}" \; | sort -# Check for a "dev" poppy config first, fall back to generating a new one from .env -if [ -f "$HOME/.poppy/poppy-dev.conf" ]; then - cp "$HOME/.poppy/poppy-dev.conf" "$WORKSPACE/docker/dev/poppy.conf" -else - if [ ! -f "$WORKSPACE/docker/dev/poppy.conf" ] || [ "$REBUILD" ]; then - echo "Running initial setup" +if [[ "$AUTO_RUN" = true ]] && [[ "$RUN_POPPY_DEPS" = true ]]; then + echo "The '-a' and '-o' flags are mutually exclusive" + exit 1 +fi + + +if [[ ! -f "$WORKSPACE/docker/dev/poppy.conf" ]] && [[ "$INIT_SETUP" = false ]]; then + echo " ** Existing poppy.conf not found -- running initial setup ** " + INIT_SETUP=true +fi + +if [[ "$INIT_SETUP" = true ]]; then + echo "Running initial setup script" + + echo "[*] copy the requirements so they can be cached within docker" + { + find "$WORKSPACE/requirements" -name "*.txt" -exec cat "{}" \; | grep -v "^-r" + cat "$WORKSPACE/doc/requirements.txt" + cat "$WORKSPACE/tests/test-requirements.txt" + } | sort | uniq | tee "$WORKSPACE/docker/dev/dev-requirements.txt" + find "$WORKSPACE/requirements" -name "*.txt" -exec cat "{}" \; | sort + # Check for a "dev" poppy config first, fall back to generating a new one from .env + + if [[ -f "$HOME/.poppy/poppy-dev.conf" ]]; then + echo "[*] poppy-dev.conf found -- copying instead of generating a new config" + cp "$HOME/.poppy/poppy-dev.conf" "$WORKSPACE/docker/dev/poppy.conf" + else + echo "[*] loading vars from .env" set -a . "$WORKSPACE/.env" set +a - if [ "$(uname -s)" = "Darwin" ]; then + if [[ "$(uname -s)" = "Darwin" ]]; then # Using docker for mac unset DOCKER_HOST - if [ ! -x "/usr/local/bin/gettext" ]; then + if [[ ! -x "/usr/local/bin/gettext" ]]; then + echo "[*] installing gettext via homebrew" brew install gettext brew link gettext --force fi - if [ ! -x "/usr/local/bin/ip" ]; then + if [[ ! -x "/usr/local/bin/ip" ]]; then + echo "[*] installing iproute2mac via homebrew" brew install gettext iproute2mac fi fi @@ -44,14 +95,22 @@ else # Generate a new poppy.conf from the .env file cat poppy.conf.template | envsubst > poppy.conf fi + + + echo "Setup Complete" + echo "You can now use docker-compose as usual," + echo "or re-run this script with flags like '$0 -a' (auto run) or '$0 -o' " + echo "(dependencies only) to quickly interact with services" + echo "" fi cd "$WORKSPACE" -if [ "$AUTORUN" ]; then +if [[ "$AUTO_RUN" = true ]]; then docker-compose up --build -d - docker ps - sleep 5 - exec "$WORKSPACE/docker/dev/_init_setup.sh" - # docker-compose exec poppy-server "init-poppy-setup" +fi + +if [[ "$RUN_POPPY_DEPS" = true ]]; then + exec docker-compose up --build zookeeper cassandra + exec docker-compose -f "$WORKSPACE/docker-compose.yml" exec poppy-server init-poppy-setup fi