Run setup scripts after environment setup

This commit is contained in:
Matthew Lopez 2023-12-20 18:14:01 -05:00
parent fe3cfdb439
commit 8237dc90e9
No known key found for this signature in database
GPG Key ID: 302A6EE3D63B7E0E
4 changed files with 24 additions and 16 deletions

View File

@ -19,4 +19,4 @@ done
docker compose exec mongodb mongosh --eval "$mongodb_init_script"
docker compose down mongodb
docker compose down

View File

@ -2,6 +2,9 @@
set -eu
# Stop all running containers so the new environment variable can be applied
docker compose down
generate_password() {
length=$1
tr -dc 'a-zA-Z0-9' </dev/urandom | fold -w "$length" | head -n 1
@ -17,17 +20,6 @@ echo "Setting up local environment variables..."
git_base=$(git rev-parse --show-toplevel)
cd "$git_base/environment"
postgres_password=""
if [ -f ./postgres.local.env ]; then
# Changing the Postgres password doesn't apply to the database if it's
# already created, and changing now it would break the other servers
. ./postgres.local.env
if [ -n "${POSTGRES_PASSWORD-}" ]; then
echo "Using existing Postgres password"
postgres_password=$POSTGRES_PASSWORD
fi
fi
rm ./*.local.env || true
# Generate an AES-256-CBC key for account server tokens
@ -51,9 +43,7 @@ mongo_express_password=$(generate_password 32)
echo "ME_CONFIG_BASICAUTH_PASSWORD=$mongo_express_password" >>./mongo-express.local.env
# Generate a password for Postgres
if [ -z "${postgres_password-}" ]; then
postgres_password=$(generate_password 32)
fi
postgres_password=$(generate_password 32)
echo "POSTGRES_PASSWORD=$postgres_password" >>./postgres.local.env
echo "PN_FRIENDS_CONFIG_DATABASE_URI=postgres://postgres_pretendo:$postgres_password@postgres/friends?sslmode=disable" >>./friends.local.env
@ -77,3 +67,8 @@ read -r wiiu_ip
echo "WIIU_IP=$wiiu_ip" >>./system.local.env
echo "Successfully set up environment."
# Some things need to be updated with the new environment variables and secrets
echo "Running necessary scripts..."
"$git_base"/scripts/update-postgres-password.sh
"$git_base"/scripts/setup-account-servers-database.sh

View File

@ -9,4 +9,4 @@ docker compose up -d minio
docker compose exec minio sh -c "$minio_init_script"
docker compose down minio
docker compose down

View File

@ -0,0 +1,13 @@
#! /bin/sh
set -eu
git_base=$(git rev-parse --show-toplevel)
. "$git_base/environment/postgres.env"
. "$git_base/environment/postgres.local.env"
docker compose up -d postgres
docker compose exec postgres psql -U "$POSTGRES_USER" -c "ALTER USER $POSTGRES_USER PASSWORD '$POSTGRES_PASSWORD';"
docker compose down