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

112 lines
3.1 KiB
Bash
Raw Normal View History

2018-07-31 11:30:21 -04:00
#!/usr/bin/env bash
#####################################################################################################
# Starts up the api, portal, and dependent services via
# docker-compose. The api will be available on localhost:9000 and the
# portal will be on localhost:9001
#
# Relevant overrides can be found at ./.env and ../docker/.env
#
# Options:
# -t, --timeout seconds: overwrite ping timeout, default of 60
# -a, --api-only: only starts up vinyldns-api and its dependencies, excludes vinyldns-portal
# -c, --clean: re-pull vinyldns/api and vinyldns/portal images from docker hub
# -v, --version tag: overwrite vinyldns/api and vinyldns/portal docker tags
#####################################################################################################
2018-07-31 11:30:21 -04:00
function wait_for_url {
echo "pinging ${URL} ..."
DATA=""
RETRY="$TIMEOUT"
while [ "$RETRY" -gt 0 ]
do
DATA=$(curl -I -s "${URL}" -o /dev/null -w "%{http_code}")
if [ $? -eq 0 ]
then
echo "Succeeded in connecting to ${URL}!"
break
else
echo "Retrying" >&2
let RETRY-=1
sleep 1
if [ "$RETRY" -eq 0 ]
then
echo "Exceeded retries waiting for ${URL} to be ready, failing"
exit 1
fi
fi
done
}
function usage {
printf "usage: docker-up-vinyldns.sh [OPTIONS]\n\n"
printf "starts up a local VinylDNS installation using docker compose\n\n"
printf "options:\n"
printf "\t-t, --timeout seconds: overwrite ping timeout of 60\n"
printf "\t-a, --api-only: do not start up vinyldns-portal\n"
printf "\t-c, --clean: re-pull vinyldns/api and vinyldns/portal images from docker hub\n"
printf "\t-v, --version tag: overwrite vinyldns/api and vinyldns/portal docker tags\n"
}
function clean_images {
if (( $CLEAN == 1 )); then
echo "cleaning docker images..."
Support non ActiveDirectory LDAP (#859) Support non ActiveDirectory LDAP This PR has an optional local portal setup against this docker container - https://github.com/rroemhild/docker-test-openldap The base modifications for LDAP was to change the actual authentication flow. Before, we only attempted to bind (setting up a DirContext and relying on an exception). We would test all of the search bases until we exhausted the list. The new approach works differently: 1. First, login using the main service account 2. Second, do a lookup of the user 3. Finally, attempt to bind to that user's context directly using the password provided. This works fine with both AD LDAP as well as the example docker container which uses OpenLDAP Besides these changes, need to make configurable the userNameField, which is the ldap attribute that is used to search for the username sent in the login screen. In AD, this is `sAMAccountName`, but in the example it is `uid`, the logon field is up to the way LDAP is setup - `docker-up-vinyldns.sh` - fixed a quote issue with the startup script to properly send in the version of vinyldns - `docker-compose-build.yml` - added the `ldap` container so the portal can connect as `vinyldns-ldap` - `docker/portal/application.conf` - new config file so that we can connect to the new ldap container - `docker-compose.yml` - added the `ldap` container here as well so we can play with it using `reStart` in sbt instead of `docker-up-vinyldns.sh` - simplifies local testing - `LdapAuthenticator.scala` - this is where the main changes happen
2019-10-08 19:13:15 -04:00
docker rmi vinyldns/api:$VINYLDNS_VERSION
docker rmi vinyldns/portal:$VINYLDNS_VERSION
fi
}
function wait_for_api {
echo "Waiting for api..."
URL="$VINYLDNS_API_URL"
wait_for_url
}
function wait_for_portal {
# check if portal was skipped
if [ "$SERVICE" != "api" ]; then
echo "Waiting for portal..."
URL="$VINYLDNS_PORTAL_URL"
wait_for_url
fi
}
2018-07-31 11:30:21 -04:00
# initial var setup
DIR=$( cd $(dirname $0) ; pwd -P )
TIMEOUT=60
Support building docker images locally and without SBT (#753) Fixes #744 Overhauls our docker release process to run releases of docker outside of SBT. This was tested through the signing process deploying SNAPSHOT images to docker hub. All images do a git clone to pull vinyldns, and perform the build of the container based on that git clone. - A new `build` directory contains the things to be built, for this PR only the docker images are here. Anticipate possibly pulling in other artifacts in the future. - `build/docker` contains all of the docker setup - `build/docker/test` contains a func test docker image that can be used to test any VinylDNS API instance - `build/docker/test-bind9` contains our bind9 setup - `build/docker/api` is a MySQL only API distribution - `build/docker/portal` is a MySQL only Portal distribution In addition, a few files are added to make the build easier: - `build/start.sh` starts a given vinyldns version - `build/stop.sh` stops the current running vinyldns setup - `build/release.sh` this is the **MAIN** guy that performs the build. Lots of arguments that are useful for testing. Can provide a repository (for publishing to a docker register that is not docker hub), for building clean vs. assuming docker images. Besides building everything, also runs func tests (smoke tests) against the docker image before completing. Added a `README.md` for others to follow along with To test.. 1. Make sure you increase your docker machine settings to 4GB (the default of 2GB failed) 2. Go to the `build` directory 3. From there, run `./release.sh -c -t 111` to only build the docker images, this should build `0.9.4-b111` 4. Start it up, run `./start.sh -v 0.9.4-b111` 5. Login to the portal at http://localhost:9001 6. When finished, run `./stop.sh` from the build directory *If you see an error code 137 error, you need to increase your memory*
2019-10-22 19:11:28 -04:00
DOCKER_COMPOSE_CONFIG="${DIR}/../docker/docker-compose-quick-start.yml"
# empty service starts up all docker services in compose file
SERVICE=""
# when CLEAN is set to 1, existing docker images are deleted so they are re-pulled
CLEAN=0
# source env before parsing args so vars can be overwritten
set -a # Required in order to source docker/.env
# Source customizable env files
source "$DIR"/.env
source "$DIR"/../docker/.env
# parse args
while [ "$1" != "" ]; do
case "$1" in
-t | --timeout ) TIMEOUT="$2"; shift;;
-a | --api-only ) SERVICE="api";;
-c | --clean ) CLEAN=1;;
Support non ActiveDirectory LDAP (#859) Support non ActiveDirectory LDAP This PR has an optional local portal setup against this docker container - https://github.com/rroemhild/docker-test-openldap The base modifications for LDAP was to change the actual authentication flow. Before, we only attempted to bind (setting up a DirContext and relying on an exception). We would test all of the search bases until we exhausted the list. The new approach works differently: 1. First, login using the main service account 2. Second, do a lookup of the user 3. Finally, attempt to bind to that user's context directly using the password provided. This works fine with both AD LDAP as well as the example docker container which uses OpenLDAP Besides these changes, need to make configurable the userNameField, which is the ldap attribute that is used to search for the username sent in the login screen. In AD, this is `sAMAccountName`, but in the example it is `uid`, the logon field is up to the way LDAP is setup - `docker-up-vinyldns.sh` - fixed a quote issue with the startup script to properly send in the version of vinyldns - `docker-compose-build.yml` - added the `ldap` container so the portal can connect as `vinyldns-ldap` - `docker/portal/application.conf` - new config file so that we can connect to the new ldap container - `docker-compose.yml` - added the `ldap` container here as well so we can play with it using `reStart` in sbt instead of `docker-up-vinyldns.sh` - simplifies local testing - `LdapAuthenticator.scala` - this is where the main changes happen
2019-10-08 19:13:15 -04:00
-v | --version ) export VINYLDNS_VERSION=$2; shift;;
* ) usage; exit;;
esac
shift
done
clean_images
2018-07-31 11:30:21 -04:00
echo "timeout is set to ${TIMEOUT}"
Support non ActiveDirectory LDAP (#859) Support non ActiveDirectory LDAP This PR has an optional local portal setup against this docker container - https://github.com/rroemhild/docker-test-openldap The base modifications for LDAP was to change the actual authentication flow. Before, we only attempted to bind (setting up a DirContext and relying on an exception). We would test all of the search bases until we exhausted the list. The new approach works differently: 1. First, login using the main service account 2. Second, do a lookup of the user 3. Finally, attempt to bind to that user's context directly using the password provided. This works fine with both AD LDAP as well as the example docker container which uses OpenLDAP Besides these changes, need to make configurable the userNameField, which is the ldap attribute that is used to search for the username sent in the login screen. In AD, this is `sAMAccountName`, but in the example it is `uid`, the logon field is up to the way LDAP is setup - `docker-up-vinyldns.sh` - fixed a quote issue with the startup script to properly send in the version of vinyldns - `docker-compose-build.yml` - added the `ldap` container so the portal can connect as `vinyldns-ldap` - `docker/portal/application.conf` - new config file so that we can connect to the new ldap container - `docker-compose.yml` - added the `ldap` container here as well so we can play with it using `reStart` in sbt instead of `docker-up-vinyldns.sh` - simplifies local testing - `LdapAuthenticator.scala` - this is where the main changes happen
2019-10-08 19:13:15 -04:00
echo "vinyldns version is set to '${VINYLDNS_VERSION}'"
2018-07-31 11:30:21 -04:00
echo "Starting vinyldns and all dependencies in the background..."
docker-compose -f "$DOCKER_COMPOSE_CONFIG" up -d ${SERVICE}
2018-07-31 11:30:21 -04:00
wait_for_api
wait_for_portal