cli: Deploying a compose file must use TaskTemplate.Networks
This is the non-deprecated field, and the one that can be changed in a
service update.
Since old daemon versions don't allow migrating from one field to the
other, make this conditional on the API version.
@@ -9,6 +9,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/swarm"
+ "github.com/docker/docker/api/types/versions"
servicecli "github.com/docker/docker/cli/command/service"
composetypes "github.com/docker/docker/cli/compose/types"
"github.com/docker/docker/client"
@@ -20,11 +21,10 @@ import (
const defaultNetwork = "default"
// Services from compose-file types to engine API types
-// TODO: fix secrets API so that SecretAPIClient is not required here
func Services(
namespace Namespace,
config *composetypes.Config,
- client client.SecretAPIClient,
+ client client.CommonAPIClient,
) (map[string]swarm.ServiceSpec, error) {
result := make(map[string]swarm.ServiceSpec)
@@ -33,12 +33,11 @@ func Services(
networks := config.Networks
for _, service := range services {
-
secrets, err := convertServiceSecrets(client, namespace, service.Secrets, config.Secrets)
if err != nil {
return nil, errors.Wrapf(err, "service %s", service.Name)
}
- serviceSpec, err := convertService(namespace, service, networks, volumes, secrets)
+ serviceSpec, err := convertService(client.ClientVersion(), namespace, service, networks, volumes, secrets)
if err != nil {
return nil, errors.Wrapf(err, "service %s", service.Name)
}
@@ -49,6 +48,7 @@ func Services(
}
func convertService(
+ apiVersion string,
namespace Namespace,
service composetypes.ServiceConfig,
networkConfigs map[string]composetypes.NetworkConfig,
@@ -133,10 +133,21 @@ func convertService(
},
EndpointSpec: endpoint,
Mode: mode,
- Networks: networks,
UpdateConfig: convertUpdateConfig(service.Deploy.UpdateConfig),
}
+ // ServiceSpec.Networks is deprecated and should not have been used by
+ // this package. It is possible to update TaskTemplate.Networks, but it
+ // is not possible to update ServiceSpec.Networks. Unfortunately, we
+ // can't unconditionally start using TaskTemplate.Networks, because that
+ // will break with older daemons that don't support migrating from
+ // ServiceSpec.Networks to TaskTemplate.Networks. So which field to use
+ // is conditional on daemon version.
+ if versions.LessThan(apiVersion, "1.29") {
+ serviceSpec.Networks = networks
+ } else {
+ serviceSpec.TaskTemplate.Networks = networks
+ }
return serviceSpec, nil
}
