From 40d00afcec6558aeaab87d69d0f522e7712fe3ca Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 10 Jun 2022 15:17:54 +0300 Subject: [PATCH 1/3] fix: Accept CODER_CACHE_DIRECTORY with CACHE_DIRECTORY fallback Fixes #2199 --- cli/server.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/server.go b/cli/server.go index 02af6a822f112..ae6fb0e4c5e82 100644 --- a/cli/server.go +++ b/cli/server.go @@ -68,6 +68,7 @@ func server() *cobra.Command { promAddress string pprofEnabled bool pprofAddress string + defaultCacheDir = filepath.Join(os.TempDir(), "coder-cache") cacheDir string dev bool devUserEmail string @@ -99,6 +100,11 @@ func server() *cobra.Command { Use: "server", Short: "Start a Coder server", RunE: func(cmd *cobra.Command, args []string) error { + if cacheDir == defaultCacheDir && os.Getenv("CACHE_DIRECTORY") != "" { + // For compatibility with systemd. + cacheDir = os.Getenv("CACHE_DIRECTORY") + } + logger := slog.Make(sloghuman.Sink(os.Stderr)) buildModeDev := semver.Prerelease(buildinfo.Version()) == "-devel" if verbose || buildModeDev { @@ -473,8 +479,7 @@ func server() *cobra.Command { cliflag.StringVarP(root.Flags(), &promAddress, "prometheus-address", "", "CODER_PROMETHEUS_ADDRESS", "127.0.0.1:2112", "The address to serve prometheus metrics.") cliflag.BoolVarP(root.Flags(), &pprofEnabled, "pprof-enable", "", "CODER_PPROF_ENABLE", false, "Enable serving pprof metrics on the address defined by --pprof-address.") cliflag.StringVarP(root.Flags(), &pprofAddress, "pprof-address", "", "CODER_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.") - // systemd uses the CACHE_DIRECTORY environment variable! - cliflag.StringVarP(root.Flags(), &cacheDir, "cache-dir", "", "CACHE_DIRECTORY", filepath.Join(os.TempDir(), "coder-cache"), "Specifies a directory to cache binaries for provision operations.") + cliflag.StringVarP(root.Flags(), &cacheDir, "cache-dir", "", "CODER_CACHE_DIRECTORY", defaultCacheDir, "Specifies a directory to cache binaries for provision operations. If unspecified and $CACHE_DIRECTORY is set, it will be used for compatibility with systemd.") cliflag.BoolVarP(root.Flags(), &dev, "dev", "", "CODER_DEV_MODE", false, "Serve Coder in dev mode for tinkering") cliflag.StringVarP(root.Flags(), &devUserEmail, "dev-admin-email", "", "CODER_DEV_ADMIN_EMAIL", "admin@coder.com", "Specifies the admin email to be used in dev mode (--dev)") cliflag.StringVarP(root.Flags(), &devUserPassword, "dev-admin-password", "", "CODER_DEV_ADMIN_PASSWORD", "", "Specifies the admin password to be used in dev mode (--dev) instead of a randomly generated one") From 9e458d0cabe51622c1b1c87f96e75f33eb2c1638 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 10 Jun 2022 15:23:49 +0300 Subject: [PATCH 2/3] fix: Reveal CACHE_DIRECTORY value by updating default --- cli/server.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/server.go b/cli/server.go index ae6fb0e4c5e82..993c62e545f84 100644 --- a/cli/server.go +++ b/cli/server.go @@ -60,6 +60,12 @@ import ( // nolint:gocyclo func server() *cobra.Command { + defaultCacheDir := filepath.Join(os.TempDir(), "coder-cache") + if dir := os.Getenv("CACHE_DIRECTORY"); dir != "" { + // For compatibility with systemd. + defaultCacheDir = dir + } + var ( accessURL string address string @@ -68,7 +74,6 @@ func server() *cobra.Command { promAddress string pprofEnabled bool pprofAddress string - defaultCacheDir = filepath.Join(os.TempDir(), "coder-cache") cacheDir string dev bool devUserEmail string @@ -100,11 +105,6 @@ func server() *cobra.Command { Use: "server", Short: "Start a Coder server", RunE: func(cmd *cobra.Command, args []string) error { - if cacheDir == defaultCacheDir && os.Getenv("CACHE_DIRECTORY") != "" { - // For compatibility with systemd. - cacheDir = os.Getenv("CACHE_DIRECTORY") - } - logger := slog.Make(sloghuman.Sink(os.Stderr)) buildModeDev := semver.Prerelease(buildinfo.Version()) == "-devel" if verbose || buildModeDev { From 7602173bdc8e5a9b8370f8eb402c5b75e5c9a3d3 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 10 Jun 2022 15:26:43 +0300 Subject: [PATCH 3/3] chore: Move defaultCacheDir closer to use --- cli/server.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cli/server.go b/cli/server.go index 993c62e545f84..2fbc645edb1b9 100644 --- a/cli/server.go +++ b/cli/server.go @@ -60,12 +60,6 @@ import ( // nolint:gocyclo func server() *cobra.Command { - defaultCacheDir := filepath.Join(os.TempDir(), "coder-cache") - if dir := os.Getenv("CACHE_DIRECTORY"); dir != "" { - // For compatibility with systemd. - defaultCacheDir = dir - } - var ( accessURL string address string @@ -479,6 +473,11 @@ func server() *cobra.Command { cliflag.StringVarP(root.Flags(), &promAddress, "prometheus-address", "", "CODER_PROMETHEUS_ADDRESS", "127.0.0.1:2112", "The address to serve prometheus metrics.") cliflag.BoolVarP(root.Flags(), &pprofEnabled, "pprof-enable", "", "CODER_PPROF_ENABLE", false, "Enable serving pprof metrics on the address defined by --pprof-address.") cliflag.StringVarP(root.Flags(), &pprofAddress, "pprof-address", "", "CODER_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.") + defaultCacheDir := filepath.Join(os.TempDir(), "coder-cache") + if dir := os.Getenv("CACHE_DIRECTORY"); dir != "" { + // For compatibility with systemd. + defaultCacheDir = dir + } cliflag.StringVarP(root.Flags(), &cacheDir, "cache-dir", "", "CODER_CACHE_DIRECTORY", defaultCacheDir, "Specifies a directory to cache binaries for provision operations. If unspecified and $CACHE_DIRECTORY is set, it will be used for compatibility with systemd.") cliflag.BoolVarP(root.Flags(), &dev, "dev", "", "CODER_DEV_MODE", false, "Serve Coder in dev mode for tinkering") cliflag.StringVarP(root.Flags(), &devUserEmail, "dev-admin-email", "", "CODER_DEV_ADMIN_EMAIL", "admin@coder.com", "Specifies the admin email to be used in dev mode (--dev)") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy