mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Make docker stack deploy a little bit more indempotent
Sort some slice fields before sending them to the swarm api so that it won't trigger an update. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
e2de212339
commit
8b1c6bfe3d
1 changed files with 23 additions and 2 deletions
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Services from compose-file types to engine API types
|
// Services from compose-file types to engine API types
|
||||||
|
@ -110,9 +111,9 @@ func convertService(
|
||||||
Command: service.Entrypoint,
|
Command: service.Entrypoint,
|
||||||
Args: service.Command,
|
Args: service.Command,
|
||||||
Hostname: service.Hostname,
|
Hostname: service.Hostname,
|
||||||
Hosts: convertExtraHosts(service.ExtraHosts),
|
Hosts: sortStrings(convertExtraHosts(service.ExtraHosts)),
|
||||||
Healthcheck: healthcheck,
|
Healthcheck: healthcheck,
|
||||||
Env: convertEnvironment(service.Environment),
|
Env: sortStrings(convertEnvironment(service.Environment)),
|
||||||
Labels: AddStackLabel(namespace, service.Labels),
|
Labels: AddStackLabel(namespace, service.Labels),
|
||||||
Dir: service.WorkingDir,
|
Dir: service.WorkingDir,
|
||||||
User: service.User,
|
User: service.User,
|
||||||
|
@ -138,6 +139,17 @@ func convertService(
|
||||||
return serviceSpec, nil
|
return serviceSpec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sortStrings(strs []string) []string {
|
||||||
|
sort.Strings(strs)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
type byNetworkTarget []swarm.NetworkAttachmentConfig
|
||||||
|
|
||||||
|
func (a byNetworkTarget) Len() int { return len(a) }
|
||||||
|
func (a byNetworkTarget) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
func (a byNetworkTarget) Less(i, j int) bool { return a[i].Target < a[j].Target }
|
||||||
|
|
||||||
func convertServiceNetworks(
|
func convertServiceNetworks(
|
||||||
networks map[string]*composetypes.ServiceNetworkConfig,
|
networks map[string]*composetypes.ServiceNetworkConfig,
|
||||||
networkConfigs networkMap,
|
networkConfigs networkMap,
|
||||||
|
@ -173,6 +185,8 @@ func convertServiceNetworks(
|
||||||
Aliases: append(aliases, name),
|
Aliases: append(aliases, name),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(byNetworkTarget(nets))
|
||||||
return nets, nil
|
return nets, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,6 +361,12 @@ func convertResources(source composetypes.Resources) (*swarm.ResourceRequirement
|
||||||
return resources, nil
|
return resources, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type byPublishedPort []swarm.PortConfig
|
||||||
|
|
||||||
|
func (a byPublishedPort) Len() int { return len(a) }
|
||||||
|
func (a byPublishedPort) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
func (a byPublishedPort) Less(i, j int) bool { return a[i].PublishedPort < a[j].PublishedPort }
|
||||||
|
|
||||||
func convertEndpointSpec(source []string) (*swarm.EndpointSpec, error) {
|
func convertEndpointSpec(source []string) (*swarm.EndpointSpec, error) {
|
||||||
portConfigs := []swarm.PortConfig{}
|
portConfigs := []swarm.PortConfig{}
|
||||||
ports, portBindings, err := nat.ParsePortSpecs(source)
|
ports, portBindings, err := nat.ParsePortSpecs(source)
|
||||||
|
@ -362,6 +382,7 @@ func convertEndpointSpec(source []string) (*swarm.EndpointSpec, error) {
|
||||||
portConfigs = append(portConfigs, portConfig...)
|
portConfigs = append(portConfigs, portConfig...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(byPublishedPort(portConfigs))
|
||||||
return &swarm.EndpointSpec{Ports: portConfigs}, nil
|
return &swarm.EndpointSpec{Ports: portConfigs}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue