#!/bin/sh # Generate local synthetic credentials into ./secrets (git-ignored). Idempotent: # existing files are kept, so a running stack keeps working. Prints no secret values. set -eu cd "$(dirname "$0")/.." mkdir -p secrets gen() { python3 -c 'import secrets; print(secrets.token_hex(24))'; } if [ ! -f secrets/postgres_password ]; then gen > secrets/postgres_password echo "created secrets/postgres_password" fi PG_PASS=$(cat secrets/postgres_password) printf 'postgresql://messenger:%s@postgres:5432/messenger\n' "$PG_PASS" > secrets/database_url if [ ! -f secrets/valkey.conf ]; then { printf 'requirepass %s\n' "$(gen)" # Pure cache: PostgreSQL holds the sessions, so no RDB/AOF is needed. printf 'save ""\nappendonly no\n' printf 'maxmemory 64mb\nmaxmemory-policy volatile-lru\n' } > secrets/valkey.conf echo "created secrets/valkey.conf" fi VK_PASS=$(sed -n 's/^requirepass //p' secrets/valkey.conf) printf 'redis://:%s@valkey:6379/0\n' "$VK_PASS" > secrets/cache_url # Containers run as non-root users that do not own these files on Linux. chmod 644 secrets/* echo "secrets ready in ./secrets (not tracked by git)"