Skip to content

Commit

Permalink
feat: run supabase locally
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoHai committed Dec 16, 2024
1 parent de69310 commit bedd370
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 199 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Docker volumnes
docker/volumes/db/data
docker/volumes/storage

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
__pycache__/
*.pyc
Expand Down Expand Up @@ -59,4 +63,3 @@ next-env.d.ts

dist/
lui/src/style.css

2 changes: 2 additions & 0 deletions client/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELF_PATH=/client/
NEXT_PUBLIC_API_DOMAIN=http://localhost:8001
53 changes: 0 additions & 53 deletions docker/docker-compose.yml

This file was deleted.

68 changes: 17 additions & 51 deletions docs/guides/self_hosted_local.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Self-Hosting
```
# Self-Hosting Guide
## Install Locally
## Local Installation
### Step 1: Clone the Repository
Clone the project repository to your local machine:
Expand All @@ -16,83 +17,47 @@ Install all required dependencies using Yarn:
yarn run bootstrap
```

### Step 3: Copy the `.env.example` Files
Copy the server environment configuration example files:
### Step 3: Copy `.env.example` Files
Copy the server environment configuration example file:

```bash
cp server/.env.example server/.env
```
Copy the Client environment configuration example files:
Copy the client environment configuration example file:
```bash
cp client/.env.example client/.env
```

### Step 4: Update the `.env` Files
Open the `.env` file and update the necessary keys. You can use any text editor, like `vim`, `emacs`, `vscode`, or `nano`:

```bash
vim server/.env
```

For local development, configure only the Supabase and OpenAI settings:
### Step 4: Start Supabase Locally with Docker Compose

```bash
# Supabase Project URL from https://supabase.com/dashboard/project/_/settings/database
SUPABASE_URL=https://{{YOUR_PROJECT_ID}}.supabase.co

# Supabase Project API key for `anon public`
SUPABASE_SERVICE_KEY=xxxx.yyyyy.zzzzz

# OpenAI API key
OPENAI_API_KEY=sk-xxxx
yarn run docker
```

### Step 5: Initialize the Database Structure
### Step 5: Initialize the Database Schema

#### Step 5.1: Navigate to the Migrations Folder
Navigate to the `migrations` folder to prepare for the database setup:
Navigate to the `migrations` folder to prepare for database setup:

```bash
cd migrations
```

#### Step 5.2: Install Supabase CLI
Install the Supabase CLI following the instructions on [Supabase's Getting Started Guide](https://supabase.com/docs/guides/cli/getting-started):
Install the Supabase CLI following the instructions in the [Supabase Getting Started Guide](https://supabase.com/docs/guides/cli/getting-started):

```bash
brew install supabase/tap/supabase
```

#### Step 5.3: Link to the Remote Project
To connect to the Supabase project, you'll need to enter the database password. You can find this password in the [Supabase Dashboard](https://supabase.com/dashboard/project/_/settings/database):

```bash
supabase link --project-ref {YOUR_PROJECT_ID}
```

If the connection is successful, you'll see output like this:

```
Enter your database password (or leave blank to skip):
Connecting to remote database...
Finished supabase link.
Local config differs from linked project. Try updating supabase/config.toml
[api]
enabled = true
port = 54321
schemas = ["public", "graphql_public"]
extra_search_path = ["public", "extensions"]
max_rows = 1000
```

#### Step 5.4: Perform Migration
#### Step 5.3: Apply Migrations
Apply the database migrations to your remote database:

```bash
supabase db push
supabase db push --db-url "postgres://postgres.your-tenant-id:[email protected]:5432/postgres"
```

If successful, you'll see output similar to:
If successful, you will see output similar to the following:

```
Connecting to remote database...
Expand All @@ -104,7 +69,7 @@ Applying migration 20240902023033_remote_schema.sql...
Finished supabase db push.
```

### Step 6: Bootstrap Server
### Step 6: Start the Server
Start the server with the following command:

```bash
Expand All @@ -113,11 +78,12 @@ yarn run server

Check if the server is running by opening `http://127.0.0.1:8000/api/health_checker` in your browser.

### Step 7: Bootstrap Client
### Step 7: Start the Client
Start the client with the following command:

```bash
yarn run client
```

You can check the client service by opening `http://127.0.0.1:3000` in your browser.
```
44 changes: 4 additions & 40 deletions docs/guides/self_hosted_local_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,10 @@ cp server/.env.example server/.env
cp client/.env.example client/.env
```

### 第四步:更新 `.env` 文件
打开 `.env` 文件并更新必要的键值。您可以使用任何文本编辑器,例如 `vim``emacs``vscode``nano`
### 第四步:使用 docker compose 在本地启动 supabase

```bash
vim server/.env
```

对于本地开发,只需配置 Supabase 和 OpenAI 设置:

```bash
# Supabase 项目 URL,获取路径:https://supabase.com/dashboard/project/_/settings/database
SUPABASE_URL=https://{{YOUR_PROJECT_ID}}.supabase.co

# Supabase 项目 API 密钥,`anon public`
SUPABASE_SERVICE_KEY=xxxx.yyyyy.zzzzz

# OpenAI API 密钥
OPENAI_API_KEY=sk-xxxx
yarn run docker
```

### 第五步:初始化数据库结构
Expand All @@ -63,33 +49,11 @@ cd migrations
brew install supabase/tap/supabase
```

#### 第五步 5.3:连接到远程项目
要连接到 Supabase 项目,您需要输入数据库密码。您可以在 [Supabase 控制面板](https://supabase.com/dashboard/project/_/settings/database) 中找到该密码:

```bash
supabase link --project-ref {YOUR_PROJECT_ID}
```

如果连接成功,您将看到类似以下的输出:

```
Enter your database password (or leave blank to skip):
Connecting to remote database...
Finished supabase link.
Local config differs from linked project. Try updating supabase/config.toml
[api]
enabled = true
port = 54321
schemas = ["public", "graphql_public"]
extra_search_path = ["public", "extensions"]
max_rows = 1000
```

#### 第五步 5.4:执行迁移
#### 第五步 5.3:执行迁移
将数据库迁移应用到您的远程数据库:

```bash
supabase db push
supabase db push --db-url "postgres://postgres.your-tenant-id:[email protected]:5432/postgres"
```

如果成功,您将看到类似以下的输出:
Expand Down
49 changes: 0 additions & 49 deletions docs/guides/self_hosting_docker.md

This file was deleted.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"client": "cd client && yarn run dev",
"assistant": "cd assistant && yarn run dev",
"server": "cd server && ./venv/bin/python3 -m uvicorn main:app --reload",
"server-local": "cd server && python3 -m uvicorn main:app --port 8001 --reload",
"env:pull": "cd server && ./venv/bin/python3 scripts/envs.py pull",
"client:server": "concurrently \"yarn run server\" \"yarn run client\"",
"assistant:server": "concurrently \"yarn run server\" \"yarn run assistant\"",
"build:docker": "docker build -t petercat .",
"build:pypi": "rm -rf dist && python3 -m build",
"publish:test": "python3 -m twine upload --repository petercat-utils dist/* ",
"publish:pypi": "python3 -m twine upload --repository pypi dist/* "
"publish:pypi": "python3 -m twine upload --repository pypi dist/* ",
"docker": "docker compose --env-file server/.env -f docker/docker-compose.yml up -d"
},
"engines": {
"node": "^18 || >=20"
Expand Down
Loading

0 comments on commit bedd370

Please sign in to comment.