diff --git a/controller/template.go b/controller/template.go index fafdb2a..5b9ab25 100644 --- a/controller/template.go +++ b/controller/template.go @@ -87,6 +87,7 @@ func templateCreate(ctx web.Context) error { tpl = &model.Template{Name: info.Name} ) + info.Normalize() info.Name = "" content, err = json.Marshal(info) if err != nil { @@ -113,6 +114,7 @@ func templateEdit(ctx web.Context) error { if err != nil { return err } + service.Normalize() service.Name = tpl.Name if service.Registry != "" { @@ -162,6 +164,7 @@ func templateUpdate(ctx web.Context) error { } ) + info.Normalize() info.Name = "" content, err = json.Marshal(info) if err != nil { diff --git a/model/docker.go b/model/docker.go index dd2a859..5a86676 100644 --- a/model/docker.go +++ b/model/docker.go @@ -74,6 +74,19 @@ func (opts Options) ToMap() map[string]string { return m } +func (opts Options) Compress() Options { + if len(opts) > 0 { + var tmp Options + for _, opt := range opts { + if opt != nil { + tmp = append(tmp, opt) + } + } + return tmp + } + return opts +} + type StackListInfo struct { Name string Services []string @@ -336,6 +349,31 @@ func (si *ServiceInfo) ToServiceSpec() swarm.ServiceSpec { return swarm.ServiceSpec{} } +func (si *ServiceInfo) Normalize() { + si.Environments = si.Environments.Compress() + si.ServiceLabels = si.ServiceLabels.Compress() + si.ContainerLabels = si.ContainerLabels.Compress() + si.LogDriver.Options = si.LogDriver.Options.Compress() + if len(si.Configs) > 0 { + var tmp []ConfigInfo + for _, c := range si.Configs { + if c.ID != "" { + tmp = append(tmp, c) + } + } + si.Configs = tmp + } + if len(si.Secrets) > 0 { + var tmp []ConfigInfo + for _, c := range si.Secrets { + if c.ID != "" { + tmp = append(tmp, c) + } + } + si.Secrets = tmp + } +} + func (si *ServiceInfo) GetDNSConfig() *swarm.DNSConfig { if si.DNS.Nameservers == "" && si.DNS.Search == "" && si.DNS.Options == "" { return nil