Skip to content
Open
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
13 changes: 6 additions & 7 deletions cli/command/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,13 @@ func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
registryAuthFrom = string(swarm.RegistryAuthFromSpec)
}

response, err := apiClient.ServiceUpdate(ctx, res.Service.ID, client.ServiceUpdateOptions{
Version: res.Service.Version,
Spec: *spec,
updateOpts.Version = res.Service.Version
updateOpts.Spec = *spec
updateOpts.EncodedRegistryAuth = encodedAuth
updateOpts.RegistryAuthFrom = swarm.RegistryAuthSource(registryAuthFrom)
updateOpts.Rollback = rollbackAction

EncodedRegistryAuth: encodedAuth,
RegistryAuthFrom: swarm.RegistryAuthSource(registryAuthFrom),
Rollback: rollbackAction,
})
response, err := apiClient.ServiceUpdate(ctx, res.Service.ID, updateOpts)
if err != nil {
return err
}
Expand Down
55 changes: 55 additions & 0 deletions cli/command/service/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package service
import (
"context"
"fmt"
"io"
"net/netip"
"slices"
"strconv"
"testing"
"time"

clitest "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/builders"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/mount"
"github.com/moby/moby/api/types/network"
Expand Down Expand Up @@ -1768,3 +1771,55 @@ func TestUpdateHostsRemoveRepeatedHost(t *testing.T) {
// is listed multiple times in the same entry.
assert.Check(t, is.DeepEqual([]string{"127.0.0.1 host2", "127.0.0.2 host2"}, hosts))
}

func TestUpdatePassesQueryRegistry(t *testing.T) {
testCases := []struct {
name string
setFlags [][2]string
wantQuery bool
}{
{
name: "image-update-queries-registry",
setFlags: [][2]string{{"image", "nginx:latest"}},
wantQuery: true,
},
{
name: "no-resolve-image",
setFlags: [][2]string{{"image", "nginx:latest"}, {"no-resolve-image", "true"}},
wantQuery: false,
},
{
name: "no-image-change",
setFlags: nil,
wantQuery: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
var got client.ServiceUpdateOptions
cli := clitest.NewFakeCli(&fakeClient{
serviceInspectFunc: func(ctx context.Context, serviceID string, options client.ServiceInspectOptions) (client.ServiceInspectResult, error) {
return client.ServiceInspectResult{
Service: *builders.Service(builders.ServiceID(serviceID), builders.ServiceImage("nginx:old")),
}, nil
},
serviceUpdateFunc: func(ctx context.Context, serviceID string, options client.ServiceUpdateOptions) (client.ServiceUpdateResult, error) {
got = options
return client.ServiceUpdateResult{}, nil
},
})
cmd := newUpdateCommand(cli)
cmd.SetArgs([]string{"service-id"})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
assert.NilError(t, cmd.Flags().Set("detach", "true"))
assert.NilError(t, cmd.Flags().Set("quiet", "true"))
for _, f := range tc.setFlags {
assert.NilError(t, cmd.Flags().Set(f[0], f[1]))
}
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(got.QueryRegistry, tc.wantQuery))
})
}
}
Loading