Skip to content

Commit 82d116e

Browse files
committed
[wip] docs: update self-hosting supabase file
1 parent f600ce0 commit 82d116e

File tree

1 file changed

+64
-12
lines changed

1 file changed

+64
-12
lines changed

docs/postgresql/SELF_HOSTING_SUPABASE_FLYIO.md

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,29 @@ sh ./utils/generate-keys.sh
314314
315315
Review the output. The script updates `.env` with generated `JWT_SECRET`, `ANON_KEY`, and `SERVICE_ROLE_KEY`.
316316
317+
### 6a.1. Get the JWT secret later
318+
319+
If you need the Supabase Auth JWT secret after setup, read the `JWT_SECRET` value from the same `.env` file used by Docker Compose:
320+
321+
```bash
322+
cd /data/supabase-docker
323+
grep '^JWT_SECRET=' .env
324+
```
325+
326+
That value is the secret GoTrue (Supabase Auth) uses to sign and verify access tokens.
327+
328+
If you want to confirm what the running auth container sees, check the container environment:
329+
330+
```bash
331+
docker compose exec auth printenv GOTRUE_JWT_SECRET
332+
```
333+
334+
Both commands should return the same value. If they do not, restart the stack after updating `.env`:
335+
336+
```bash
337+
docker compose up -d
338+
```
339+
317340
### 6b. Edit `.env` manually for remaining values
318341
319342
```bash
@@ -579,24 +602,44 @@ export ORG_API_KEY="<your-org-api-key>" # Organization
579602
580603
#### Connection string
581604
582-
The CloudSync server needs to connect to your PostgreSQL database. Since both the CloudSync server and the Supabase VM are in the same Fly org, they can communicate over Fly's **private internal network** using `.internal` addresses — no public port exposure needed.
605+
The CloudSync server needs a PostgreSQL connection string to reach your database. There are two options depending on where your CloudSync server runs:
583606
584-
The connection goes through **Supavisor** (Supabase's connection pooler) in session mode. The username format is `postgres.<POOLER_TENANT_ID>` (check your `.env` for `POOLER_TENANT_ID`).
607+
**Option A: CloudSync on the same Fly org (`.internal` network)**
608+
609+
If both the CloudSync server and the Supabase VM are in the same Fly org, they can communicate over Fly's **private internal network** — no public port exposure needed. Connect directly to the `db` container's mapped port (5432 is exposed on the host by default in docker-compose):
585610
586611
```bash
587-
# Connection string format:
588-
# postgres://postgres.<POOLER_TENANT_ID>:<POSTGRES_PASSWORD>@<fly-app-name>.internal:5432/postgres
612+
# Direct connection (no Supavisor) — recommended for CloudSync server-to-server
613+
export CONNECTION_STRING="postgres://postgres:$POSTGRES_PASSWORD@<your-fly-app-name>.internal:5432/postgres"
614+
```
615+
616+
**Option B: CloudSync running outside Fly (e.g., local machine, another cloud)**
617+
618+
Use `fly proxy` to tunnel the Postgres port to your local machine:
589619
590-
export CONNECTION_STRING="postgres://postgres.cloudsync-supabase-test:$POSTGRES_PASSWORD@cloudsync-supabase-test.internal:5432/postgres"
620+
```bash
621+
# In a separate terminal — keep this running
622+
fly proxy 5432:5432 -a <your-fly-app-name>
591623
```
592624
593-
To verify the connection works, SSH into the VM and test through Supavisor:
625+
This makes the remote Postgres available at `localhost:5432`. Then use:
594626
595627
```bash
596-
docker compose exec db psql "postgres://postgres.cloudsync-supabase-test:<POSTGRES_PASSWORD>@supabase-pooler:5432/postgres" -c "SELECT 1;"
628+
export CONNECTION_STRING="postgres://postgres:$POSTGRES_PASSWORD@localhost:5432/postgres"
597629
```
598630
599-
> **Note:** Inside Docker, use the container name `supabase-pooler` instead of the `.internal` address. The `.internal` address is for Fly-to-Fly communication.
631+
> **Note:** The proxy must stay running in a separate terminal for the duration of your session. If the proxy disconnects, just re-run the command.
632+
633+
To verify the connection works:
634+
635+
```bash
636+
# Option A: SSH into the VM and test locally
637+
fly ssh console --app <your-fly-app-name>
638+
docker compose exec db psql -U postgres -c "SELECT 1;"
639+
640+
# Option B: With fly proxy running, test from your local machine
641+
psql "postgres://postgres:$POSTGRES_PASSWORD@localhost:5432/postgres" -c "SELECT 1;"
642+
```
600643
601644
### 10a. Verify CloudSync server is reachable
602645
@@ -745,20 +788,29 @@ grep DASHBOARD /data/supabase-docker/.env
745788
746789
The values are `DASHBOARD_USERNAME` (default: `supabase`) and `DASHBOARD_PASSWORD` (default: `this_password_is_insecure_and_should_be_updated`).
747790
748-
> **Note:** Since the Fly VM doesn't expose ports publicly, access Studio via SSH tunnel:
791+
> **Note:** The Fly VM doesn't expose ports publicly by default. Use `fly proxy` to access services from your local machine:
749792
> ```bash
750-
> fly proxy 8000:8000 -a cloudsync-supabase-test
793+
> fly proxy 8000:8000 -a <your-app-name>
751794
> ```
752795
> Then open `http://localhost:8000` in your browser.
753796
754797
### Connect to Postgres directly
755798
756-
Via Supavisor (connection pooler):
799+
Use `fly proxy` to tunnel the Postgres port to your local machine:
757800
758801
```bash
759-
psql 'postgres://postgres.your-tenant-id:<POSTGRES_PASSWORD>@<your-fly-ip>:5432/postgres'
802+
# In a separate terminal — keep this running
803+
fly proxy 5432:5432 -a <your-app-name>
760804
```
761805
806+
Then connect from your local machine:
807+
808+
```bash
809+
psql 'postgres://postgres:<POSTGRES_PASSWORD>@localhost:5432/postgres'
810+
```
811+
812+
> **Tip:** You can proxy multiple ports at once by running multiple `fly proxy` commands in separate terminals (e.g., `8000` for Studio and `5432` for Postgres).
813+
762814
---
763815
764816
## Step 11: Set up HTTPS (production)

0 commit comments

Comments
 (0)