边缘函数

使用 CI/CD 流水线部署

使用 GitHub Actions、Bitbucket 和 GitLab CI 来部署您的边缘函数。


您可以使用流行的 CI/CD 工具如 GitHub Actions、Bitbucket 和 GitLab CI 来自动化部署边缘函数。

GitHub Actions

您可以使用官方的 setup-cli GitHub Action 在 GitHub Actions 中运行 Supabase CLI 命令。

以下 GitHub Action 会在代码合并到 main 分支时部署所有边缘函数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
name: Deploy Functionon: push: branches: - main workflow_dispatch:jobs: deploy: runs-on: ubuntu-latest env: SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }} PROJECT_ID: your-project-id steps: - uses: actions/checkout@v4 - uses: supabase/setup-cli@v1 with: version: latest - run: supabase functions deploy --project-ref $PROJECT_ID

GitLab CI

以下是使用 GitLab CI 进行部署的示例管道配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
image: node:20# 任务执行阶段及其顺序列表stages: - setup - deploy# 该任务在 setup 阶段运行,会首先执行setup-npm: stage: setup script: - npm i supabase cache: paths: - node_modules/ artifacts: paths: - node_modules/# 该任务在 deploy 阶段运行,只有当 build 阶段的任务成功完成后才会开始deploy-function: stage: deploy script: - npx supabase init - npx supabase functions deploy --debug services: - docker:dind variables: DOCKER_HOST: tcp://docker:2375

Bitbucket 流水线

以下是用于通过 Bitbucket 部署的示例流水线配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
image: node:20pipelines: default: - step: name: 初始化设置 caches: - node script: - npm i supabase - parallel: - step: name: 函数部署 script: - npx supabase init - npx supabase functions deploy --debug services: - docker

声明式配置

可以通过 config.toml 文件设置单个函数的配置,例如 JWT 验证导入映射位置

1
2
[functions.hello-world]verify_jwt = false

相关资源