From 1441e61fda447ae50729bcc70b0a247c8709e3f8 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Thu, 12 Oct 2023 00:14:47 +0800 Subject: [PATCH] fix(functions): create named volume for caching deno directory --- internal/functions/serve/serve.go | 3 +++ internal/stop/stop.go | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/functions/serve/serve.go b/internal/functions/serve/serve.go index 83ebd86b2..dc8fb66de 100644 --- a/internal/functions/serve/serve.go +++ b/internal/functions/serve/serve.go @@ -99,6 +99,9 @@ func ServeFunctions(ctx context.Context, envFilePath string, noVerifyJWT *bool, } // 3. Parse custom import map 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", filepath.Join(cwd, utils.FunctionsDir) + ":" + dockerFuncDirPath + ":rw,z", } if importMapPath != "" { diff --git a/internal/stop/stop.go b/internal/stop/stop.go index 13946fe91..8a5d082c7 100644 --- a/internal/stop/stop.go +++ b/internal/stop/stop.go @@ -67,10 +67,17 @@ func stop(ctx context.Context, backup bool, w io.Writer) error { fmt.Fprintln(os.Stderr, "Postgres database saved to volume:", utils.DbId) fmt.Fprintln(os.Stderr, "Postgres config saved to volume:", utils.ConfigId) fmt.Fprintln(os.Stderr, "Storage directory saved to volume:", utils.StorageId) + fmt.Fprintln(os.Stderr, "Functions cache saved to volume:", utils.EdgeRuntimeId) fmt.Fprintln(os.Stderr, "Inbucket emails saved to volume:", utils.InbucketId) } else { // TODO: label named volumes to use VolumesPrune for branch support - volumes := []string{utils.ConfigId, utils.DbId, utils.StorageId, utils.InbucketId} + volumes := []string{ + utils.ConfigId, + utils.DbId, + utils.StorageId, + utils.EdgeRuntimeId, + utils.InbucketId, + } result = utils.WaitAll(volumes, func(name string) error { if err := utils.Docker.VolumeRemove(ctx, name, true); err != nil && !errdefs.IsNotFound(err) { return fmt.Errorf("Failed to remove volume %s: %w", name, err)