Skip to content

Commit 4b0b2b1

Browse files
authored
feat: support deploying functions without docker (#3123)
* feat: support deploying functions without docker * chore: add unit tests * fix: use bulk update endpoint when deploying multiple slugs * fix: cancel goroutine with cause * chore: test form writer * chore: update unit tests * fix: fail on static directories
1 parent b6d428a commit 4b0b2b1

File tree

15 files changed

+957
-53
lines changed

15 files changed

+957
-53
lines changed

api/beta.yaml

Lines changed: 129 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,45 @@ paths:
23542354
- Edge Functions
23552355
security:
23562356
- bearer: []
2357+
put:
2358+
operationId: v1-bulk-update-functions
2359+
summary: Bulk update functions
2360+
description: >-
2361+
Bulk update functions. It will create a new function or replace
2362+
existing. The operation is idempotent. NOTE: You will need to manually
2363+
bump the version.
2364+
parameters:
2365+
- name: ref
2366+
required: true
2367+
in: path
2368+
description: Project ref
2369+
schema:
2370+
minLength: 20
2371+
maxLength: 20
2372+
type: string
2373+
requestBody:
2374+
required: true
2375+
content:
2376+
application/json:
2377+
schema:
2378+
type: array
2379+
items:
2380+
$ref: '#/components/schemas/BulkUpdateFunctionBody'
2381+
responses:
2382+
'200':
2383+
description: ''
2384+
content:
2385+
application/json:
2386+
schema:
2387+
$ref: '#/components/schemas/BulkUpdateFunctionResponse'
2388+
'403':
2389+
description: ''
2390+
'500':
2391+
description: Failed to update functions
2392+
tags:
2393+
- Edge Functions
2394+
security:
2395+
- bearer: []
23572396
/v1/projects/{ref}/functions/deploy:
23582397
post:
23592398
operationId: v1-deploy-a-function
@@ -2376,6 +2415,11 @@ paths:
23762415
schema:
23772416
pattern: /^[A-Za-z0-9_-]+$/
23782417
type: string
2418+
- name: bundleOnly
2419+
required: false
2420+
in: query
2421+
schema:
2422+
type: boolean
23792423
requestBody:
23802424
required: true
23812425
content:
@@ -2388,7 +2432,7 @@ paths:
23882432
content:
23892433
application/json:
23902434
schema:
2391-
$ref: '#/components/schemas/FunctionResponse'
2435+
$ref: '#/components/schemas/DeployFunctionResponse'
23922436
'403':
23932437
description: ''
23942438
'500':
@@ -5671,7 +5715,50 @@ components:
56715715
- slug
56725716
- name
56735717
- body
5674-
FunctionMetadata:
5718+
BulkUpdateFunctionBody:
5719+
type: object
5720+
properties:
5721+
version:
5722+
type: integer
5723+
created_at:
5724+
type: integer
5725+
format: int64
5726+
id:
5727+
type: string
5728+
slug:
5729+
type: string
5730+
name:
5731+
type: string
5732+
status:
5733+
enum:
5734+
- ACTIVE
5735+
- REMOVED
5736+
- THROTTLED
5737+
type: string
5738+
verify_jwt:
5739+
type: boolean
5740+
import_map:
5741+
type: boolean
5742+
entrypoint_path:
5743+
type: string
5744+
import_map_path:
5745+
type: string
5746+
required:
5747+
- version
5748+
- id
5749+
- slug
5750+
- name
5751+
- status
5752+
BulkUpdateFunctionResponse:
5753+
type: object
5754+
properties:
5755+
functions:
5756+
type: array
5757+
items:
5758+
$ref: '#/components/schemas/FunctionResponse'
5759+
required:
5760+
- functions
5761+
FunctionDeployMetadata:
56755762
type: object
56765763
properties:
56775764
entrypoint_path:
@@ -5697,10 +5784,49 @@ components:
56975784
type: string
56985785
format: binary
56995786
metadata:
5700-
$ref: '#/components/schemas/FunctionMetadata'
5787+
$ref: '#/components/schemas/FunctionDeployMetadata'
57015788
required:
57025789
- file
57035790
- metadata
5791+
DeployFunctionResponse:
5792+
type: object
5793+
properties:
5794+
version:
5795+
type: integer
5796+
created_at:
5797+
type: integer
5798+
format: int64
5799+
updated_at:
5800+
type: integer
5801+
format: int64
5802+
id:
5803+
type: string
5804+
slug:
5805+
type: string
5806+
name:
5807+
type: string
5808+
status:
5809+
enum:
5810+
- ACTIVE
5811+
- REMOVED
5812+
- THROTTLED
5813+
type: string
5814+
verify_jwt:
5815+
type: boolean
5816+
import_map:
5817+
type: boolean
5818+
entrypoint_path:
5819+
type: string
5820+
import_map_path:
5821+
type: string
5822+
compute_multiplier:
5823+
type: number
5824+
required:
5825+
- version
5826+
- id
5827+
- slug
5828+
- name
5829+
- status
57045830
FunctionSlugResponse:
57055831
type: object
57065832
properties:

cmd/functions.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ var (
5252
},
5353
}
5454

