Skip to content

Commit

Permalink
fix(functions): unbundle to slug directory by default
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Apr 5, 2024
1 parent 85a03ca commit d9ff87c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/functions/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ func Run(ctx context.Context, slug string, projectRef string, useLegacyBundle bo
}
}()
// Extract eszip to functions directory
err = extractOne(ctx, eszipPath)
err = extractOne(ctx, slug, eszipPath)
if err != nil {
utils.CmdSuggestion += suggestLegacyBundle(slug)
}
return err
}

func downloadOne(ctx context.Context, slug string, projectRef string, fsys afero.Fs) (string, error) {
func downloadOne(ctx context.Context, slug, projectRef string, fsys afero.Fs) (string, error) {
fmt.Println("Downloading " + utils.Bold(slug))
resp, err := utils.GetSupabase().GetFunctionBody(ctx, projectRef, slug)
if err != nil {
Expand All @@ -161,23 +161,24 @@ func downloadOne(ctx context.Context, slug string, projectRef string, fsys afero
return eszipPath, nil
}

func extractOne(ctx context.Context, eszipPath string) error {
hostFuncDirPath, err := filepath.Abs(utils.FunctionsDir)
func extractOne(ctx context.Context, slug, eszipPath string) error {
hostFuncDirPath, err := filepath.Abs(filepath.Join(utils.FunctionsDir, slug))
if err != nil {
return errors.Errorf("failed to resolve absolute path: %w", err)
}

hostEszipPath, err := filepath.Abs(eszipPath)
if err != nil {
return errors.Errorf("failed to resolve eszip path: %w", err)
}

dockerEszipPath := path.Join(dockerEszipDir, filepath.Base(hostEszipPath))

binds := []string{
// Reuse deno cache directory, ie. DENO_DIR, between container restarts
// https://denolib.gitbook.io/guide/advanced/deno_dir-code-fetch-and-cache
utils.EdgeRuntimeId + ":/root/.cache/deno:rw,z",
hostEszipPath + ":" + dockerEszipPath + ":ro,z",
hostFuncDirPath + ":" + utils.DockerFuncDirPath + ":rw,z",
hostFuncDirPath + ":" + utils.DockerDenoDir + ":rw,z",
}

return utils.DockerRunOnceWithConfig(
Expand Down

0 comments on commit d9ff87c

Please sign in to comment.