Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit fb72517

Browse files
committed
Switch back to go-yaml
Signed-off-by: Josh Curl <[email protected]>
1 parent f349867 commit fb72517

21 files changed

+222
-147
lines changed

config/interpolation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"os"
66
"testing"
77

8-
yaml "github.com/cloudfoundry-incubator/candiedyaml"
98
"github.com/stretchr/testify/assert"
9+
"gopkg.in/yaml.v2"
1010
)
1111

1212
func testInterpolatedLine(t *testing.T, expectedLine, interpolatedLine string, envVariables map[string]string) {

config/marshal_config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package config
33
import (
44
"testing"
55

6-
yaml "github.com/cloudfoundry-incubator/candiedyaml"
76
yamlTypes "github.com/docker/libcompose/yaml"
87
"github.com/stretchr/testify/assert"
8+
"gopkg.in/yaml.v2"
99
)
1010

1111
type TestConfig struct {

config/merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"fmt"
77
"strings"
88

9-
yaml "github.com/cloudfoundry-incubator/candiedyaml"
109
"github.com/docker/docker/pkg/urlutil"
1110
"github.com/docker/libcompose/utils"
1211
composeYaml "github.com/docker/libcompose/yaml"
12+
"gopkg.in/yaml.v2"
1313
)
1414

1515
var (

config/merge_v1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"path"
66

77
"github.com/Sirupsen/logrus"
8-
yaml "github.com/cloudfoundry-incubator/candiedyaml"
98
"github.com/docker/libcompose/utils"
9+
"gopkg.in/yaml.v2"
1010
)
1111

1212
// MergeServicesV1 merges a v1 compose file into an existing set of service configs

config/merge_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"path"
66

77
"github.com/Sirupsen/logrus"
8-
yaml "github.com/cloudfoundry-incubator/candiedyaml"
98
"github.com/docker/libcompose/utils"
9+
"gopkg.in/yaml.v2"
1010
)
1111

1212
// MergeServicesV2 merges a v2 compose file into an existing set of service configs

