diff --git a/biz/docker/service.go b/biz/docker/service.go index 308d230..52149a4 100644 --- a/biz/docker/service.go +++ b/biz/docker/service.go @@ -301,6 +301,9 @@ func ServiceUpdate(info *model.ServiceInfo) error { } } + // DNS + spec.TaskTemplate.ContainerSpec.DNSConfig = info.GetDNSConfig() + options := types.ServiceUpdateOptions{ RegistryAuthFrom: types.RegistryAuthFromSpec, QueryRegistry: false, @@ -504,6 +507,9 @@ func ServiceCreate(info *model.ServiceInfo) error { } } + // DNS + service.TaskTemplate.ContainerSpec.DNSConfig = info.GetDNSConfig() + opts := types.ServiceCreateOptions{EncodedRegistryAuth: info.RegistryAuth} var resp types.ServiceCreateResponse resp, err = cli.ServiceCreate(ctx, service, opts) diff --git a/misc/util.go b/misc/util.go index ef7bb87..06d28e4 100644 --- a/misc/util.go +++ b/misc/util.go @@ -15,6 +15,7 @@ var Funcs = map[string]interface{}{ //"time": func(t time.Time) string { // return t.Local().Format("2006-01-02 15:04:05") //}, + "join": strings.Join, "eq": func(v1, v2 interface{}) bool { return fmt.Sprint(v1) == fmt.Sprint(v2) }, diff --git a/model/docker.go b/model/docker.go index b20239d..dd2a859 100644 --- a/model/docker.go +++ b/model/docker.go @@ -213,6 +213,11 @@ type ServiceInfo struct { Limit ResourceInfo `json:"limit"` Reserve ResourceInfo `json:"reserve"` } `json:"resource"` + DNS struct { + Nameservers string `json:"nameservers,omitempty"` + Search string `json:"search,omitempty"` + Options string `json:"options,omitempty"` + } `json:"dns"` } func NewServiceInfo(service swarm.Service) *ServiceInfo { @@ -318,13 +323,37 @@ func NewServiceInfo(service swarm.Service) *ServiceInfo { config := NewConfigInfo(c) si.Configs = append(si.Configs, config) } + if dns := spec.TaskTemplate.ContainerSpec.DNSConfig; dns != nil { + si.DNS.Nameservers = strings.Join(dns.Nameservers, ",") + si.DNS.Search = strings.Join(dns.Search, ",") + si.DNS.Options = strings.Join(dns.Options, ",") + } return si } +// TODO: finish this method func (si *ServiceInfo) ToServiceSpec() swarm.ServiceSpec { return swarm.ServiceSpec{} } +func (si *ServiceInfo) GetDNSConfig() *swarm.DNSConfig { + if si.DNS.Nameservers == "" && si.DNS.Search == "" && si.DNS.Options == "" { + return nil + } + + c := &swarm.DNSConfig{} + if si.DNS.Nameservers != "" { + c.Nameservers = strings.Split(si.DNS.Nameservers, ",") + } + if si.DNS.Search != "" { + c.Search = strings.Split(si.DNS.Search, ",") + } + if si.DNS.Options != "" { + c.Options = strings.Split(si.DNS.Options, ",") + } + return c +} + type EndpointPort struct { Name string `json:"name"` Protocol swarm.PortConfigProtocol `json:"protocol"` diff --git a/views/_modules/service.jet b/views/_modules/service.jet index 5775eb3..f51ab0f 100644 --- a/views/_modules/service.jet +++ b/views/_modules/service.jet @@ -98,6 +98,11 @@ Log driver +