Skip to content

Commit

Permalink
Merge branch 'develop' into feat/add-dynamic-env-provider-for-vault
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete authored Oct 30, 2024
2 parents bf16a99 + 0109975 commit 027a3b4
Show file tree
Hide file tree
Showing 15 changed files with 592 additions and 95 deletions.
98 changes: 97 additions & 1 deletion api/beta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,63 @@ paths:
- Projects
security:
- bearer: []
/v1/projects/{ref}/config/storage:
get:
operationId: v1-get-storage-config
summary: Gets project's storage config
parameters:
- name: ref
required: true
in: path
description: Project ref
schema:
minLength: 20
maxLength: 20
type: string
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/StorageConfigResponse'
'403':
description: ''
'500':
description: Failed to retrieve project's storage config
tags:
- Storage
security:
- bearer: []
patch:
operationId: v1-update-storage-config
summary: Updates project's storage config
parameters:
- name: ref
required: true
in: path
description: Project ref
schema:
minLength: 20
maxLength: 20
type: string
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateStorageConfigBody'
responses:
'200':
description: ''
'403':
description: ''
'500':
description: Failed to update project's storage config
tags:
- Storage
security:
- bearer: []
/v1/projects/{ref}/config/database/postgres:
get:
operationId: v1-get-postgres-config
Expand Down Expand Up @@ -1910,7 +1967,7 @@ paths:
- bearer: []
/v1/projects/{ref}/functions:
post:
operationId: createFunction
operationId: v1-create-a-function
summary: Create a function
description: Creates a function and adds it to the specified project.
parameters:
Expand Down Expand Up @@ -2545,6 +2602,7 @@ components:
- RESTORING
- RESTORE_FAILED
- PAUSE_FAILED
- RESIZING
type: string
db_host:
type: string
Expand Down Expand Up @@ -2639,9 +2697,12 @@ components:
BranchResetResponse:
type: object
properties:
workflow_run_id:
type: string
message:
type: string
required:
- workflow_run_id
- message
V1DatabaseResponse:
type: object
Expand Down Expand Up @@ -2701,6 +2762,7 @@ components:
- RESTORING
- RESTORE_FAILED
- PAUSE_FAILED
- RESIZING
type: string
required:
- id
Expand Down Expand Up @@ -3644,6 +3706,40 @@ components:
- name
- healthy
- status
StorageFeatureImageTransformation:
type: object
properties:
enabled:
type: boolean
required:
- enabled
StorageFeatures:
type: object
properties:
imageTransformation:
$ref: '#/components/schemas/StorageFeatureImageTransformation'
required:
- imageTransformation
StorageConfigResponse:
type: object
properties:
fileSizeLimit:
type: number
features:
$ref: '#/components/schemas/StorageFeatures'
required:
- fileSizeLimit
- features
UpdateStorageConfigBody:
type: object
properties:
fileSizeLimit:
type: integer
minimum: 0
maximum: 53687091200
format: int64
features:
$ref: '#/components/schemas/StorageFeatures'
PostgresConfigResponse:
type: object
properties:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/supabase/cli

go 1.22.4
go 1.23.2

