mirror of
https://code.tvl.fyi/depot.git:/tools/nixery.git
synced 2025-03-15 06:01:51 +00:00
feat(server): Add configuration option for Nix build timeouts
Adds a NIX_TIMEOUT environment variable which can be set to a number of seconds that is the maximum allowed time each Nix builder can run. By default this is set to 60 seconds, which should be plenty for most use-cases as Nixery is not expected to be performing builds of uncached binaries in most production cases. Currently the errors Nix throws on a build timeout are not separated from other types of errors, meaning that users will see a generic 500 server error in case of a timeout. This fixes #47
This commit is contained in:
parent
66c4d83b07
commit
f084124318
|
@ -119,6 +119,7 @@ func BuildImage(ctx *context.Context, cfg *config.Config, cache *BuildCache, ima
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
|
"--timeout", cfg.Timeout,
|
||||||
"--argstr", "name", image.Name,
|
"--argstr", "name", image.Name,
|
||||||
"--argstr", "packages", string(packages),
|
"--argstr", "packages", string(packages),
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,10 +102,12 @@ func signingOptsFromEnv() *storage.SignedURLOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfig(key, desc string) string {
|
func getConfig(key, desc, def string) string {
|
||||||
value := os.Getenv(key)
|
value := os.Getenv(key)
|
||||||
if value == "" {
|
if value == "" && def == "" {
|
||||||
log.Fatalln(desc + " must be specified")
|
log.Fatalln(desc + " must be specified")
|
||||||
|
} else if value == "" {
|
||||||
|
return def
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
@ -117,15 +119,17 @@ type Config struct {
|
||||||
Signing *storage.SignedURLOptions // Signing options to use for GCS URLs
|
Signing *storage.SignedURLOptions // Signing options to use for GCS URLs
|
||||||
Port string // Port on which to launch HTTP server
|
Port string // Port on which to launch HTTP server
|
||||||
Pkgs *PkgSource // Source for Nix package set
|
Pkgs *PkgSource // Source for Nix package set
|
||||||
WebDir string
|
Timeout string // Timeout for a single Nix builder (seconds)
|
||||||
|
WebDir string // Directory with static web assets
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromEnv() *Config {
|
func FromEnv() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Bucket: getConfig("BUCKET", "GCS bucket for layer storage"),
|
Bucket: getConfig("BUCKET", "GCS bucket for layer storage", ""),
|
||||||
Port: getConfig("PORT", "HTTP port"),
|
Port: getConfig("PORT", "HTTP port", ""),
|
||||||
Pkgs: pkgSourceFromEnv(),
|
Pkgs: pkgSourceFromEnv(),
|
||||||
Signing: signingOptsFromEnv(),
|
Signing: signingOptsFromEnv(),
|
||||||
WebDir: getConfig("WEB_DIR", "Static web file dir"),
|
Timeout: getConfig("NIX_TIMEOUT", "Nix builder timeout", "60"),
|
||||||
|
WebDir: getConfig("WEB_DIR", "Static web file dir", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user