1
0
mirror of https://github.com/rancher/os.git synced 2025-09-20 10:03:59 +00:00
Files
os/pkg/docker/env.go
Olli Janatuinen 872f1cd6da Initiate Burmilla OS project
- Use burmilla GitHub repos
- Release under burmilla Docker Hub
- GitHub action for create releases
- Updated boot image and login banner
- Use Debian as default console
- Updated system-cron to v0.5.0
- Updated services to latest versions
- Bump up kernel to 4.14.206
- Include burmilla/os-debianconsole:v1.9.0 to initrd
2021-02-18 20:07:36 +02:00

85 lines
2.1 KiB
Go

package docker
import (
"fmt"
"strings"
"github.com/burmilla/os/config"
"github.com/burmilla/os/pkg/log"
composeConfig "github.com/docker/libcompose/config"
)
type ConfigEnvironment struct {
cfg *config.CloudConfig
}
func NewConfigEnvironment(cfg *config.CloudConfig) *ConfigEnvironment {
return &ConfigEnvironment{
cfg: cfg,
}
}
func appendEnv(array []string, key, value string) []string {
parts := strings.SplitN(key, "/", 2)
if len(parts) == 2 {
key = parts[1]
}
return append(array, fmt.Sprintf("%s=%s", key, value))
}
func environmentFromCloudConfig(cfg *config.CloudConfig) map[string]string {
environment := cfg.Rancher.Environment
if cfg.Rancher.Network.HTTPProxy != "" {
environment["http_proxy"] = cfg.Rancher.Network.HTTPProxy
environment["HTTP_PROXY"] = cfg.Rancher.Network.HTTPProxy
}
if cfg.Rancher.Network.HTTPSProxy != "" {
environment["https_proxy"] = cfg.Rancher.Network.HTTPSProxy
environment["HTTPS_PROXY"] = cfg.Rancher.Network.HTTPSProxy
}
if cfg.Rancher.Network.NoProxy != "" {
environment["no_proxy"] = cfg.Rancher.Network.NoProxy
environment["NO_PROXY"] = cfg.Rancher.Network.NoProxy
}
if v := config.GetKernelVersion(); v != "" {
environment["KERNEL_VERSION"] = v
log.Debugf("Using /proc/version to set rancher.environment.KERNEL_VERSION = %s", v)
}
return environment
}
func lookupKeys(cfg *config.CloudConfig, keys ...string) []string {
environment := environmentFromCloudConfig(cfg)
for _, key := range keys {
if strings.HasSuffix(key, "*") {
result := []string{}
for envKey, envValue := range environment {
keyPrefix := key[:len(key)-1]
if strings.HasPrefix(envKey, keyPrefix) {
result = appendEnv(result, envKey, envValue)
}
}
if len(result) > 0 {
return result
}
} else if value, ok := environment[key]; ok {
return appendEnv([]string{}, key, value)
}
}
return []string{}
}
func (c *ConfigEnvironment) SetConfig(cfg *config.CloudConfig) {
c.cfg = cfg
}
func (c *ConfigEnvironment) Lookup(key, serviceName string, serviceConfig *composeConfig.ServiceConfig) []string {
fullKey := fmt.Sprintf("%s/%s", serviceName, key)
return lookupKeys(c.cfg, fullKey, key)
}