require (
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
github.com/Netflix/go-env v0.1.0
github.com/Netflix/go-env v0.1.2
github.com/andybalholm/brotli v1.1.1
github.com/cenkalti/backoff/v4 v4.3.0
github.com/charmbracelet/bubbles v0.18.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lpr
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Netflix/go-env v0.1.0 h1:qSMk2A4D6urE/YqOKpLeOkaATGmFmMLo56E7kNNKypk=
github.com/Netflix/go-env v0.1.0/go.mod h1:9IRTAm+pQDPMpUtMLR26JOrjHnAWz3KUbhaegqTdhfY=
github.com/Netflix/go-env v0.1.2 h1:0DRoLR9lECQ9Zqvkswuebm3jJ/2enaDX6Ei8/Z+EnK0=
github.com/Netflix/go-env v0.1.2/go.mod h1:WlIhYi++8FlKNJtrop1mjXYAJMzv1f43K4MqCoh0yGE=
github.com/OpenPeeDeeP/depguard/v2 v2.2.0 h1:vDfG60vDtIuf0MEOhmLlLLSzqaRM8EMcgJPdp74zmpA=
github.com/OpenPeeDeeP/depguard/v2 v2.2.0/go.mod h1:CIzddKRvLBC4Au5aYP/i3nyaWQ+ClszLIuVocRiCYFQ=
github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78=
Expand Down
6 changes: 3 additions & 3 deletions internal/functions/deploy/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func (b *dockerBundler) Bundle(ctx context.Context, entrypoint string, importMap
}
}()
// Create bind mounts
hostEntrypointDir := filepath.Dir(entrypoint)
binds, err := GetBindMounts(cwd, utils.FunctionsDir, hostOutputDir, hostEntrypointDir, importMap, b.fsys)
binds, err := GetBindMounts(cwd, utils.FunctionsDir, hostOutputDir, entrypoint, importMap, b.fsys)
if err != nil {
return err
}
Expand Down Expand Up @@ -86,7 +85,7 @@ func (b *dockerBundler) Bundle(ctx context.Context, entrypoint string, importMap
return function.Compress(eszipBytes, output)
}

