Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support deploying functions without docker #3123

Merged
merged 8 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 129 additions & 3 deletions api/beta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,45 @@ paths:
- Edge Functions
security:
- bearer: []
put:
operationId: v1-bulk-update-functions
summary: Bulk update functions
description: >-
Bulk update functions. It will create a new function or replace
existing. The operation is idempotent. NOTE: You will need to manually
bump the version.
parameters:
- name: ref
required: true
in: path
description: Project ref
schema:
minLength: 20
maxLength: 20
type: string
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/BulkUpdateFunctionBody'
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/BulkUpdateFunctionResponse'
'403':
description: ''
'500':
description: Failed to update functions
tags:
- Edge Functions
security:
- bearer: []
/v1/projects/{ref}/functions/deploy:
post:
operationId: v1-deploy-a-function
Expand All @@ -2376,6 +2415,11 @@ paths:
schema:
pattern: /^[A-Za-z0-9_-]+$/
type: string
- name: bundleOnly
required: false
in: query
schema:
type: boolean
requestBody:
required: true
content:
Expand All @@ -2388,7 +2432,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/FunctionResponse'
$ref: '#/components/schemas/DeployFunctionResponse'
'403':
description: ''
'500':
Expand Down Expand Up @@ -5671,7 +5715,50 @@ components:
- slug
- name
- body
FunctionMetadata:
BulkUpdateFunctionBody:
type: object
properties:
version:
type: integer
created_at:
type: integer
format: int64
id:
type: string
slug:
type: string
name:
type: string
status:
enum:
- ACTIVE
- REMOVED
- THROTTLED
type: string
verify_jwt:
type: boolean
import_map:
type: boolean
entrypoint_path:
type: string
import_map_path:
type: string
required:
- version
- id
- slug
- name
- status
BulkUpdateFunctionResponse:
type: object
properties:
functions:
type: array
items:
$ref: '#/components/schemas/FunctionResponse'
required:
- functions
FunctionDeployMetadata:
type: object
properties:
entrypoint_path:
Expand All @@ -5697,10 +5784,49 @@ components:
type: string
format: binary
metadata:
$ref: '#/components/schemas/FunctionMetadata'
$ref: '#/components/schemas/FunctionDeployMetadata'
required:
- file
- metadata
DeployFunctionResponse:
type: object
properties:
version:
type: integer
created_at:
type: integer
format: int64
updated_at:
type: integer
format: int64
id:
type: string
slug:
type: string
name:
type: string
status:
enum:
- ACTIVE
- REMOVED
- THROTTLED
type: string
verify_jwt:
type: boolean
import_map:
type: boolean
entrypoint_path:
type: string
import_map_path:
type: string
compute_multiplier:
type: number
required:
- version
- id
- slug
- name
- status
FunctionSlugResponse:
type: object
properties:
Expand Down
23 changes: 16 additions & 7 deletions cmd/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ var (
},
}

noVerifyJWT = new(bool)
useApi bool
useDocker bool
useLegacyBundle bool
noVerifyJWT = new(bool)
importMapPath string

functionsDeployCmd = &cobra.Command{
Expand All @@ -65,7 +67,10 @@ var (
if !cmd.Flags().Changed("no-verify-jwt") {
noVerifyJWT = nil
}
return deploy.Run(cmd.Context(), args, flags.ProjectRef, noVerifyJWT, importMapPath, afero.NewOsFs())
if useApi {
useDocker = false
}
return deploy.Run(cmd.Context(), args, useDocker, noVerifyJWT, importMapPath, afero.NewOsFs())
},
}

Expand Down Expand Up @@ -123,11 +128,15 @@ var (
func init() {
functionsListCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
functionsDeleteCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
functionsDeployCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
functionsDeployCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
functionsDeployCmd.Flags().BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
functionsDeployCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")
cobra.CheckErr(functionsDeployCmd.Flags().MarkHidden("legacy-bundle"))
deployFlags := functionsDeployCmd.Flags()
deployFlags.BoolVar(&useApi, "use-api", false, "Use Management API to bundle functions.")
deployFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to bundle functions.")
deployFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
functionsDeployCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker", "legacy-bundle")
cobra.CheckErr(deployFlags.MarkHidden("legacy-bundle"))
deployFlags.BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
deployFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
deployFlags.StringVar(&importMapPath, "import-map", "", "Path to import map file.")
functionsServeCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.")
functionsServeCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")
Expand Down
14 changes: 9 additions & 5 deletions internal/functions/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/supabase/cli/pkg/function"
)

func Run(ctx context.Context, slugs []string, projectRef string, noVerifyJWT *bool, importMapPath string, fsys afero.Fs) error {
func Run(ctx context.Context, slugs []string, useDocker bool, noVerifyJWT *bool, importMapPath string, fsys afero.Fs) error {
// Load function config and project id
if err := flags.LoadConfig(fsys); err != nil {
return err
Expand All @@ -37,12 +37,16 @@ func Run(ctx context.Context, slugs []string, projectRef string, noVerifyJWT *bo
if err != nil {
return err
}
api := function.NewEdgeRuntimeAPI(projectRef, *utils.GetSupabase(), NewDockerBundler(fsys))
if err := api.UpsertFunctions(ctx, functionConfig); err != nil {
if useDocker {
api := function.NewEdgeRuntimeAPI(flags.ProjectRef, *utils.GetSupabase(), NewDockerBundler(fsys))
if err := api.UpsertFunctions(ctx, functionConfig); err != nil {
return err
}
} else if err := deploy(ctx, functionConfig, fsys); err != nil {
return err
}
fmt.Printf("Deployed Functions on project %s: %s\n", utils.Aqua(projectRef), strings.Join(slugs, ", "))
url := fmt.Sprintf("%s/project/%v/functions", utils.GetSupabaseDashboardURL(), projectRef)
fmt.Printf("Deployed Functions on project %s: %s\n", utils.Aqua(flags.ProjectRef), strings.Join(slugs, ", "))
url := fmt.Sprintf("%s/project/%v/functions", utils.GetSupabaseDashboardURL(), flags.ProjectRef)
fmt.Println("You can inspect your deployment in the Dashboard: " + url)
return nil
}
Expand Down
Loading
Loading