-
Notifications
You must be signed in to change notification settings - Fork 903
feat: refactor deployment config #6347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
6c29207
12dcc45
d1e2e15
8db4626
dc81f47
d511001
8cc406e
18b2552
bad7aca
f075ad5
69600d7
63159a6
03b08fa
e0d6c1e
5bebd0f
2c7b39d
05b3a10
dcbd0d8
fc06f64
d31fa37
0d7d557
f3d45d3
d322114
8f9d44b
acac92d
1c8359b
8d0020f
882a80f
ae858b4
b34d481
e0e113b
02c8f6c
000466f
c6133f2
ab21e8f
b816b1a
559b046
3b24149
e422c1d
ea6c3b7
d4aa8d3
58b6324
cae2eab
d4bd380
8a493ef
84b59be
ac3507f
95db142
790f45a
360b600
2344013
394fbfa
ac909b5
8a2637d
3ed919e
d397839
957500b
0890005
622df7f
362618e
2fa8b78
28e4b07
410ad26
5c3f648
f29889f
6ced9cf
d9d1592
74c6da2
9e53c96
06f82b5
2f5a522
53e92fc
e9e2908
c3a11fd
a090cd4
d9a8da6
e53367a
6252316
bf1a099
274d5c5
a213d25
2938980
140438e
46936f5
06277c4
fc8e6ca
2a74445
3cfb4bf
4d8bc75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"crypto/x509" | ||
"database/sql" | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"log" | ||
|
@@ -96,19 +97,31 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close | |
cfg := codersdk.NewDeploymentConfig() | ||
cliOpts := cfg.ConfigOptions() | ||
|
||
_, err := cliOpts.ParseFlags(args...) | ||
var configDir bigcli.String | ||
// This is a hack to get around the fact that the Cobra-defined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume Global Config won't appear in the help either right now... |
||
// flags are not available. | ||
cliOpts.Add(bigcli.Option{ | ||
Name: "Global Config", | ||
Flag: config.FlagName, | ||
Usage: "Global Config is ignored in server mode.", | ||
Hidden: true, | ||
Default: config.DefaultDir(), | ||
Value: &configDir, | ||
}) | ||
|
||
err := cliOpts.SetDefaults() | ||
if err != nil { | ||
return xerrors.Errorf("parse flags: %w", err) | ||
return xerrors.Errorf("set defaults: %w", err) | ||
} | ||
|
||
err = cliOpts.ParseEnv("CODER_", os.Environ()) | ||
_, err = cliOpts.ParseFlags(args...) | ||
if err != nil { | ||
return xerrors.Errorf("parse env: %w", err) | ||
return xerrors.Errorf("parse flags: %w", err) | ||
} | ||
|
||
err = cliOpts.SetDefaults() | ||
err = cliOpts.ParseEnv("CODER_", os.Environ()) | ||
if err != nil { | ||
return xerrors.Errorf("set defaults: %w", err) | ||
return xerrors.Errorf("parse env: %w", err) | ||
} | ||
|
||
// Print deprecation warnings. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a function in |
||
|
@@ -134,7 +147,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close | |
go dumpHandler(ctx) | ||
|
||
// Validate bind addresses. | ||
if cfg.Address.Host != "" { | ||
if cfg.Address.String() != "" { | ||
if cfg.TLS.Enable { | ||
cfg.HTTPAddress.Host = "" | ||
cfg.TLS.Address = cfg.Address | ||
|
@@ -143,10 +156,10 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close | |
cfg.TLS.Address.Host = "" | ||
} | ||
} | ||
if cfg.TLS.Enable && cfg.TLS.Address.Host == "" { | ||
if cfg.TLS.Enable && cfg.TLS.Address.String() == "" { | ||
return xerrors.Errorf("TLS address must be set if TLS is enabled") | ||
} | ||
if !cfg.TLS.Enable && cfg.HTTPAddress.Host == "" { | ||
if !cfg.TLS.Enable && cfg.HTTPAddress.String() == "" { | ||
return xerrors.Errorf("TLS is disabled. Enable with --tls-enable or specify a HTTP address") | ||
} | ||
|
||
|
@@ -155,7 +168,6 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close | |
loginRateLimit := 60 | ||
filesRateLimit := 12 | ||
if cfg.RateLimit.DisableAll { | ||
|
||
cfg.RateLimit.API = -1 | ||
loginRateLimit = -1 | ||
filesRateLimit = -1 | ||
|
@@ -233,7 +245,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close | |
} | ||
} | ||
|
||
config := createConfig(cmd) | ||
config := config.Root(configDir) | ||
builtinPostgres := false | ||
// Only use built-in if PostgreSQL URL isn't specified! | ||
if !cfg.InMemoryDatabase && cfg.PostgresURL == "" { | ||
|
@@ -264,7 +276,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close | |
httpListener net.Listener | ||
httpURL *url.URL | ||
) | ||
if cfg.HTTPAddress.Host != "" { | ||
if cfg.HTTPAddress.String() != "" { | ||
httpListener, err = net.Listen("tcp", cfg.HTTPAddress.String()) | ||
if err != nil { | ||
return xerrors.Errorf("listen %q: %w", cfg.HTTPAddress.String(), err) | ||
|
@@ -304,7 +316,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close | |
httpsURL *url.URL | ||
) | ||
if cfg.TLS.Enable { | ||
if cfg.TLS.Address.Host == "" { | ||
if cfg.TLS.Address.String() == "" { | ||
return xerrors.New("tls address must be set if tls is enabled") | ||
} | ||
|
||
|
@@ -736,7 +748,10 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close | |
// This is helpful for tests, but can be silently ignored. | ||
// Coder may be ran as users that don't have permission to write in the homedir, | ||
// such as via the systemd service. | ||
_ = config.URL().Write(client.URL.String()) | ||
err = config.URL().Write(client.URL.String()) | ||
if err != nil && flag.Lookup("test.v") != nil { | ||
return xerrors.Errorf("write config url: %w", err) | ||
} | ||
|
||
// Since errCh only has one buffered slot, all routines | ||
// sending on it must be wrapped in a select/default to | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong type name!