mirror of
https://github.com/rancher/os.git
synced 2025-09-02 07:15:41 +00:00
Support environment globbing for prefix only
You can now put FOO* in the compose environment and it will find all environment variables that start with FOO
This commit is contained in:
@@ -2,6 +2,7 @@ package docker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/rancherio/os/config"
|
"github.com/rancherio/os/config"
|
||||||
@@ -13,20 +14,40 @@ type configEnvironemnt struct {
|
|||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configEnvironemnt) Lookup(key, serviceName string, serviceConfig *project.ServiceConfig) []string {
|
func appendEnv(array []string, key, value string) []string {
|
||||||
result := ""
|
parts := strings.SplitN(key, "/", 2)
|
||||||
fullKey := fmt.Sprintf("%s/%s", serviceName, key)
|
if len(parts) == 2 {
|
||||||
if value, ok := c.cfg.Environment[fullKey]; ok {
|
key = parts[1]
|
||||||
result = value
|
|
||||||
} else if value, ok := c.cfg.Environment[key]; ok {
|
|
||||||
result = value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if result == "" {
|
return append(array, fmt.Sprintf("%s=%s", key, value))
|
||||||
return []string{}
|
}
|
||||||
} else {
|
|
||||||
return []string{fmt.Sprintf("%s=%s", key, result)}
|
func lookupKeys(cfg *config.Config, keys ...string) []string {
|
||||||
|
for _, key := range keys {
|
||||||
|
if strings.HasSuffix(key, "*") {
|
||||||
|
result := []string{}
|
||||||
|
for envKey, envValue := range cfg.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 := cfg.Environment[key]; ok {
|
||||||
|
return appendEnv([]string{}, key, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *configEnvironemnt) Lookup(key, serviceName string, serviceConfig *project.ServiceConfig) []string {
|
||||||
|
fullKey := fmt.Sprintf("%s/%s", serviceName, key)
|
||||||
|
return lookupKeys(c.cfg, fullKey, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunServices(name string, cfg *config.Config, configs map[string]*project.ServiceConfig) error {
|
func RunServices(name string, cfg *config.Config, configs map[string]*project.ServiceConfig) error {
|
||||||
|
Reference in New Issue
Block a user