sprockets-dynamodb/bootstrap

63 lines
1.5 KiB
Text
Raw Permalink Normal View History

2016-09-26 20:46:55 +00:00
#!/bin/sh
#
# NAME
# bootstrap -- initialize/update docker environment
#
# SYNOPSIS
# bootstrap
# bootstrap shellinit
#
# DESCRIPTION
# Execute this script without parameters to build the local docker
# environment. Once bootstrapped, dependent services are running
# via docker-compose and the environment variables are written to
# *build/test-environment* for future use.
#
# Running this script with the _shellinit_ command line parameter
# causes it to simply interrogate the running docker environment,
# update *build/test-environment*, and print the environment to
# the standard output stream in a shell executable manner. This
# makes the following pattern for setting environment variables
# in the current shell work.
#
# prompt% $(./bootstrap shellinit)
#
# vim: set ts=2 sts=2 sw=2 et:
PROJECT=sprockets
if test -e /var/run/docker.sock
then
DOCKER_IP=127.0.0.1
else
echo "Failed to initialize docker environment"
exit 2
fi
get_exposed_port() {
2018-01-10 22:41:07 +00:00
docker-compose port $1 $2 | cut -d: -f2
2016-09-26 20:46:55 +00:00
}
build_env_file() {
2018-01-10 22:41:07 +00:00
cat > $1<<EOF
export AWS_DEFAULT_REGION=local
export AWS_ACCESS_KEY_ID=LOCALDEV
export AWS_SECRET_ACCESS_KEY=LOCALDEV
2018-01-10 22:41:07 +00:00
export DYNAMODB_ENDPOINT=http://${DOCKER_IP}:$(get_exposed_port dynamodb 7777)
EOF
2016-09-26 20:46:55 +00:00
}
set -e
mkdir -p build
if test "$1" = 'shellinit'
then
# just build the environment file from docker containers
build_env_file build/test-environment
else
2018-01-10 22:41:07 +00:00
docker-compose down --volumes --remove-orphans
docker-compose up -d
2016-09-26 20:46:55 +00:00
build_env_file build/test-environment
fi
cat build/test-environment