2021-12-01 12:54:34 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-11-30 14:29:10 +00:00
|
|
|
|
|
|
|
# Prepare Moonstream API application for docker-compose use
|
|
|
|
|
2021-12-01 12:38:14 +00:00
|
|
|
# Print help message
|
|
|
|
function usage {
|
|
|
|
echo "Usage: $0 [-h] -d DATABASE_NAME"
|
|
|
|
echo
|
|
|
|
echo "CLI to generate environment variables"
|
|
|
|
echo
|
|
|
|
echo "Optional arguments:"
|
|
|
|
echo " -h Show this help message and exit"
|
|
|
|
echo " -d Database name for postgres in docker-compose setup"
|
|
|
|
}
|
|
|
|
|
|
|
|
FLAG_DATABASE_NAME="moonstream_dev"
|
|
|
|
|
|
|
|
while getopts 'd:' flag; do
|
|
|
|
case "${flag}" in
|
2021-12-01 12:59:54 +00:00
|
|
|
d) FLAG_DATABASE_NAME="${OPTARG}" ;;
|
2021-12-01 12:38:14 +00:00
|
|
|
h) usage
|
|
|
|
exit 1 ;;
|
|
|
|
*) usage
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-11-30 14:29:10 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(realpath $(dirname $0))"
|
2021-12-01 12:38:14 +00:00
|
|
|
DOCKER_MOONSTREAM_DB_URI="postgresql://postgres:postgres@db/$FLAG_DATABASE_NAME"
|
2021-11-30 14:29:10 +00:00
|
|
|
DOCKER_MOONSTREAM_ENV_FILE="docker.moonstreamapi.env"
|
2021-12-01 20:40:43 +00:00
|
|
|
BUGOUT_BROOD_URL="http://brood:7474"
|
|
|
|
BUGOUT_SPIRE_URL="http://spire:7475"
|
2021-11-30 14:29:10 +00:00
|
|
|
|
|
|
|
# Generate environment variables
|
|
|
|
|
|
|
|
cp "$SCRIPT_DIR/sample.env" "$SCRIPT_DIR/$DOCKER_MOONSTREAM_ENV_FILE"
|
|
|
|
|
|
|
|
# Clean file with variables from export prefix and quotation marks
|
|
|
|
sed --in-place 's|^export * ||' "$SCRIPT_DIR/$DOCKER_MOONSTREAM_ENV_FILE"
|
|
|
|
sed --in-place 's|"||g' "$SCRIPT_DIR/$DOCKER_MOONSTREAM_ENV_FILE"
|
|
|
|
|
|
|
|
sed -i "s|^MOONSTREAM_DB_URI=.*|MOONSTREAM_DB_URI=$DOCKER_MOONSTREAM_DB_URI|" "$SCRIPT_DIR/$DOCKER_MOONSTREAM_ENV_FILE"
|
2021-12-01 20:40:43 +00:00
|
|
|
sed -i "s|^BUGOUT_BROOD_URL=.*|BUGOUT_BROOD_URL=$BUGOUT_BROOD_URL|" "$SCRIPT_DIR/$DOCKER_MOONSTREAM_ENV_FILE"
|
|
|
|
sed -i "s|^BUGOUT_SPIRE_URL=.*|BUGOUT_SPIRE_URL=$BUGOUT_SPIRE_URL|" "$SCRIPT_DIR/$DOCKER_MOONSTREAM_ENV_FILE"
|