From 7eb5108a475ea8cf6895b12a6be72355fa9995ce Mon Sep 17 00:00:00 2001 From: Matthew Lopez <73856503+MatthewL246@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:53:29 -0500 Subject: [PATCH] Set up Postgres server for friends --- compose.yml | 33 +++++++++++++++++++++++++++++++++ config/postgres-init.sh | 12 ++++++++++++ environment/adminer.env | 1 + environment/postgres.env | 1 + scripts/setup-environment.sh | 5 +++++ 5 files changed, 52 insertions(+) create mode 100644 config/postgres-init.sh create mode 100644 environment/adminer.env create mode 100644 environment/postgres.env diff --git a/compose.yml b/compose.yml index 3a34b1d..9c78ca0 100644 --- a/compose.yml +++ b/compose.yml @@ -137,6 +137,38 @@ services: networks: internal: + postgres: + image: postgres:alpine + depends_on: + - coredns + volumes: + - type: volume + source: postgres-database + target: /var/lib/postgresql/data + - type: bind + source: ./config/postgres-init.sh + target: /docker-entrypoint-initdb.d/postgres-init.sh + env_file: + - ./environment/postgres.env + - ./environment/postgres.local.env + dns: 172.20.0.2 + networks: + internal: + + adminer: + image: adminer:latest + depends_on: + - coredns + - postgres + ports: + # For the Adminer web interface + - 127.0.0.1:8091:8080 + env_file: + - ./environment/adminer.env + dns: 172.20.0.2 + networks: + internal: + account: build: ./repos/account depends_on: @@ -182,6 +214,7 @@ volumes: minio-s3-data: redis-data: maildev-mail: + postgres-database: account-certificates: networks: diff --git a/config/postgres-init.sh b/config/postgres-init.sh new file mode 100644 index 0000000..dbfabec --- /dev/null +++ b/config/postgres-init.sh @@ -0,0 +1,12 @@ +#! /bin/sh + +set -eu + +databases="friends" + +for database in $databases; do + echo "Creating database: $database" + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL + CREATE DATABASE $database; +EOSQL +done diff --git a/environment/adminer.env b/environment/adminer.env new file mode 100644 index 0000000..8f10c43 --- /dev/null +++ b/environment/adminer.env @@ -0,0 +1 @@ +ADMINER_DEFAULT_SERVER=postgres diff --git a/environment/postgres.env b/environment/postgres.env new file mode 100644 index 0000000..fa1e0c7 --- /dev/null +++ b/environment/postgres.env @@ -0,0 +1 @@ +POSTGRES_USER=postgres_pretendo diff --git a/scripts/setup-environment.sh b/scripts/setup-environment.sh index 13e15b5..4d308d7 100755 --- a/scripts/setup-environment.sh +++ b/scripts/setup-environment.sh @@ -28,6 +28,11 @@ echo "MINIO_ROOT_PASSWORD=$minio_secret_key" >>./minio.local.env mongo_express_password=$(openssl rand -base64 32) echo "ME_CONFIG_BASICAUTH_PASSWORD=$mongo_express_password" >>./mongo-express.local.env +# Generate a password for Postgres +postgres_password=$(openssl rand -base64 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 + # Get the Wii U IP address printf "Enter your Wii U's IP address: " read -r wiiu_ip