Skip to content

Commit 5cb1ef6

Browse files
committed
keep the password reset logic for self-hosting
1 parent da71ab4 commit 5cb1ef6

2 files changed

Lines changed: 81 additions & 2 deletions

File tree

docker/docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ services:
386386
# Comment out everything below this point if you are using an external Postgres database
387387
db:
388388
container_name: supabase-db
389-
image: supabase/postgres:15.8.1.060
389+
image: supabase/postgres:15-local
390390
restart: unless-stopped
391391
volumes:
392+
- ./docker-entrypoint.sh:/usr/local/bin/custom-docker-entrypoint.sh:Z
392393
- ./volumes/db/realtime.sql:/docker-entrypoint-initdb.d/migrations/99-realtime.sql:Z
393394
# Must be superuser to create event trigger
394395
- ./volumes/db/webhooks.sql:/docker-entrypoint-initdb.d/init-scripts/98-webhooks.sql:Z
@@ -432,7 +433,7 @@ services:
432433
POSTGRES_DB: ${POSTGRES_DB}
433434
JWT_SECRET: ${JWT_SECRET}
434435
JWT_EXP: ${JWT_EXPIRY}
435-
ROLES_INIT_SCRIPT_PATH: /docker-entrypoint-initdb.d/init-scripts/99-roles.sql
436+
entrypoint: /usr/local/bin/custom-docker-entrypoint.sh
436437
command:
437438
[
438439
"postgres",

docker/docker-entrypoint.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
set -Eeo pipefail
3+
4+
source /usr/local/bin/docker-entrypoint.sh
5+
6+
# sync $POSTGRES_PASSWORD to supabase-specific roles
7+
pg_sync_password() {
8+
# Wait for PostgreSQL to be ready with timeout
9+
timeout 30s bash -c 'until pg_isready -h localhost >/dev/null 2>&1; do
10+
echo "Waiting for PostgreSQL to be ready..."
11+
sleep 1
12+
done' || {
13+
echo "Timeout waiting for PostgreSQL to be ready after 30 seconds"
14+
return 1
15+
}
16+
17+
# Connect via TCP/IP to localhost and alter the supabase_admin password
18+
psql -h localhost -U supabase_admin <<-'EOSQL'
19+
\set pgpass `echo "$POSTGRES_PASSWORD"`
20+
ALTER USER supabase_admin WITH PASSWORD :'pgpass';
21+
EOSQL
22+
23+
# execute the roles SQL file using psql
24+
psql -h localhost -U supabase_admin -f "/docker-entrypoint-initdb.d/init-scripts/99-roles.sql"
25+
}
26+
27+
_main() {
28+
# if first arg looks like a flag, assume we want to run postgres server
29+
if [ "${1:0:1}" = '-' ]; then
30+
set -- postgres "$@"
31+
fi
32+
33+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
34+
docker_setup_env
35+
# setup data directories and permissions (when run as root)
36+
docker_create_db_directories
37+
if [ "$(id -u)" = '0' ]; then
38+
# then restart script as postgres user
39+
exec gosu postgres "$BASH_SOURCE" "$@"
40+
fi
41+
42+
# only run initialization on an empty data directory
43+
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
44+
docker_verify_minimum_env
45+
46+
# check dir permissions to reduce likelihood of half-initialized database
47+
ls /docker-entrypoint-initdb.d/ > /dev/null
48+
49+
docker_init_database_dir
50+
pg_setup_hba_conf "$@"
51+
52+
docker_setup_db
53+
docker_process_init_files /docker-entrypoint-initdb.d/*
54+
55+
cat <<-'EOM'
56+
57+
PostgreSQL init process complete; ready for start up.
58+
59+
EOM
60+
else
61+
cat <<-'EOM'
62+
63+
PostgreSQL Database directory appears to contain a database; Skipping initialization
64+
65+
EOM
66+
fi
67+
68+
# Start pg_sync_password in the background
69+
pg_sync_password "$@" &
70+
fi
71+
72+
# Execute the main postgres command
73+
exec "$@"
74+
}
75+
76+
if ! _is_sourced; then
77+
_main "$@"
78+
fi

0 commit comments

Comments
 (0)