Skip to content

Commit af2ba00

Browse files
committed
Add CODER_CONFIG_PATH
1 parent 8abe48c commit af2ba00

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

cli/deployment/config.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
"github.com/coder/coder/buildinfo"
1818
"github.com/coder/coder/cli/cliui"
19-
"github.com/coder/coder/cli/config"
2019
"github.com/coder/coder/codersdk"
2120
)
2221

@@ -161,6 +160,13 @@ func newConfig() *codersdk.DeploymentConfig {
161160
Flag: "cache-dir",
162161
Default: DefaultCacheDir(),
163162
},
163+
ConfigPath: &codersdk.DeploymentConfigField[string]{
164+
Name: "Config file path",
165+
Usage: "If provided, coder server will use this configuration file in addition to provided flags.",
166+
Flag: "config",
167+
Shorthand: "c",
168+
Default: "",
169+
},
164170
InMemoryDatabase: &codersdk.DeploymentConfigField[bool]{
165171
Name: "In Memory Database",
166172
Usage: "Controls whether data will be stored in an in-memory database.",
@@ -574,17 +580,13 @@ func newConfig() *codersdk.DeploymentConfig {
574580
}
575581

576582
//nolint:revive
577-
func Config(flagset *pflag.FlagSet, vip *viper.Viper) (*codersdk.DeploymentConfig, error) {
583+
func Config(configPath string, vip *viper.Viper) (*codersdk.DeploymentConfig, error) {
578584
dc := newConfig()
579-
flg, err := flagset.GetString(config.FlagName)
580-
if err != nil {
581-
return nil, xerrors.Errorf("get global config from flag: %w", err)
582-
}
583-
vip.SetEnvPrefix("coder")
585+
vip.SetEnvPrefix("CODER")
584586

585-
if flg != "" {
586-
vip.SetConfigFile(flg + "/server.yaml")
587-
err = vip.ReadInConfig()
587+
if configPath != "" {
588+
vip.SetConfigFile(configPath)
589+
err := vip.ReadInConfig()
588590
if err != nil && !xerrors.Is(err, os.ErrNotExist) {
589591
return dc, xerrors.Errorf("reading deployment config: %w", err)
590592
}

cli/deployment/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func TestConfig(t *testing.T) {
256256
for key, value := range tc.Env {
257257
t.Setenv(key, value)
258258
}
259-
config, err := deployment.Config(flagSet, viper)
259+
config, err := deployment.Config("", viper)
260260
require.NoError(t, err)
261261
tc.Valid(config)
262262
})

cli/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
9696

9797
go dumpHandler(ctx)
9898

99-
cfg, err := deployment.Config(cmd.Flags(), vip)
99+
configPath, _ := cmd.Flags().GetString("config")
100+
cfg, err := deployment.Config(configPath, vip)
100101
if err != nil {
101102
return xerrors.Errorf("getting deployment config: %w", err)
102103
}

codersdk/deployment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ type DeploymentConfig struct {
148148
SessionDuration *DeploymentConfigField[time.Duration] `json:"max_session_expiry" typescript:",notnull"`
149149
DisableSessionExpiryRefresh *DeploymentConfigField[bool] `json:"disable_session_expiry_refresh" typescript:",notnull"`
150150
DisablePasswordAuth *DeploymentConfigField[bool] `json:"disable_password_auth" typescript:",notnull"`
151+
ConfigPath *DeploymentConfigField[string] `json:"config_path" typescript:",notnull"`
151152

152153
// DEPRECATED: Use HTTPAddress or TLS.Address instead.
153154
Address *DeploymentConfigField[string] `json:"address" typescript:",notnull"`

0 commit comments

Comments
 (0)