forked from LaconicNetwork/kompose
Updated Vendoring
This commit is contained in:
1 parent
5de4aa85f8
commit
b3f2134cec
298 files changed
+27729
-66945
No files matched your search
+5
-1
@@ -86,8 +86,12 @@ func GetServiceHash(name string, config *ServiceConfig) string {
|
||||
for _, sliceKey := range sliceKeys {
|
||||
io.WriteString(hash, fmt.Sprintf("%s, ", sliceKey))
|
||||
}
|
||||
case *yaml.Networks:
|
||||
io.WriteString(hash, fmt.Sprintf("%s, ", s.HashString()))
|
||||
case *yaml.Volumes:
|
||||
io.WriteString(hash, fmt.Sprintf("%s, ", s.HashString()))
|
||||
default:
|
||||
io.WriteString(hash, fmt.Sprintf("%v", serviceValue))
|
||||
io.WriteString(hash, fmt.Sprintf("%v, ", serviceValue))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+44
-2
@@ -5,13 +5,19 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var defaultValues = make(map[string]string)
|
||||
|
||||
func isNum(c uint8) bool {
|
||||
return c >= '0' && c <= '9'
|
||||
}
|
||||
|
||||
func validVariableDefault(c uint8, line string, pos int) bool {
|
||||
return (c == ':' && line[pos+1] == '-') || (c == '-')
|
||||
}
|
||||
|
||||
func validVariableNameChar(c uint8) bool {
|
||||
return c == '_' ||
|
||||
c >= 'A' && c <= 'Z' ||
|
||||
@@ -36,6 +42,30 @@ func parseVariable(line string, pos int, mapping func(string) string) (string, i
|
||||
return mapping(buffer.String()), pos, true
|
||||
}
|
||||
|
||||
func parseDefaultValue(line string, pos int) (string, int, bool) {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
// only skip :, :- and - at the beginning
|
||||
for ; pos < len(line); pos++ {
|
||||
c := line[pos]
|
||||
if c == ':' || c == '-' {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
for ; pos < len(line); pos++ {
|
||||
c := line[pos]
|
||||
if c == '}' {
|
||||
return buffer.String(), pos - 1, true
|
||||
}
|
||||
err := buffer.WriteByte(c)
|
||||
if err != nil {
|
||||
return "", pos, false
|
||||
}
|
||||
}
|
||||
return "", 0, false
|
||||
}
|
||||
|
||||
func parseVariableWithBraces(line string, pos int, mapping func(string) string) (string, int, bool) {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
@@ -49,10 +79,13 @@ func parseVariableWithBraces(line string, pos int, mapping func(string) string)
|
||||
if bufferString == "" {
|
||||
return "", 0, false
|
||||
}
|
||||
|
||||
return mapping(buffer.String()), pos, true
|
||||
case validVariableNameChar(c):
|
||||
buffer.WriteByte(c)
|
||||
case validVariableDefault(c, line, pos):
|
||||
defaultValue := ""
|
||||
defaultValue, pos, _ = parseDefaultValue(line, pos)
|
||||
defaultValues[buffer.String()] = defaultValue
|
||||
default:
|
||||
return "", 0, false
|
||||
}
|
||||
@@ -143,10 +176,19 @@ func Interpolate(key string, data *interface{}, environmentLookup EnvironmentLoo
|
||||
values := environmentLookup.Lookup(s, nil)
|
||||
|
||||
if len(values) == 0 {
|
||||
if val, ok := defaultValues[s]; ok {
|
||||
return val
|
||||
}
|
||||
logrus.Warnf("The %s variable is not set. Substituting a blank string.", s)
|
||||
return ""
|
||||
}
|
||||
|
||||
if strings.SplitN(values[0], "=", 2)[1] == "" {
|
||||
if val, ok := defaultValues[s]; ok {
|
||||
return val
|
||||
}
|
||||
}
|
||||
|
||||
// Use first result if many are given
|
||||
value := values[0]
|
||||
|
||||
|
||||
+2
-9
@@ -6,11 +6,12 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"reflect"
|
||||
|
||||
"github.com/docker/docker/pkg/urlutil"
|
||||
"github.com/docker/libcompose/utils"
|
||||
composeYaml "github.com/docker/libcompose/yaml"
|
||||
"gopkg.in/yaml.v2"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -229,19 +230,11 @@ func readEnvFile(resourceLookup ResourceLookup, inFile string, serviceData RawSe
|
||||
|
||||
serviceData["environment"] = vars
|
||||
|
||||
delete(serviceData, "env_file")
|
||||
|
||||
return serviceData, nil
|
||||
}
|
||||
|
||||
func mergeConfig(baseService, serviceData RawService) RawService {
|
||||
for k, v := range serviceData {
|
||||
// Image and build are mutually exclusive in merge
|
||||
if k == "image" {
|
||||
delete(baseService, "build")
|
||||
} else if k == "build" {
|
||||
delete(baseService, "image")
|
||||
}
|
||||
existing, ok := baseService[k]
|
||||
if ok {
|
||||
baseService[k] = merge(existing, v)
|
||||
|
||||
+22
-3
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/libcompose/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// MergeServicesV1 merges a v1 compose file into an existing set of service configs
|
||||
@@ -29,7 +29,7 @@ func MergeServicesV1(existingServices *ServiceConfigs, environmentLookup Environ
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data = mergeConfig(rawExistingService, data)
|
||||
data = mergeConfigV1(rawExistingService, data)
|
||||
}
|
||||
|
||||
datas[name] = data
|
||||
@@ -148,7 +148,7 @@ func parseV1(resourceLookup ResourceLookup, environmentLookup EnvironmentLookup,
|
||||
}
|
||||
}
|
||||
|
||||
baseService = mergeConfig(baseService, serviceData)
|
||||
baseService = mergeConfigV1(baseService, serviceData)
|
||||
|
||||
logrus.Debugf("Merged result %#v", baseService)
|
||||
|
||||
@@ -177,3 +177,22 @@ func resolveContextV1(inFile string, serviceData RawService) RawService {
|
||||
|
||||
return serviceData
|
||||
}
|
||||
|
||||
func mergeConfigV1(baseService, serviceData RawService) RawService {
|
||||
for k, v := range serviceData {
|
||||
// Image and build are mutually exclusive in merge
|
||||
if k == "image" {
|
||||
delete(baseService, "build")
|
||||
} else if k == "build" {
|
||||
delete(baseService, "image")
|
||||
}
|
||||
existing, ok := baseService[k]
|
||||
if ok {
|
||||
baseService[k] = merge(existing, v)
|
||||
} else {
|
||||
baseService[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return baseService
|
||||
}
|
||||
+1
-1
@@ -5,8 +5,8 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/libcompose/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// MergeServicesV2 merges a v2 compose file into an existing set of service configs
|
||||
|
||||
Reference in new issue
Block a user