-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/run supabase locally (#590)
- 支持纯本地启动
- Loading branch information
Showing
10 changed files
with
122 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELF_PATH=/client/ | ||
NEXT_PUBLIC_API_DOMAIN=http://localhost:8001 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
``` | ||
# Self-Hosting | ||
## Install Locally | ||
## Local Installation | ||
### Step 1: Clone the Repository | ||
Clone the project repository to your local machine: | ||
|
@@ -10,89 +11,71 @@ git clone https://github.com/petercat-ai/petercat.git | |
``` | ||
|
||
### Step 2: Install Dependencies | ||
Install all required dependencies using Yarn: | ||
Install all necessary dependencies using Yarn: | ||
|
||
```bash | ||
yarn run bootstrap | ||
``` | ||
|
||
### Step 3: Copy the `.env.example` Files | ||
Copy the server environment configuration example files: | ||
### Step 3: Start Supabase Locally | ||
|
||
Refer to [Supabase Self-Hosting Guide](https://supabase.com/docs/guides/self-hosting/docker#installing-and-running-supabase): | ||
|
||
```bash | ||
cp server/.env.example server/.env | ||
``` | ||
Copy the Client environment configuration example files: | ||
```bash | ||
cp client/.env.example client/.env | ||
``` | ||
# Get the code | ||
git clone --depth 1 https://github.com/supabase/supabase | ||
|
||
### 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`: | ||
# Go to the docker folder | ||
cd supabase/docker | ||
|
||
```bash | ||
vim server/.env | ||
``` | ||
# Copy the fake env vars | ||
cp .env.example .env | ||
|
||
For local development, configure only the Supabase and OpenAI settings: | ||
# Pull the latest images | ||
docker compose pull | ||
|
||
```bash | ||
# Supabase Project URL from https://supabase.com/dashboard/project/_/settings/database | ||
SUPABASE_URL=https://{{YOUR_PROJECT_ID}}.supabase.co | ||
# Start the services (in detached mode) | ||
docker compose up -d | ||
``` | ||
|
||
# Supabase Project API key for `anon public` | ||
SUPABASE_SERVICE_KEY=xxxx.yyyyy.zzzzz | ||
### Step 4: Copy the `.env.example` Files | ||
Copy the client environment configuration example file: | ||
```bash | ||
cp client/.env.local.example client/.env | ||
``` | ||
|
||
# OpenAI API key | ||
OPENAI_API_KEY=sk-xxxx | ||
Copy the server environment configuration example file: | ||
```bash | ||
cp server/.env.local.example server/.env | ||
``` | ||
|
||
### Step 5: Initialize the Database Structure | ||
Open the `server/.env` file and update the `SERVICE_ROLE_KEY` field to match the value of `SERVICE_ROLE_KEY` from the `docker/.env` file in Supabase. | ||
|
||
### Step 5: Initialize 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 [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: Run Migrations | ||
Apply the database migrations to your remote database: | ||
|
||
```bash | ||
supabase db push | ||
# The postgres db URL can be found in the .env file from Step 4 | ||
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 should see output similar to the following: | ||
|
||
``` | ||
Connecting to remote database... | ||
|
@@ -104,20 +87,21 @@ 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 | ||
yarn run server | ||
yarn run server:local | ||
``` | ||
|
||
Check if the server is running by opening `http://127.0.0.1:8000/api/health_checker` in your browser. | ||
Verify the server is running by opening `http://127.0.0.1:8001/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. | ||
Verify the client service by opening `http://127.0.0.1:3000` in your browser. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,37 +16,41 @@ git clone https://github.com/petercat-ai/petercat.git | |
yarn run bootstrap | ||
``` | ||
|
||
### 第三步:复制 `.env.example` 文件 | ||
复制服务器环境配置示例文件: | ||
### 第三步:在本地启动 supabase | ||
|
||
参考 https://supabase.com/docs/guides/self-hosting/docker#installing-and-running-supabase | ||
|
||
```bash | ||
cp server/.env.example server/.env | ||
``` | ||
复制客户端环境配置示例文件: | ||
```bash | ||
cp client/.env.example client/.env | ||
``` | ||
# Get the code | ||
git clone --depth 1 https://github.com/supabase/supabase | ||
### 第四步:更新 `.env` 文件 | ||
打开 `.env` 文件并更新必要的键值。您可以使用任何文本编辑器,例如 `vim`、`emacs`、`vscode` 或 `nano`: | ||
# Go to the docker folder | ||
cd supabase/docker | ||
```bash | ||
vim server/.env | ||
``` | ||
# Copy the fake env vars | ||
cp .env.example .env | ||
# Pull the latest images | ||
docker compose pull | ||
对于本地开发,只需配置 Supabase 和 OpenAI 设置: | ||
# Start the services (in detached mode) | ||
docker compose up -d | ||
``` | ||
|
||
### 第四步:复制 `.env.example` 文件 | ||
复制客户端环境配置示例文件: | ||
```bash | ||
# Supabase 项目 URL,获取路径:https://supabase.com/dashboard/project/_/settings/database | ||
SUPABASE_URL=https://{{YOUR_PROJECT_ID}}.supabase.co | ||
cp client/.env.local.example client/.env | ||
``` | ||
|
||
# Supabase 项目 API 密钥,`anon public` | ||
SUPABASE_SERVICE_KEY=xxxx.yyyyy.zzzzz | ||
复制服务器环境配置示例文件: | ||
|
||
# OpenAI API 密钥 | ||
OPENAI_API_KEY=sk-xxxx | ||
```bash | ||
cp server/.env.local.example server/.env | ||
``` | ||
|
||
打开 `server/.env` 文件,把 `SERVICE_ROLE_KEY` 字段改成从 supabase 的 `docker/.env` 文件的 `SERVICE_ROLE_KEY` 的值 | ||
|
||
### 第五步:初始化数据库结构 | ||
|
||
#### 第五步 5.1:导航到 Migrations 文件夹 | ||
|
@@ -63,33 +67,12 @@ 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 | ||
# postgres db url 在第四步的 .env 文件中可以找到 | ||
supabase db push --db-url "postgres://postgres.your-tenant-id:[email protected]:5432/postgres" | ||
``` | ||
|
||
如果成功,您将看到类似以下的输出: | ||
|
@@ -108,10 +91,10 @@ Finished supabase db push. | |
使用以下命令启动服务器: | ||
|
||
```bash | ||
yarn run server | ||
yarn run server:local | ||
``` | ||
|
||
通过在浏览器中打开 `http://127.0.0.1:8000/api/health_checker` 检查服务器是否正在运行。 | ||
通过在浏览器中打开 `http://127.0.0.1:8001/api/health_checker` 检查服务器是否正在运行。 | ||
|
||
### 第七步:启动客户端 | ||
使用以下命令启动客户端: | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.