Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we marshall version too… #891

Merged
merged 1 commit into from Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions cli/command/stack/kubernetes/loader.go
Expand Up @@ -8,16 +8,30 @@ import (
)

type versionedConfig struct {
*composetypes.Config `yaml:",inline"`
Version string
composetypes.Config
version string
}

func (c versionedConfig) MarshalYAML() (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll be able to remove these MarshalYAML in the future by making Config.Services a type with a MarshalYAML.

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.
func LoadStack(name, version string, cfg composetypes.Config) (*apiv1beta1.Stack, error) {
cfg.Filename = ""
res, err := yaml.Marshal(versionedConfig{
Version: version,
Config: &cfg,
version: version,
Config: cfg,
})
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions cli/command/stack/kubernetes/loader_test.go
Expand Up @@ -37,6 +37,7 @@ services:
image: bar
foo:
image: foo
version: "3.1"
volumes: {}
`),
},
Expand Down
22 changes: 10 additions & 12 deletions cli/compose/types/types.go
Expand Up @@ -70,7 +70,7 @@ func (cd ConfigDetails) LookupEnv(key string) (string, bool) {

// Config is a full compose file configuration
type Config struct {
Filename string
Filename string `yaml:"-"`
Services []ServiceConfig
Networks map[string]NetworkConfig
Volumes map[string]VolumeConfig
Expand All @@ -80,24 +80,22 @@ type Config struct {

// MarshalYAML makes Config implement yaml.Marshaller
func (c *Config) MarshalYAML() (interface{}, error) {
m := map[string]interface{}{}
services := map[string]ServiceConfig{}
for _, service := range c.Services {
s := service
s.Name = ""
services[service.Name] = s
services[service.Name] = service
}
m["services"] = services
m["networks"] = c.Networks
m["volumes"] = c.Volumes
m["secrets"] = c.Secrets
m["configs"] = c.Configs
return m, nil
return map[string]interface{}{
"services": services,
"networks": c.Networks,
"volumes": c.Volumes,
"secrets": c.Secrets,
"configs": c.Configs,
}, nil
}

// ServiceConfig is the configuration of one service
type ServiceConfig struct {
Name string `yaml:",omitempty"`
Name string `yaml:"-"`

Build BuildConfig `yaml:",omitempty"`
CapAdd []string `mapstructure:"cap_add" yaml:"cap_add,omitempty"`
Expand Down