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
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package lookup
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/runconfig/opts"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/libcompose/config"
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// relativePath returns the proper relative path for the given file path. If
|
||||
|
||||
+1
-1
@@ -9,9 +9,9 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/libcompose/config"
|
||||
"github.com/docker/libcompose/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var projectRegexp = regexp.MustCompile("[^a-zA-Z0-9_.-]")
|
||||
|
||||
+1
-1
@@ -3,8 +3,8 @@ package project
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/libcompose/project/events"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@ type Create struct {
|
||||
|
||||
// Run holds options of compose run.
|
||||
type Run struct {
|
||||
Detached bool
|
||||
Detached bool
|
||||
DisableTty bool
|
||||
}
|
||||
|
||||
// Up holds options of compose up.
|
||||
|
||||
+1
-1
@@ -10,13 +10,13 @@ import (
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/libcompose/config"
|
||||
"github.com/docker/libcompose/logger"
|
||||
"github.com/docker/libcompose/lookup"
|
||||
"github.com/docker/libcompose/project/events"
|
||||
"github.com/docker/libcompose/utils"
|
||||
"github.com/docker/libcompose/yaml"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// ComposeVersion is name of docker-compose.yml file syntax supported version
|
||||
|
||||
+5
@@ -2,6 +2,7 @@ package project
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
@@ -12,6 +13,8 @@ import (
|
||||
// the Filter struct.
|
||||
func (p *Project) Containers(ctx context.Context, filter Filter, services ...string) ([]string, error) {
|
||||
containers := []string{}
|
||||
var lock sync.Mutex
|
||||
|
||||
err := p.forEach(services, wrapperAction(func(wrapper *serviceWrapper, wrappers map[string]*serviceWrapper) {
|
||||
wrapper.Do(nil, events.NoEvent, events.NoEvent, func(service Service) error {
|
||||
serviceContainers, innerErr := service.Containers(ctx)
|
||||
@@ -37,7 +40,9 @@ func (p *Project) Containers(ctx context.Context, filter Filter, services ...str
|
||||
return fmt.Errorf("Invalid container filter: %s", filter.State)
|
||||
}
|
||||
containerID := container.ID()
|
||||
lock.Lock()
|
||||
containers = append(containers, containerID)
|
||||
lock.Unlock()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Scale scales the specified services.
|
||||
|
||||
+1
-1
@@ -3,8 +3,8 @@ package project
|
||||
import (
|
||||
"sync"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/libcompose/project/events"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type serviceWrapper struct {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
+31
@@ -3,6 +3,8 @@ package yaml
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Networks represents a list of service networks in compose file.
|
||||
@@ -20,6 +22,35 @@ type Network struct {
|
||||
IPv6Address string `yaml:"ipv6_address,omitempty"`
|
||||
}
|
||||
|
||||
// Generate a hash string to detect service network config changes
|
||||
func (n *Networks) HashString() string {
|
||||
if n == nil {
|
||||
return ""
|
||||
}
|
||||
result := []string{}
|
||||
for _, net := range n.Networks {
|
||||
result = append(result, net.HashString())
|
||||
}
|
||||
sort.Strings(result)
|
||||
return strings.Join(result, ",")
|
||||
}
|
||||
|
||||
// Generate a hash string to detect service network config changes
|
||||
func (n *Network) HashString() string {
|
||||
if n == nil {
|
||||
return ""
|
||||
}
|
||||
result := []string{}
|
||||
result = append(result, n.Name)
|
||||
result = append(result, n.RealName)
|
||||
sort.Strings(n.Aliases)
|
||||
result = append(result, strings.Join(n.Aliases, ","))
|
||||
result = append(result, n.IPv4Address)
|
||||
result = append(result, n.IPv6Address)
|
||||
sort.Strings(result)
|
||||
return strings.Join(result, ",")
|
||||
}
|
||||
|
||||
// MarshalYAML implements the Marshaller interface.
|
||||
func (n Networks) MarshalYAML() (interface{}, error) {
|
||||
m := map[string]*Network{}
|
||||
|
||||
+14
@@ -3,6 +3,7 @@ package yaml
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -19,6 +20,19 @@ type Volume struct {
|
||||
AccessMode string `yaml:"-"`
|
||||
}
|
||||
|
||||
// Generate a hash string to detect service volume config changes
|
||||
func (v *Volumes) HashString() string {
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
result := []string{}
|
||||
for _, vol := range v.Volumes {
|
||||
result = append(result, vol.String())
|
||||
}
|
||||
sort.Strings(result)
|
||||
return strings.Join(result, ",")
|
||||
}
|
||||
|
||||
// String implements the Stringer interface.
|
||||
func (v *Volume) String() string {
|
||||
var paths []string
|
||||
|
||||
Reference in new issue
Block a user