Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cli/command/service/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/versions"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"golang.org/x/net/context"
Expand Down Expand Up @@ -92,7 +93,7 @@ func runCreate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *service
service.TaskTemplate.ContainerSpec.Configs = configs
}

if err := resolveServiceImageDigest(dockerCli, &service); err != nil {
if err := resolveServiceImageDigestContentTrust(dockerCli, &service); err != nil {
return err
}

Expand All @@ -106,6 +107,11 @@ func runCreate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *service
createOpts.EncodedRegistryAuth = encodedAuth
}

// query registry if flag disabling it was not set
if !opts.noResolveImage && versions.GreaterThanOrEqualTo(apiClient.ClientVersion(), "1.30") {
createOpts.QueryRegistry = true
}

response, err := apiClient.ServiceCreate(ctx, service, createOpts)
if err != nil {
return err
Expand Down
6 changes: 5 additions & 1 deletion cli/command/service/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ type serviceOptions struct {
networks opts.ListOpts
endpoint endpointOptions

registryAuth bool
registryAuth bool
noResolveImage bool

logDriver logDriverOptions

Expand Down Expand Up @@ -797,6 +798,8 @@ func addServiceFlags(flags *pflag.FlagSet, opts *serviceOptions, defaultFlagValu
flags.StringVar(&opts.endpoint.mode, flagEndpointMode, defaultFlagValues.getString(flagEndpointMode), "Endpoint mode (vip or dnsrr)")

flags.BoolVar(&opts.registryAuth, flagRegistryAuth, false, "Send registry authentication details to swarm agents")
flags.BoolVar(&opts.noResolveImage, flagNoResolveImage, false, "Do not query the registry to resolve image digest and supported platforms")
Copy link
Member

Choose a reason for hiding this comment

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

I this option is API version dependent, this needs an annotation;

flags.SetAnnotation(flagNoResolveImage, "version", []string{"1.30"})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thaJeztah done, this flag is indeed API version dependent.

Choose a reason for hiding this comment

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

Do we really want to hide this flag when talking to an older daemon? I'd think you would want to use the flag when the daemon is old, because the daemon wouldn't support the "distribution inspect" endpoint that gets used without this flag.

Copy link
Member

Choose a reason for hiding this comment

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

@aaronlehmann if the daemon ignores the option, do we want people to try and use it?

flags.SetAnnotation(flagNoResolveImage, "version", []string{"1.30"})

flags.StringVar(&opts.logDriver.name, flagLogDriver, "", "Logging driver for service")
flags.Var(&opts.logDriver.opts, flagLogOpt, "Logging driver options")
Expand Down Expand Up @@ -899,6 +902,7 @@ const (
flagUser = "user"
flagWorkdir = "workdir"
flagRegistryAuth = "with-registry-auth"
flagNoResolveImage = "no-resolve-image"
flagLogDriver = "log-driver"
flagLogOpt = "log-opt"
flagHealthCmd = "health-cmd"
Expand Down
6 changes: 3 additions & 3 deletions cli/command/service/trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"golang.org/x/net/context"
)

func resolveServiceImageDigest(dockerCli command.Cli, service *swarm.ServiceSpec) error {
func resolveServiceImageDigestContentTrust(dockerCli command.Cli, service *swarm.ServiceSpec) error {
if !command.IsTrusted() {
// Digests are resolved by the daemon when not using content
// trust.
// When not using content trust, digest resolution happens later when
// contacting the registry to retrieve image information.
return nil
}

Expand Down
5 changes: 4 additions & 1 deletion cli/command/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,12 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, options *serv
}

if flags.Changed("image") {
if err := resolveServiceImageDigest(dockerCli, spec); err != nil {
if err := resolveServiceImageDigestContentTrust(dockerCli, spec); err != nil {
return err
}
if !options.noResolveImage && versions.GreaterThanOrEqualTo(apiClient.ClientVersion(), "1.30") {
updateOpts.QueryRegistry = true
}
}

updatedSecrets, err := getUpdatedSecrets(apiClient, flags, spec.TaskTemplate.ContainerSpec.Secrets)
Expand Down