|
| 1 | +# Deploying CloudSync to Self-Hosted Supabase on Fly.io |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Build a custom Supabase Postgres image with CloudSync baked in, push it to a container registry, and configure your Fly.io Supabase deployment to use it. |
| 6 | + |
| 7 | +## Step-by-step |
| 8 | + |
| 9 | +### 1. Build the custom Supabase Postgres image |
| 10 | + |
| 11 | +The project includes `docker/postgresql/Dockerfile.supabase` which builds CloudSync into the Supabase Postgres base image. Match the tag to the PG version your Fly.io Supabase uses: |
| 12 | + |
| 13 | +```bash |
| 14 | +# Build with the default Supabase Postgres tag (17.6.1.071) |
| 15 | +make postgres-supabase-build |
| 16 | + |
| 17 | +# Or specify the exact tag your Fly deployment uses: |
| 18 | +make postgres-supabase-build SUPABASE_POSTGRES_TAG=17.6.1.071 |
| 19 | +``` |
| 20 | + |
| 21 | +This produces a Docker image tagged as `public.ecr.aws/supabase/postgres:<tag>` locally. |
| 22 | + |
| 23 | +### 2. Tag and push to a container registry |
| 24 | + |
| 25 | +You need a registry accessible from Fly.io (Docker Hub, GitHub Container Registry, or Fly's own registry): |
| 26 | + |
| 27 | +```bash |
| 28 | +# Tag for your registry |
| 29 | +docker tag public.ecr.aws/supabase/postgres:17.6.1.071 \ |
| 30 | + registry.fly.io/<your-app>/postgres-cloudsync:17.6.1.071 |
| 31 | + |
| 32 | +# Push |
| 33 | +docker push registry.fly.io/<your-app>/postgres-cloudsync:17.6.1.071 |
| 34 | +``` |
| 35 | + |
| 36 | +Or use Docker Hub / GHCR: |
| 37 | + |
| 38 | +```bash |
| 39 | +docker tag public.ecr.aws/supabase/postgres:17.6.1.071 \ |
| 40 | + ghcr.io/<your-org>/supabase-postgres-cloudsync:17.6.1.071 |
| 41 | +docker push ghcr.io/<your-org>/supabase-postgres-cloudsync:17.6.1.071 |
| 42 | +``` |
| 43 | + |
| 44 | +### 3. Update your Fly.io Supabase deployment |
| 45 | + |
| 46 | +In your Fly.io Supabase config (`fly.toml` or however you deployed the DB service), point the Postgres image to your custom image: |
| 47 | + |
| 48 | +```toml |
| 49 | +[build] |
| 50 | + image = "ghcr.io/<your-org>/supabase-postgres-cloudsync:17.6.1.071" |
| 51 | +``` |
| 52 | + |
| 53 | +Then redeploy: |
| 54 | + |
| 55 | +```bash |
| 56 | +fly deploy --app <your-supabase-db-app> |
| 57 | +``` |
| 58 | + |
| 59 | +### 4. Enable the extension |
| 60 | + |
| 61 | +Connect to your Fly Postgres instance and enable CloudSync: |
| 62 | + |
| 63 | +```bash |
| 64 | +fly postgres connect --app <your-supabase-db-app> |
| 65 | +``` |
| 66 | + |
| 67 | +```sql |
| 68 | +CREATE EXTENSION cloudsync; |
| 69 | +SELECT cloudsync_version(); |
| 70 | + |
| 71 | +-- Initialize sync on a table |
| 72 | +SELECT cloudsync_init('my_table'); |
| 73 | +``` |
| 74 | + |
| 75 | +### 5. If using supabase-docker (docker-compose) |
| 76 | + |
| 77 | +If your Fly.io Supabase is based on the [supabase/supabase](https://github.com/supabase/supabase) docker-compose setup, update the `db` service image in `docker-compose.yml`: |
| 78 | + |
| 79 | +```yaml |
| 80 | +services: |
| 81 | + db: |
| 82 | + image: ghcr.io/<your-org>/supabase-postgres-cloudsync:17.6.1.071 |
| 83 | +``` |
| 84 | +
|
| 85 | +## Important notes |
| 86 | +
|
| 87 | +- **Match the Postgres major version** — the Dockerfile defaults to PG 17 (`SUPABASE_POSTGRES_TAG=17.6.1.071`). Check what your Fly deployment runs with `SHOW server_version;`. |
| 88 | +- **ARM vs x86** — if your Fly machines are ARM (`fly.toml` with `vm.size` using arm), build the image for `linux/arm64`: `docker buildx build --platform linux/arm64 ...` |
| 89 | +- **RLS considerations** — when using Supabase Auth with Row-Level Security, use a JWT `token` (not `apikey`) when calling sync functions. |
0 commit comments