本页还没有译文
本页 36 段还没译成한국어,下面显示的是英文原文。Deploy to Production
还没翻译译自英文(supabase.com)本页 36 段都还没译
Once you have developed your Edge Functions locally, you can deploy them to your Supabase project.
Note
Before getting started, make sure you have the Supabase CLI installed. Check out the CLI installation guide for installation methods and troubleshooting.
Step 1: Authenticate
Sign in to the Supabase CLI if you haven't already:
supabase loginStep 2: Connect your project
Get the project ID associated with your function:
supabase projects listNeed a new project?
If you haven't yet created a Supabase project, you can do so by visiting database.new.
Link your local project to your remote Supabase project using the ID you retrieved:
supabase link --project-ref your-project-idNow you should have your local development environment connected to your production project.
Step 3: Deploy Functions
You can deploy all edge functions within the functions folder with a single command:
supabase functions deployOr deploy individual Edge Functions by specifying the function name:
supabase functions deploy hello-worldStep 4: Verify successful deployment
🎉 Your function is now live!
When the deployment is successful, your function is automatically distributed to edge locations worldwide. Your edge functions is now running globally at https://[YOUR_PROJECT_ID].supabase.co/functions/v1/hello-world.
Step 5: Test your live function
You can now invoke your Edge Function using one of the project's PUBLISHABLE_KEYS, which can be found in the API settings of the Supabase Dashboard. You can invoke it from within your app:
curl --request POST 'https://<project_id>.supabase.co/functions/v1/hello-world' \
--header 'apikey: PUBLISHABLE_KEY' \
--header 'Content-Type: application/json' \
--data '{ "name":"Functions" }'import { createClient } from '@supabase/supabase-js'
// Create a single supabase client for interacting with your database
const supabase = createClient('https://xyzcompany.supabase.co', 'sb_publishable_...')
const { data, error } = await supabase.functions.invoke('hello-world', {
body: { name: 'Functions' },
})Note
Note that the SUPABASE_PUBLISHABLE_KEYS is different in development and production. To get a publishable key, you can find it in your Supabase dashboard under Settings > API.
You should now see the expected response:
{ "message": "Hello Production!" }Note
You can also test the function through the Dashboard. To see how that works, check out the Dashboard Quickstart guide.
CI/CD deployment
You can use popular CI / CD tools like GitHub Actions, Bitbucket, and GitLab CI to automate Edge Function deployments.
GitHub Actions
You can use the official setup-cli GitHub Action to run Supabase CLI commands in your GitHub Actions.
The following GitHub Action deploys all Edge Functions any time code is merged into the main branch:
name: Deploy Function
on:
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_IDGitLab CI
Here is the sample pipeline configuration to deploy via GitLab CI.
image: node:20
# List of stages for jobs, and their order of execution
stages:
- setup
- deploy
# This job runs in the setup stage, which runs first.
setup-npm:
stage: setup
script:
- npm i supabase
cache:
paths:
- node_modules/
artifacts:
paths:
- node_modules/
# This job runs in the deploy stage, which only starts when the job in the build stage completes successfully.
deploy-function:
stage: deploy
script:
- npx supabase init
- npx supabase functions deploy --debug
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375Bitbucket Pipelines
Here is the sample pipeline configuration to deploy via Bitbucket.
image: node:20
pipelines:
default:
- step:
name: Setup
caches:
- node
script:
- npm i supabase
- parallel:
- step:
name: Functions Deploy
script:
- npx supabase init
- npx supabase functions deploy --debug
services:
- dockerFunction configuration
Individual function configuration like JWT verification and import map location can be set via the config.toml file.
[functions.hello-world]
verify_jwt = falseThis ensures your function configurations are consistent across all environments and deployments.
Example
This example shows a GitHub Actions workflow that deploys all Edge Functions when code is merged into the main branch.
name: Deploy Function
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
SUPABASE_PROJECT_ID: ${{ secrets.SUPABASE_PROJECT_ID }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: supabase/setup-cli@3c2f5e2ae34c34e428e8e206e2c4d21fa2d20fbf # v2.1.1
with:
version: latest
- run: supabase functions deploy --project-ref $SUPABASE_PROJECT_ID