Skip to content

Commit 40d00af

Browse files
committed
fix: Accept CODER_CACHE_DIRECTORY with CACHE_DIRECTORY fallback
Fixes #2199
1 parent 06021bd commit 40d00af

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cli/server.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func server() *cobra.Command {
6868
promAddress string
6969
pprofEnabled bool
7070
pprofAddress string
71+
defaultCacheDir = filepath.Join(os.TempDir(), "coder-cache")
7172
cacheDir string
7273
dev bool
7374
devUserEmail string
@@ -99,6 +100,11 @@ func server() *cobra.Command {
99100
Use: "server",
100101
Short: "Start a Coder server",
101102
RunE: func(cmd *cobra.Command, args []string) error {
103+
if cacheDir == defaultCacheDir && os.Getenv("CACHE_DIRECTORY") != "" {
104+
// For compatibility with systemd.
105+
cacheDir = os.Getenv("CACHE_DIRECTORY")
106+
}
107+
102108
logger := slog.Make(sloghuman.Sink(os.Stderr))
103109
buildModeDev := semver.Prerelease(buildinfo.Version()) == "-devel"
104110
if verbose || buildModeDev {
@@ -473,8 +479,7 @@ func server() *cobra.Command {
473479
cliflag.StringVarP(root.Flags(), &promAddress, "prometheus-address", "", "CODER_PROMETHEUS_ADDRESS", "127.0.0.1:2112", "The address to serve prometheus metrics.")
474480
cliflag.BoolVarP(root.Flags(), &pprofEnabled, "pprof-enable", "", "CODER_PPROF_ENABLE", false, "Enable serving pprof metrics on the address defined by --pprof-address.")
475481
cliflag.StringVarP(root.Flags(), &pprofAddress, "pprof-address", "", "CODER_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.")
476-
// systemd uses the CACHE_DIRECTORY environment variable!
477-
cliflag.StringVarP(root.Flags(), &cacheDir, "cache-dir", "", "CACHE_DIRECTORY", filepath.Join(os.TempDir(), "coder-cache"), "Specifies a directory to cache binaries for provision operations.")
482+
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.")
478483
cliflag.BoolVarP(root.Flags(), &dev, "dev", "", "CODER_DEV_MODE", false, "Serve Coder in dev mode for tinkering")
479484
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)")
480485
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")

0 commit comments

Comments
 (0)