55-
noVerifyJWT = new(bool)
55+
useApi bool
56+
useDocker bool
5657
useLegacyBundle bool
58+
noVerifyJWT = new(bool)
5759
importMapPath string
5860

5961
functionsDeployCmd = &cobra.Command{
@@ -65,7 +67,10 @@ var (
6567
if !cmd.Flags().Changed("no-verify-jwt") {
6668
noVerifyJWT = nil
6769
}
68-
return deploy.Run(cmd.Context(), args, flags.ProjectRef, noVerifyJWT, importMapPath, afero.NewOsFs())
70+
if useApi {
71+
useDocker = false
72+
}
73+
return deploy.Run(cmd.Context(), args, useDocker, noVerifyJWT, importMapPath, afero.NewOsFs())
6974
},
7075
}
7176

@@ -123,11 +128,15 @@ var (
123128
func init() {
124129
functionsListCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
125130
functionsDeleteCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
126-
functionsDeployCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
127-
functionsDeployCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
128-
functionsDeployCmd.Flags().BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
129-
functionsDeployCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")
130-
cobra.CheckErr(functionsDeployCmd.Flags().MarkHidden("legacy-bundle"))
131+
deployFlags := functionsDeployCmd.Flags()
132+
deployFlags.BoolVar(&useApi, "use-api", false, "Use Management API to bundle functions.")
133+
deployFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to bundle functions.")
134+
deployFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
135+
functionsDeployCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker", "legacy-bundle")
136+
cobra.CheckErr(deployFlags.MarkHidden("legacy-bundle"))
137+
deployFlags.BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
138+
deployFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
139+
deployFlags.StringVar(&importMapPath, "import-map", "", "Path to import map file.")
131140
functionsServeCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
132141
functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.")
133142
functionsServeCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")

internal/functions/deploy/deploy.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/supabase/cli/pkg/function"
1717
)
1818

19-
func Run(ctx context.Context, slugs []string, projectRef string, noVerifyJWT *bool, importMapPath string, fsys afero.Fs) error {
19+
func Run(ctx context.Context, slugs []string, useDocker bool, noVerifyJWT *bool, importMapPath string, fsys afero.Fs) error {
2020
// Load function config and project id
2121
if err := flags.LoadConfig(fsys); err != nil {
2222
return err
@@ -37,12 +37,16 @@ func Run(ctx context.Context, slugs []string, projectRef string, noVerifyJWT *bo
3737
if err != nil {
3838
return err
3939
}
40-
api := function.NewEdgeRuntimeAPI(projectRef, *utils.GetSupabase(), NewDockerBundler(fsys))
41-
if err := api.UpsertFunctions(ctx, functionConfig); err != nil {
40+
if useDocker {
41+
api := function.NewEdgeRuntimeAPI(flags.ProjectRef, *utils.GetSupabase(), NewDockerBundler(fsys))
42+
if err := api.UpsertFunctions(ctx, functionConfig); err != nil {
43+
return err
44+
}
45+
} else if err := deploy(ctx, functionConfig, fsys); err != nil {
4246
return err
4347
}
44-
fmt.Printf("Deployed Functions on project %s: %s\n", utils.Aqua(projectRef), strings.Join(slugs, ", "))
45-
url := fmt.Sprintf("%s/project/%v/functions", utils.GetSupabaseDashboardURL(), projectRef)
48+
fmt.Printf("Deployed Functions on project %s: %s\n", utils.Aqua(flags.ProjectRef), strings.Join(slugs, ", "))
49+
url := fmt.Sprintf("%s/project/%v/functions", utils.GetSupabaseDashboardURL(), flags.ProjectRef)
4650
fmt.Println("You can inspect your deployment in the Dashboard: " + url)
4751
return nil
4852
}

0 commit comments

Comments
 (0)