Skip to content

Commit

Permalink
Merge pull request #117 from supabase-community/feat/deploy-with-supa…
Browse files Browse the repository at this point in the history
…base

feat: database deployment on Supabase
  • Loading branch information
jgoux authored Nov 26, 2024
2 parents ee734fa + 3c8fab8 commit c239111
Show file tree
Hide file tree
Showing 80 changed files with 12,444 additions and 959 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/node_modules
**/.next
**/.turbo
**/.env*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ tls/
dist/

.env
.turbo
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,63 @@ How is this possible? [PGlite](https://pglite.dev/), a WASM version of Postgres

This is a monorepo split into the following projects:

- [Frontend (Next.js)](./apps/postgres-new/): This contains the primary web app built with Next.js
- [Backend (pg-gateway)](./apps/db-service/): This serves S3-backed PGlite databases over the PG wire protocol using [pg-gateway](https://github.com/supabase-community/pg-gateway)
- [Web](./apps/postgres-new/): The primary web app built with Next.js
- [Browser proxy](./apps/browser-proxy/): Proxies Postgres TCP connections back to the browser using [pg-gateway](https://github.com/supabase-community/pg-gateway) and Web Sockets
- [Deploy worker](./apps/deploy-worker/): Deploys in-browser databases to database platforms (currently Supabase is supported)

### Setup

From the monorepo root:

1. Install dependencies

```shell
npm i
```

2. Start local Supabase stack:
```shell
npx supabase start
```
3. Store local Supabase URL/anon key in `./apps/postgres-new/.env.local`:
```shell
npx supabase status -o env \
--override-name api.url=NEXT_PUBLIC_SUPABASE_URL \
--override-name auth.anon_key=NEXT_PUBLIC_SUPABASE_ANON_KEY |
grep NEXT_PUBLIC >> ./apps/postgres-new/.env.local
```
4. Create an [OpenAI API key](https://platform.openai.com/api-keys) and save to `./apps/postgres-new/.env.local`:
```shell
echo 'OPENAI_API_KEY="<openai-api-key>"' >> ./apps/postgres-new/.env.local
```
5. Store local KV (Redis) vars. Use these exact values:

```shell
echo 'KV_REST_API_URL="http://localhost:8080"' >> ./apps/postgres-new/.env.local
echo 'KV_REST_API_TOKEN="local_token"' >> ./apps/postgres-new/.env.local
```

6. Start local Redis containers (used for rate limiting). Serves an API on port 8080:

```shell
docker compose -f ./apps/postgres-new/docker-compose.yml up -d
```

7. Fill in the remaining variables for each app as seen in:

- `./apps/postgres-new/.env.example`
- `./apps/browser-proxy/.env.example`
- `./apps/deploy-worker/.env.example`

### Development

From the monorepo root:

```shell
npm run dev
```

_**Important:** This command uses `turbo` under the hood which understands the relationship between dependencies in the monorepo and automatically builds them accordingly (ie. `./packages/*`). If you by-pass `turbo`, you will have to manually build each `./packages/*` before each `./app/*` can use them._

## Why rename postgres.new?

Expand Down
14 changes: 3 additions & 11 deletions apps/browser-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ It is using a WebSocket server and a TCP server to make the communication betwee

Copy the `.env.example` file to `.env` and set the correct environment variables.

Install dependencies:
Run the dev server from the monorepo root. See [Development](../../README.md#development).

```sh
npm install
```

Start the proxy in development mode:

```sh
npm run dev
```
The browser proxy will be listening on ports `5432` (Postgres TCP) and `443` (Web Sockets).

## Deployment

Expand All @@ -30,4 +22,4 @@ Deploy the app:

```sh
fly deploy --app database-build-browser-proxy
```
```
5 changes: 0 additions & 5 deletions apps/db-service/.dockerignore

This file was deleted.

68 changes: 0 additions & 68 deletions apps/db-service/Dockerfile

This file was deleted.

101 changes: 0 additions & 101 deletions apps/db-service/README.md

This file was deleted.

63 changes: 0 additions & 63 deletions apps/db-service/docker-compose.yml

This file was deleted.

38 changes: 0 additions & 38 deletions apps/db-service/entrypoint.sh

This file was deleted.

Loading

0 comments on commit c239111

Please sign in to comment.