Some checks failed
CI / test-and-build (push) Failing after 25s
Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.4 KiB
Bash
47 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
# Allow Docker containers to reach host Postgres via host.docker.internal.
|
|
set -euo pipefail
|
|
cd ~/games_app
|
|
|
|
PG_CONF=$(ls /etc/postgresql/*/main/postgresql.conf | head -1)
|
|
PG_HBA=$(ls /etc/postgresql/*/main/pg_hba.conf | head -1)
|
|
|
|
echo "Using $PG_CONF"
|
|
if sudo grep -qE '^\s*listen_addresses\s*=' "$PG_CONF"; then
|
|
sudo sed -i -E "s/^\s*listen_addresses\s*=.*/listen_addresses = '*'/" "$PG_CONF"
|
|
else
|
|
echo "listen_addresses = '*'" | sudo tee -a "$PG_CONF" >/dev/null
|
|
fi
|
|
|
|
if ! sudo grep -q 'tloto-docker-bridge' "$PG_HBA"; then
|
|
sudo tee -a "$PG_HBA" >/dev/null <<'HBA'
|
|
|
|
# tloto-docker-bridge — Docker → host Postgres (UFW still blocks public :5432)
|
|
host all all 172.16.0.0/12 scram-sha-256
|
|
host all all 192.168.0.0/16 scram-sha-256
|
|
HBA
|
|
fi
|
|
|
|
sudo systemctl restart postgresql
|
|
sleep 2
|
|
sudo ss -tlnp | grep 5432
|
|
|
|
PGPASS=$(python3 - <<'PY'
|
|
import re
|
|
from pathlib import Path
|
|
m=re.search(r'^POSTGRES_PASSWORD=(.*)$', Path('.env').read_text(), re.M)
|
|
print(m.group(1).strip() if m else '')
|
|
PY
|
|
)
|
|
export PGPASSWORD="$PGPASS"
|
|
|
|
echo "Local check:"
|
|
psql -h 127.0.0.1 -U postgres -d games_platform_db -c 'SELECT 1 AS local_ok;'
|
|
|
|
echo "Docker check:"
|
|
sudo docker run --rm --add-host=host.docker.internal:host-gateway \
|
|
-e PGPASSWORD="$PGPASS" postgres:16-alpine \
|
|
psql -h host.docker.internal -U postgres -d games_platform_db -c 'SELECT 1 AS docker_ok;'
|
|
|
|
echo "PG_DOCKER_OK"
|