mirror of
https://github.com/sprockets/sprockets-dynamodb.git
synced 2024-11-14 19:29:28 +00:00
62 lines
1.5 KiB
Bash
Executable file
62 lines
1.5 KiB
Bash
Executable file
#!/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() {
|
|
docker-compose port $1 $2 | cut -d: -f2
|
|
}
|
|
|
|
build_env_file() {
|
|
cat > $1<<EOF
|
|
export AWS_DEFAULT_REGION=local
|
|
export AWS_ACCESS_KEY_ID=LOCALDEV
|
|
export AWS_SECRET_ACCESS_KEY=LOCALDEV
|
|
export DYNAMODB_ENDPOINT=http://${DOCKER_IP}:$(get_exposed_port dynamodb 7777)
|
|
EOF
|
|
}
|
|
|
|
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
|
|
docker-compose down --volumes --remove-orphans
|
|
docker-compose up -d
|
|
build_env_file build/test-environment
|
|
fi
|
|
cat build/test-environment
|