Add pgAdmin to the peo4c image
Install pgAdmin 9.18 in its own virtualenv and run it under gunicorn on port 5050 next to PostgreSQL and the bridge. On first start the entrypoint creates the pgAdmin login (PGADMIN_DEFAULT_EMAIL, default admin@example.com; PGADMIN_DEFAULT_PASSWORD, default POSTGRES_PASSWORD) and registers the bundled PostgreSQL server. pgAdmin is optional (PEO4C_PGADMIN=false) and a failure in it does not stop the container. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
47b8f5f746
commit
e72af59401
4 files changed
+98
-20
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# Runs PostgreSQL (through the stock postgres entrypoint) and the peo4c bridge
|
||||
# side by side, and stops the container when either of them exits.
|
||||
# Runs PostgreSQL (through the stock postgres entrypoint), the peo4c bridge and
|
||||
# pgAdmin side by side. The container stops when PostgreSQL or the bridge exits;
|
||||
# pgAdmin is optional and its failure does not take the others down.
|
||||
set -euo pipefail
|
||||
|
||||
if [ "${1:-}" != "postgres" ]; then
|
||||
@@ -9,6 +10,31 @@ fi
|
||||
|
||||
export PEO4C_PG_DATABASE="${PEO4C_PG_DATABASE:-${POSTGRES_DB:-${POSTGRES_USER:-postgres}}}"
|
||||
|
||||
start_pgadmin() {
|
||||
local app=/opt/pgadmin/app
|
||||
local email="${PGADMIN_DEFAULT_EMAIL:-admin@example.com}"
|
||||
|
||||
if [ ! -f /var/lib/pgadmin/pgadmin4.db ]; then
|
||||
# First start: create the login user and register the bundled PostgreSQL.
|
||||
cat > /var/lib/pgadmin/servers.json <<EOF
|
||||
{"Servers": {"1": {"Name": "peo4c", "Group": "Servers", "Host": "127.0.0.1", "Port": 5432,
|
||||
"MaintenanceDB": "${PEO4C_PG_DATABASE}", "Username": "${POSTGRES_USER:-postgres}", "SSLMode": "prefer"}}}
|
||||
EOF
|
||||
chown postgres:postgres /var/lib/pgadmin/servers.json
|
||||
PGADMIN_SETUP_EMAIL="$email" \
|
||||
PGADMIN_SETUP_PASSWORD="${PGADMIN_DEFAULT_PASSWORD:-${POSTGRES_PASSWORD:-}}" \
|
||||
gosu postgres /opt/pgadmin/bin/python "$app/setup.py" setup-db \
|
||||
&& gosu postgres /opt/pgadmin/bin/python "$app/setup.py" load-servers \
|
||||
/var/lib/pgadmin/servers.json --user "$email" \
|
||||
|| { rm -f /var/lib/pgadmin/pgadmin4.db; return 1; }
|
||||
fi
|
||||
|
||||
gosu postgres /opt/pgadmin/bin/gunicorn --bind "0.0.0.0:${PEO4C_PGADMIN_PORT}" \
|
||||
--workers 1 --threads 25 --timeout 0 --chdir "$app" --log-level warning pgAdmin4:app &
|
||||
pgadmin_pid=$!
|
||||
echo "peo4c: pgAdmin on http://localhost:${PEO4C_PGADMIN_PORT}/ (login: $email)"
|
||||
}
|
||||
|
||||
docker-entrypoint.sh "$@" &
|
||||
pg_pid=$!
|
||||
|
||||
@@ -16,16 +42,22 @@ cd /opt/peo4c/bridge
|
||||
gosu postgres python3 -m peo4c &
|
||||
bridge_pid=$!
|
||||
|
||||
pgadmin_pid=
|
||||
if [ "${PEO4C_PGADMIN}" = "true" ]; then
|
||||
start_pgadmin || echo "peo4c: WARNING: pgAdmin setup failed, continuing without it" >&2
|
||||
fi
|
||||
|
||||
shutdown() {
|
||||
kill -TERM "$bridge_pid" 2>/dev/null || true
|
||||
kill -TERM "$pg_pid" 2>/dev/null || true
|
||||
for pid in "$bridge_pid" $pgadmin_pid "$pg_pid"; do
|
||||
kill -TERM "$pid" 2>/dev/null || true
|
||||
done
|
||||
}
|
||||
trap shutdown TERM INT
|
||||
|
||||
# Wait until one of the two processes exits, then stop the other one too.
|
||||
# Wait until PostgreSQL or the bridge exits, then stop everything.
|
||||
set +e
|
||||
wait -n "$pg_pid" "$bridge_pid"
|
||||
status=$?
|
||||
shutdown
|
||||
wait "$pg_pid" 2>/dev/null
|
||||
wait 2>/dev/null
|
||||
exit "$status"
|
||||
Reference in new issue
Block a user