current state: Not Working... at all
I was tweaking the entrypoint and now its like it just randomly drops env-vars or fails to read them *no reason* despite them being confirmed to exist via other methods (manual running of commands within container, sanity checking in the entrypoint)
This commit is contained in:
parent
c7098ae0f6
commit
048450dee9
4 changed files with 101 additions and 62 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// loadEnvVars loads configuration settings from environment variables
|
||||
|
@ -14,53 +16,59 @@ func loadEnvVars(config *Config) {
|
|||
// This implementation causes env-vars to override config file settings,
|
||||
// without writing to the config file.
|
||||
|
||||
// SkipEnv if variable is set
|
||||
if _, ok := os.LookupEnv("RUNNER__SKIP_ENV"); ok {
|
||||
return
|
||||
if debug, ok := os.LookupEnv("DEBUG"); ok && debug == "true" {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.Debug("Debug logging enabled")
|
||||
}
|
||||
|
||||
// Log
|
||||
loadEnvStr(config, "RUNNER__LOG__LEVEL", &config.Log.Level)
|
||||
loadEnvStr(config, "RUNNER__LOG__JOB_LEVEL", &config.Log.JobLevel)
|
||||
loadEnvStr(config, "RUNNER__log__LEVEL", &config.Log.Level)
|
||||
loadEnvStr(config, "RUNNER__log__JOB_LEVEL", &config.Log.JobLevel)
|
||||
|
||||
// Runner
|
||||
loadEnvStr(config, "RUNNER__RUNNER__FILE", &config.Runner.File)
|
||||
loadEnvInt(config, "RUNNER__RUNNER__CAPACITY", &config.Runner.Capacity)
|
||||
loadEnvTable(config, "RUNNER__RUNNER__ENVS", &config.Runner.Envs)
|
||||
loadEnvStr(config, "RUNNER__RUNNER__ENV_FILE", &config.Runner.EnvFile)
|
||||
loadEnvDuration(config, "RUNNER__RUNNER__SHUTDOWN_TIMEOUT", &config.Runner.ShutdownTimeout)
|
||||
loadEnvBool(config, "RUNNER__RUNNER__INSECURE", &config.Runner.Insecure)
|
||||
loadEnvDuration(config, "RUNNER__RUNNER__FETCH_TIMEOUT", &config.Runner.FetchTimeout)
|
||||
loadEnvDuration(config, "RUNNER__RUNNER__FETCH_INTERVAL", &config.Runner.FetchInterval)
|
||||
loadEnvDuration(config, "RUNNER__RUNNER__REPORT_INTERVAL", &config.Runner.ReportInterval)
|
||||
loadEnvList(config, "RUNNER__RUNNER__LABELS", &config.Runner.Labels)
|
||||
loadEnvStr(config, "RUNNER__runner__FILE", &config.Runner.File)
|
||||
loadEnvInt(config, "RUNNER__runner__CAPACITY", &config.Runner.Capacity)
|
||||
loadEnvTable(config, "RUNNER__runner__ENVS", &config.Runner.Envs)
|
||||
loadEnvStr(config, "RUNNER__runner__ENV_FILE", &config.Runner.EnvFile)
|
||||
loadEnvDuration(config, "RUNNER__runner__SHUTDOWN_TIMEOUT", &config.Runner.ShutdownTimeout)
|
||||
loadEnvBool(config, "RUNNER__runner__INSECURE", &config.Runner.Insecure)
|
||||
loadEnvDuration(config, "RUNNER__runner__FETCH_TIMEOUT", &config.Runner.FetchTimeout)
|
||||
loadEnvDuration(config, "RUNNER__runner__FETCH_INTERVAL", &config.Runner.FetchInterval)
|
||||
loadEnvDuration(config, "RUNNER__runner__REPORT_INTERVAL", &config.Runner.ReportInterval)
|
||||
loadEnvList(config, "RUNNER__runner__LABELS", &config.Runner.Labels)
|
||||
|
||||
// Cache
|
||||
loadEnvBool(config, "RUNNER__CACHE__ENABLED", config.Cache.Enabled)
|
||||
loadEnvStr(config, "RUNNER__CACHE__DIR", &config.Cache.Dir)
|
||||
loadEnvStr(config, "RUNNER__CACHE__HOST", &config.Cache.Host)
|
||||
loadEnvUInt16(config, "RUNNER__CACHE__PORT", &config.Cache.Port)
|
||||
loadEnvStr(config, "RUNNER__CACHE__EXTERNAL_SERVER", &config.Cache.ExternalServer)
|
||||
loadEnvBool(config, "RUNNER__cache__ENABLED", config.Cache.Enabled)
|
||||
loadEnvStr(config, "RUNNER__cache__DIR", &config.Cache.Dir)
|
||||
loadEnvStr(config, "RUNNER__cache__HOST", &config.Cache.Host)
|
||||
loadEnvUInt16(config, "RUNNER__cache__PORT", &config.Cache.Port)
|
||||
loadEnvStr(config, "RUNNER__cache__EXTERNAL_SERVER", &config.Cache.ExternalServer)
|
||||
|
||||
// Container
|
||||
loadEnvStr(config, "RUNNER__CONTAINER__NETWORK", &config.Container.Network)
|
||||
loadEnvStr(config, "RUNNER__CONTAINER__NETWORK_MODE", &config.Container.NetworkMode)
|
||||
loadEnvBool(config, "RUNNER__CONTAINER__ENABLE_IPV6", &config.Container.EnableIPv6)
|
||||
loadEnvBool(config, "RUNNER__CONTAINER__PRIVILEGED", &config.Container.Privileged)
|
||||
loadEnvStr(config, "RUNNER__CONTAINER__OPTIONS", &config.Container.Options)
|
||||
loadEnvStr(config, "RUNNER__CONTAINER__WORKDIR_PARENT", &config.Container.WorkdirParent)
|
||||
loadEnvList(config, "RUNNER__CONTAINER__VALID_VOLUMES", &config.Container.ValidVolumes)
|
||||
loadEnvStr(config, "RUNNER__CONTAINER__DOCKER_HOST", &config.Container.DockerHost)
|
||||
loadEnvBool(config, "RUNNER__CONTAINER__FORCE_PULL", &config.Container.ForcePull)
|
||||
loadEnvStr(config, "RUNNER__container__NETWORK", &config.Container.Network)
|
||||
loadEnvStr(config, "RUNNER__container__NETWORK_MODE", &config.Container.NetworkMode)
|
||||
loadEnvBool(config, "RUNNER__container__ENABLE_IPV6", &config.Container.EnableIPv6)
|
||||
loadEnvBool(config, "RUNNER__container__PRIVILEGED", &config.Container.Privileged)
|
||||
loadEnvStr(config, "RUNNER__container__OPTIONS", &config.Container.Options)
|
||||
loadEnvStr(config, "RUNNER__container__WORKDIR_PARENT", &config.Container.WorkdirParent)
|
||||
loadEnvList(config, "RUNNER__container__VALID_VOLUMES", &config.Container.ValidVolumes)
|
||||
loadEnvStr(config, "RUNNER__container__DOCKER_HOST", &config.Container.DockerHost)
|
||||
loadEnvBool(config, "RUNNER__container__FORCE_PULL", &config.Container.ForcePull)
|
||||
|
||||
// Host
|
||||
loadEnvStr(config, "RUNNER__HOST__WORKDIR_PARENT", &config.Host.WorkdirParent)
|
||||
loadEnvStr(config, "RUNNER__host__WORKDIR_PARENT", &config.Host.WorkdirParent)
|
||||
}
|
||||
|
||||
// loadEnvStr loads an environment variable into the provided string pointer if it exists.
|
||||
// General Coverage Docs for below:
|
||||
// loadEnvType, where Type is the type of the variable being loaded, loads an environment variable into the provided pointer if the environment variable exists and is not empty.
|
||||
// The key parameter is the environment variable key to look for.
|
||||
// The dest parameter is a pointer to the variable to load the environment variable into.
|
||||
// Config is present but unused, it remains for future use to prevent the need to redo the above functions.
|
||||
|
||||
func loadEnvStr(config *Config, key string, dest *string) {
|
||||
// Example: RUNNER__LOG__LEVEL = "info"
|
||||
if v := os.Getenv(key); v != "" {
|
||||
log.Debug("Loading env var: ", key, "=", v)
|
||||
*dest = v
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +78,7 @@ func loadEnvInt(config *Config, key string, dest *int) {
|
|||
// Example: RUNNER__RUNNER__CAPACITY = "1"
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if intValue, err := strconv.Atoi(v); err == nil {
|
||||
log.Debug("Loading env var: ", key, "=", v)
|
||||
*dest = intValue
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +89,7 @@ func loadEnvUInt16(config *Config, key string, dest *uint16) {
|
|||
// Example: RUNNER__CACHE__PORT = "8080"
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if uint16Value, err := strconv.ParseUint(v, 10, 16); err == nil {
|
||||
log.Debug("Loading env var: ", key, "=", v)
|
||||
*dest = uint16(uint16Value)
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +100,7 @@ func loadEnvDuration(config *Config, key string, dest *time.Duration) {
|
|||
// Example: RUNNER__RUNNER__SHUTDOWN_TIMEOUT = "3h"
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if durationValue, err := time.ParseDuration(v); err == nil {
|
||||
log.Debug("Loading env var: ", key, "=", v)
|
||||
*dest = durationValue
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +111,7 @@ func loadEnvBool(config *Config, key string, dest *bool) {
|
|||
// Example: RUNNER__RUNNER__INSECURE = "false"
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if boolValue, err := strconv.ParseBool(v); err == nil {
|
||||
log.Debug("Loading env var: ", key, "=", v)
|
||||
*dest = boolValue
|
||||
}
|
||||
}
|
||||
|
@ -123,6 +135,7 @@ func loadEnvTable(config *Config, key string, dest *map[string]string) {
|
|||
func loadEnvList(config *Config, key string, dest *[]string) {
|
||||
// Example: RUNNER__RUNNER__LABELS = "label1, label2, label3"
|
||||
if v := os.Getenv(key); v != "" {
|
||||
log.Debug("Loading env var: ", key, "=", v)
|
||||
*dest = splitAndTrim(v)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,5 +173,15 @@ func LoadDefault(file string) (*Config, error) {
|
|||
// Load environment variables at the end to allow for overriding the default values.
|
||||
loadEnvVars(cfg)
|
||||
|
||||
// Write the state of the config, including default values, to a debug file.
|
||||
debugFile := file + ".debug.yml"
|
||||
content, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("marshal config to debug file %q: %w", debugFile, err)
|
||||
}
|
||||
if err := os.WriteFile(debugFile, content, 0644); err != nil {
|
||||
return nil, fmt.Errorf("write debug config file %q: %w", debugFile, err)
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue