diff --git a/internal/config/config.go b/internal/config/config.go index 9cac80b0..6c8da9ad 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -22,14 +22,15 @@ type HostMount struct { } type Complement struct { - BaseImageURI string - BaseImageArgs []string - DebugLoggingEnabled bool - AlwaysPrintServerLogs bool - BestEffort bool - SpawnHSTimeout time.Duration - KeepBlueprints []string - HostMounts []HostMount + BaseImageURI string + BaseImageArgs []string + DebugLoggingEnabled bool + AlwaysPrintServerLogs bool + BestEffort bool + EnvVarsPropagatePrefix string + SpawnHSTimeout time.Duration + KeepBlueprints []string + HostMounts []HostMount // The namespace for all complement created blueprints and deployments PackageNamespace string // Certificate Authority generated values for this run of complement. Homeservers will use this @@ -47,6 +48,7 @@ func NewConfigFromEnvVars(pkgNamespace, baseImageURI string) *Complement { cfg.BaseImageArgs = strings.Split(os.Getenv("COMPLEMENT_BASE_IMAGE_ARGS"), " ") cfg.DebugLoggingEnabled = os.Getenv("COMPLEMENT_DEBUG") == "1" cfg.AlwaysPrintServerLogs = os.Getenv("COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS") == "1" + cfg.EnvVarsPropagatePrefix = os.Getenv("COMPLEMENT_SHARE_ENV_PREFIX") cfg.SpawnHSTimeout = time.Duration(parseEnvWithDefault("COMPLEMENT_SPAWN_HS_TIMEOUT_SECS", 30)) * time.Second if os.Getenv("COMPLEMENT_VERSION_CHECK_ITERATIONS") != "" { fmt.Fprintln(os.Stderr, "Deprecated: COMPLEMENT_VERSION_CHECK_ITERATIONS will be removed in a later version. Use COMPLEMENT_SPAWN_HS_TIMEOUT_SECS instead which does the same thing and is clearer.") diff --git a/internal/docker/deployer.go b/internal/docker/deployer.go index deee3d59..8582954f 100644 --- a/internal/docker/deployer.go +++ b/internal/docker/deployer.go @@ -22,7 +22,9 @@ import ( "log" "net/http" "net/url" + "os" "runtime" + "strings" "sync" "time" @@ -196,6 +198,14 @@ func deployImage( env := []string{ "SERVER_NAME=" + hsName, } + if cfg.EnvVarsPropagatePrefix != "" { + for _, ev := range os.Environ() { + if strings.HasPrefix(ev, cfg.EnvVarsPropagatePrefix) { + env = append(env, strings.TrimPrefix(ev, cfg.EnvVarsPropagatePrefix)) + } + } + log.Printf("Sharing %v host environment variables with container", env) + } body, err := docker.ContainerCreate(ctx, &container.Config{ Image: imageID,