Skip to content
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

Enable arbitrary env vars to be propagated to Complement containers #382

Merged
merged 1 commit into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")
Expand Down
10 changes: 10 additions & 0 deletions internal/docker/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"log"
"net/http"
"net/url"
"os"
"runtime"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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,
Expand Down