config/types.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ type ServiceConfigV1 struct {
2323
CapAdd []string `yaml:"cap_add,omitempty"`
2424
CapDrop []string `yaml:"cap_drop,omitempty"`
2525
CgroupParent string `yaml:"cgroup_parent,omitempty"`
26-
CPUQuota int64 `yaml:"cpu_quota,omitempty"`
26+
CPUQuota yaml.StringorInt `yaml:"cpu_quota,omitempty"`
2727
CPUSet string `yaml:"cpuset,omitempty"`
28-
CPUShares int64 `yaml:"cpu_shares,omitempty"`
28+
CPUShares yaml.StringorInt `yaml:"cpu_shares,omitempty"`
2929
Command yaml.Command `yaml:"command,flow,omitempty"`
3030
ContainerName string `yaml:"container_name,omitempty"`
3131
Devices []string `yaml:"devices,omitempty"`
@@ -42,8 +42,8 @@ type ServiceConfigV1 struct {
4242
Links yaml.MaporColonSlice `yaml:"links,omitempty"`
4343
LogDriver string `yaml:"log_driver,omitempty"`
4444
MacAddress string `yaml:"mac_address,omitempty"`
45-
MemLimit int64 `yaml:"mem_limit,omitempty"`
46-
MemSwapLimit int64 `yaml:"memswap_limit,omitempty"`
45+
MemLimit yaml.StringorInt `yaml:"mem_limit,omitempty"`
46+
MemSwapLimit yaml.StringorInt `yaml:"memswap_limit,omitempty"`
4747
Name string `yaml:"name,omitempty"`
4848
Net string `yaml:"net,omitempty"`
4949
Pid string `yaml:"pid,omitempty"`
@@ -53,7 +53,7 @@ type ServiceConfigV1 struct {
5353
Privileged bool `yaml:"privileged,omitempty"`
5454
Restart string `yaml:"restart,omitempty"`
5555
ReadOnly bool `yaml:"read_only,omitempty"`
56-
ShmSize int64 `yaml:"shm_size,omitempty"`
56+
ShmSize yaml.StringorInt `yaml:"shm_size,omitempty"`
5757
StdinOpen bool `yaml:"stdin_open,omitempty"`
5858
SecurityOpt []string `yaml:"security_opt,omitempty"`
5959
Tty bool `yaml:"tty,omitempty"`
@@ -81,8 +81,8 @@ type ServiceConfig struct {
8181
CapAdd []string `yaml:"cap_add,omitempty"`
8282
CapDrop []string `yaml:"cap_drop,omitempty"`
8383
CPUSet string `yaml:"cpuset,omitempty"`
84-
CPUShares int64 `yaml:"cpu_shares,omitempty"`
85-
CPUQuota int64 `yaml:"cpu_quota,omitempty"`
84+
CPUShares yaml.StringorInt `yaml:"cpu_shares,omitempty"`
85+
CPUQuota yaml.StringorInt `yaml:"cpu_quota,omitempty"`
8686
Command yaml.Command `yaml:"command,flow,omitempty"`
8787
CgroupParent string `yaml:"cgroup_parent,omitempty"`
8888
ContainerName string `yaml:"container_name,omitempty"`
@@ -105,15 +105,15 @@ type ServiceConfig struct {
105105
Links yaml.MaporColonSlice `yaml:"links,omitempty"`
106106
Logging Log `yaml:"logging,omitempty"`
107107
MacAddress string `yaml:"mac_address,omitempty"`
108-
MemLimit int64 `yaml:"mem_limit,omitempty"`
109-
MemSwapLimit int64 `yaml:"memswap_limit,omitempty"`
108+
MemLimit yaml.StringorInt `yaml:"mem_limit,omitempty"`
109+
MemSwapLimit yaml.StringorInt `yaml:"memswap_limit,omitempty"`
110110
NetworkMode string `yaml:"network_mode,omitempty"`
111111
Networks *yaml.Networks `yaml:"networks,omitempty"`
112112
Pid string `yaml:"pid,omitempty"`
113113
Ports []string `yaml:"ports,omitempty"`
114114
Privileged bool `yaml:"privileged,omitempty"`
115115
SecurityOpt []string `yaml:"security_opt,omitempty"`
116-
ShmSize int64 `yaml:"shm_size,omitempty"`
116+
ShmSize yaml.StringorInt `yaml:"shm_size,omitempty"`
117117
StopSignal string `yaml:"stop_signal,omitempty"`
118118
VolumeDriver string `yaml:"volume_driver,omitempty"`
119119
Volumes []string `yaml:"volumes,omitempty"`

docker/convert.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ func Convert(c *config.ServiceConfig, ctx project.Context, clientFactory compose
171171

172172
resources := container.Resources{
173173
CgroupParent: c.CgroupParent,
174-
Memory: c.MemLimit,
175-
MemorySwap: c.MemSwapLimit,
176-
CPUShares: c.CPUShares,
177-
CPUQuota: c.CPUQuota,
174+
Memory: int64(c.MemLimit),
175+
MemorySwap: int64(c.MemSwapLimit),
176+
CPUShares: int64(c.CPUShares),
177+
CPUQuota: int64(c.CPUQuota),
178178
CpusetCpus: c.CPUSet,
179179
Ulimits: ulimits,
180180
Devices: deviceMappings,
@@ -242,7 +242,7 @@ func Convert(c *config.ServiceConfig, ctx project.Context, clientFactory compose
242242
IpcMode: container.IpcMode(c.Ipc),
243243
PortBindings: portBindings,
244244
RestartPolicy: *restartPolicy,
245-
ShmSize: c.ShmSize,
245+
ShmSize: int64(c.ShmSize),
246246
SecurityOpt: utils.CopySlice(c.SecurityOpt),
247247
VolumeDriver: c.VolumeDriver,
248248
Resources: resources,

project/project_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestParseWithBadContent(t *testing.T) {
9292
t.Fatal("Should have failed parse")
9393
}
9494

95-
if !strings.HasPrefix(err.Error(), "Invalid timestamp: 'garbage'") {
95+
if !strings.Contains(err.Error(), "cannot unmarshal !!str `garbage` into config.Config") {
9696
t.Fatalf("Should have failed parse: %#v", err)
9797
}
9898
}
@@ -204,5 +204,5 @@ func TestParseWithMultipleComposeFiles(t *testing.T) {
204204
assert.Equal(t, "busybox", multipleConfig.Image)
205205
assert.Equal(t, "multi", multipleConfig.ContainerName)
206206
assert.Equal(t, []string{"8000", "9000", "10000"}, multipleConfig.Ports)
207-
assert.Equal(t, int64(40000000), multipleConfig.MemLimit)
207+
assert.Equal(t, yaml.StringorInt(40000000), multipleConfig.MemLimit)
208208
}

utils/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/Sirupsen/logrus"
88

9-
yaml "github.com/cloudfoundry-incubator/candiedyaml"
9+
"gopkg.in/yaml.v2"
1010
)
1111

1212
// InParallel holds a pool and a waitgroup to execute tasks in parallel and to be able

yaml/build.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package yaml
22

33
import (
4+
"errors"
45
"fmt"
56
"strconv"
67
"strings"
@@ -15,7 +16,7 @@ type Build struct {
1516
}
1617

1718
// MarshalYAML implements the Marshaller interface.
18-
func (b Build) MarshalYAML() (tag string, value interface{}, err error) {
19+
func (b Build) MarshalYAML() (interface{}, error) {
1920
m := map[string]interface{}{}
2021
if b.Context != "" {
2122
m["context"] = b.Context
@@ -26,16 +27,20 @@ func (b Build) MarshalYAML() (tag string, value interface{}, err error) {
2627
if len(b.Args) > 0 {
2728
m["args"] = b.Args
2829
}
29-
return "", m, nil
30+
return m, nil
3031
}
3132

3233
// UnmarshalYAML implements the Unmarshaller interface.
33-
func (b *Build) UnmarshalYAML(tag string, value interface{}) error {
34-
switch v := value.(type) {
35-
case string:
36-
b.Context = v
37-
case map[interface{}]interface{}:
38-
for mapKey, mapValue := range v {
34+
func (b *Build) UnmarshalYAML(unmarshal func(interface{}) error) error {
35+
var stringType string
36+
if err := unmarshal(&stringType); err == nil {
37+
b.Context = stringType
38+
return nil
39+
}
40+
41+
var mapType map[interface{}]interface{}
42+
if err := unmarshal(&mapType); err == nil {
43+
for mapKey, mapValue := range mapType {
3944
switch mapKey {
4045
case "context":
4146
b.Context = mapValue.(string)
@@ -52,10 +57,10 @@ func (b *Build) UnmarshalYAML(tag string, value interface{}) error {
5257
continue
5358
}
5459
}
55-
default:
56-
return fmt.Errorf("Failed to unmarshal Build: %#v", value)
60+
return nil
5761
}
58-
return nil
62+
63+
return errors.New("Failed to unmarshal Build")
5964
}
6065

6166
func handleBuildArgs(value interface{}) (map[string]string, error) {
@@ -98,6 +103,8 @@ func handleBuildArgMap(m map[interface{}]interface{}) (map[string]string, error)
98103
switch a := mapValue.(type) {
99104
case string:
100105
argValue = a
106+
case int:
107+
argValue = strconv.Itoa(a)
101108
case int64:
102109
argValue = strconv.Itoa(int(a))
103110
default:

0 commit comments

Comments
 (0)