func GetBindMounts(cwd, hostFuncDir, hostOutputDir, hostEntrypointDir, hostImportMapPath string, fsys afero.Fs) ([]string, error) {
func GetBindMounts(cwd, hostFuncDir, hostOutputDir, hostEntrypointPath, hostImportMapPath string, fsys afero.Fs) ([]string, error) {
sep := string(filepath.Separator)
// Docker requires all host paths to be absolute
if !filepath.IsAbs(hostFuncDir) {
Expand Down Expand Up @@ -116,6 +115,7 @@ func GetBindMounts(cwd, hostFuncDir, hostOutputDir, hostEntrypointDir, hostImpor
}
}
// Allow entrypoints outside the functions directory
hostEntrypointDir := filepath.Dir(hostEntrypointPath)
if len(hostEntrypointDir) > 0 {
if !filepath.IsAbs(hostEntrypointDir) {
hostEntrypointDir = filepath.Join(cwd, hostEntrypointDir)
Expand Down
4 changes: 4 additions & 0 deletions internal/functions/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func GetFunctionSlugs(fsys afero.Fs) (slugs []string, err error) {
slugs = append(slugs, slug)
}
}
// Add all function slugs declared in config file
for slug := range utils.Config.Functions {
slugs = append(slugs, slug)
}
return slugs, nil
}

Expand Down
10 changes: 4 additions & 6 deletions internal/functions/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,13 @@ func ServeFunctions(ctx context.Context, envFilePath string, noVerifyJWT *bool,
if err != nil {
return err
}
cwd, err := os.Getwd()
if err != nil {
return errors.Errorf("failed to get working directory: %w", err)
}
dockerFuncDir := utils.ToDockerPath(filepath.Join(cwd, utils.FunctionsDir))
env = append(env,
fmt.Sprintf("SUPABASE_URL=http://%s:8000", utils.KongAliases[0]),
"SUPABASE_ANON_KEY="+utils.Config.Auth.AnonKey,
"SUPABASE_SERVICE_ROLE_KEY="+utils.Config.Auth.ServiceRoleKey,
"SUPABASE_DB_URL="+dbUrl,
"SUPABASE_INTERNAL_JWT_SECRET="+utils.Config.Auth.JwtSecret,
fmt.Sprintf("SUPABASE_INTERNAL_HOST_PORT=%d", utils.Config.Api.Port),
"SUPABASE_INTERNAL_FUNCTIONS_PATH="+dockerFuncDir,
)
if viper.GetBool("DEBUG") {
env = append(env, "SUPABASE_INTERNAL_DEBUG=true")
Expand All @@ -130,6 +124,10 @@ func ServeFunctions(ctx context.Context, envFilePath string, noVerifyJWT *bool,
env = append(env, "SUPABASE_INTERNAL_WALLCLOCK_LIMIT_SEC=0")
}
// 3. Parse custom import map
cwd, err := os.Getwd()
if err != nil {
return errors.Errorf("failed to get working directory: %w", err)
}
binds, functionsConfigString, err := populatePerFunctionConfigs(cwd, importMapPath, noVerifyJWT, fsys)
if err != nil {
return err
Expand Down
11 changes: 8 additions & 3 deletions internal/functions/serve/templates/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
STATUS_CODE,
STATUS_TEXT,
} from "https://deno.land/std/http/status.ts";
import * as posix from "https://deno.land/std/path/posix/mod.ts";

import * as jose from "https://deno.land/x/[email protected]/index.ts";

Expand All @@ -28,7 +29,6 @@ const EXCLUDED_ENVS = ["HOME", "HOSTNAME", "PATH", "PWD"];

const JWT_SECRET = Deno.env.get("SUPABASE_INTERNAL_JWT_SECRET")!;
const HOST_PORT = Deno.env.get("SUPABASE_INTERNAL_HOST_PORT")!;
const FUNCTIONS_PATH = Deno.env.get("SUPABASE_INTERNAL_FUNCTIONS_PATH")!;
const DEBUG = Deno.env.get("SUPABASE_INTERNAL_DEBUG") === "true";
const FUNCTIONS_CONFIG_STRING = Deno.env.get(
"SUPABASE_INTERNAL_FUNCTIONS_CONFIG",
Expand All @@ -43,6 +43,7 @@ const DENO_SB_ERROR_MAP = new Map([
]);

interface FunctionConfig {
entrypointPath: string;
importMapPath: string;
verifyJWT: boolean;
}
Expand Down Expand Up @@ -144,7 +145,7 @@ Deno.serve({
}
}

const servicePath = `${FUNCTIONS_PATH}/${functionName}`;
const servicePath = posix.dirname(functionsConfig[functionName].entrypointPath);
console.error(`serving the request with ${servicePath}`);

// Ref: https://supabase.com/docs/guides/functions/limits
Expand All @@ -167,6 +168,9 @@ Deno.serve({
// point, as their migration process will not be easy.
const decoratorType = "tc39";

const absEntrypoint = posix.join(Deno.cwd(), functionsConfig[functionName].entrypointPath);
const maybeEntrypoint = posix.toFileUrl(absEntrypoint).href;

try {
const worker = await EdgeRuntime.userWorkers.create({
servicePath,
Expand All @@ -179,7 +183,8 @@ Deno.serve({
customModuleRoot,
cpuTimeSoftLimitMs,
cpuTimeHardLimitMs,
decoratorType
decoratorType,
maybeEntrypoint
});

const controller = new AbortController();
Expand Down
11 changes: 1 addition & 10 deletions internal/seed/buckets/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package buckets
import (
"context"
"fmt"
"path/filepath"

"github.com/spf13/afero"
"github.com/supabase/cli/internal/storage/client"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/config"
)

func Run(ctx context.Context, projectRef string, interactive bool, fsys afero.Fs) error {
Expand All @@ -31,12 +29,5 @@ func Run(ctx context.Context, projectRef string, interactive bool, fsys afero.Fs
if err := api.UpsertBuckets(ctx, utils.Config.Storage.Buckets, filter); err != nil {
return err
}
resolved := config.BucketConfig{}
for name, bucket := range utils.Config.Storage.Buckets {
if len(bucket.ObjectsPath) > 0 && !filepath.IsAbs(bucket.ObjectsPath) {
bucket.ObjectsPath = filepath.Join(utils.SupabaseDirPath, bucket.ObjectsPath)
}
resolved[name] = bucket
}
return api.UpsertObjects(ctx, resolved, utils.NewRootFS(fsys))
return api.UpsertObjects(ctx, utils.Config.Storage.Buckets, utils.NewRootFS(fsys))
}
Loading

0 comments on commit 027a3b4

Please sign in to comment.