mirror of https://github.com/docker/cli.git
Make sure we marshall version too…
… otherwise the k8s controller might fail to parse the file as it will think it's version 1. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
bbe7f84540
commit
9f9f1c8515
|
@ -8,16 +8,30 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type versionedConfig struct {
|
type versionedConfig struct {
|
||||||
*composetypes.Config `yaml:",inline"`
|
composetypes.Config
|
||||||
Version string
|
version string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c versionedConfig) MarshalYAML() (interface{}, error) {
|
||||||
|
services := map[string]composetypes.ServiceConfig{}
|
||||||
|
for _, service := range c.Services {
|
||||||
|
services[service.Name] = service
|
||||||
|
}
|
||||||
|
return map[string]interface{}{
|
||||||
|
"services": services,
|
||||||
|
"networks": c.Networks,
|
||||||
|
"volumes": c.Volumes,
|
||||||
|
"secrets": c.Secrets,
|
||||||
|
"configs": c.Configs,
|
||||||
|
"version": c.version,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadStack loads a stack from a Compose config, with a given name.
|
// LoadStack loads a stack from a Compose config, with a given name.
|
||||||
func LoadStack(name, version string, cfg composetypes.Config) (*apiv1beta1.Stack, error) {
|
func LoadStack(name, version string, cfg composetypes.Config) (*apiv1beta1.Stack, error) {
|
||||||
cfg.Filename = ""
|
|
||||||
res, err := yaml.Marshal(versionedConfig{
|
res, err := yaml.Marshal(versionedConfig{
|
||||||
Version: version,
|
version: version,
|
||||||
Config: &cfg,
|
Config: cfg,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -37,6 +37,7 @@ services:
|
||||||
image: bar
|
image: bar
|
||||||
foo:
|
foo:
|
||||||
image: foo
|
image: foo
|
||||||
|
version: "3.1"
|
||||||
volumes: {}
|
volumes: {}
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (cd ConfigDetails) LookupEnv(key string) (string, bool) {
|
||||||
|
|
||||||
// Config is a full compose file configuration
|
// Config is a full compose file configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Filename string
|
Filename string `yaml:"-"`
|
||||||
Services []ServiceConfig
|
Services []ServiceConfig
|
||||||
Networks map[string]NetworkConfig
|
Networks map[string]NetworkConfig
|
||||||
Volumes map[string]VolumeConfig
|
Volumes map[string]VolumeConfig
|
||||||
|
@ -80,24 +80,22 @@ type Config struct {
|
||||||
|
|
||||||
// MarshalYAML makes Config implement yaml.Marshaller
|
// MarshalYAML makes Config implement yaml.Marshaller
|
||||||
func (c *Config) MarshalYAML() (interface{}, error) {
|
func (c *Config) MarshalYAML() (interface{}, error) {
|
||||||
m := map[string]interface{}{}
|
|
||||||
services := map[string]ServiceConfig{}
|
services := map[string]ServiceConfig{}
|
||||||
for _, service := range c.Services {
|
for _, service := range c.Services {
|
||||||
s := service
|
services[service.Name] = service
|
||||||
s.Name = ""
|
|
||||||
services[service.Name] = s
|
|
||||||
}
|
}
|
||||||
m["services"] = services
|
return map[string]interface{}{
|
||||||
m["networks"] = c.Networks
|
"services": services,
|
||||||
m["volumes"] = c.Volumes
|
"networks": c.Networks,
|
||||||
m["secrets"] = c.Secrets
|
"volumes": c.Volumes,
|
||||||
m["configs"] = c.Configs
|
"secrets": c.Secrets,
|
||||||
return m, nil
|
"configs": c.Configs,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceConfig is the configuration of one service
|
// ServiceConfig is the configuration of one service
|
||||||
type ServiceConfig struct {
|
type ServiceConfig struct {
|
||||||
Name string `yaml:",omitempty"`
|
Name string `yaml:"-"`
|
||||||
|
|
||||||
Build BuildConfig `yaml:",omitempty"`
|
Build BuildConfig `yaml:",omitempty"`
|
||||||
CapAdd []string `mapstructure:"cap_add" yaml:"cap_add,omitempty"`
|
CapAdd []string `mapstructure:"cap_add" yaml:"cap_add,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue