Skip to content

Commit 94615bb

Browse files
committed
Reapply "cli/command/image: deprecate TagTrusted, move to cli/trust"
This reverts commit 4aecad4. Signed-off-by: Sebastiaan van Stijn <[email protected]> cli/trust: TagTrusted: lazily request APIClient to fix regression Commit e37d814 moved the image.TagTrusted function to the trust package, but changed the signature slightly to accept an API client, instead of requiring the command.Cli. However, this could result in situations where the Client obtained from the CLI was not correctly initialized, resulting in failures in our e2e test; === FAIL: e2e/global TestPromptExitCode/plugin_upgrade (9.14s) cli_test.go:203: assertion failed: Command: docker plugin push registry:5000/plugin-content-trust-upgrade:next ExitCode: 1 Error: exit status 1 Stdout: The push refers to repository [registry:5000/plugin-content-trust-upgrade] 24ec5b45d59b: Preparing 6a594992d358: Preparing 224414d1b129: Preparing 24ec5b45d59b: Preparing 6a594992d358: Preparing 224414d1b129: Preparing Stderr: error pushing plugin: failed to do request: Head "https://registry:5000/v2/plugin-content-trust-upgrade/blobs/sha256:6a594992d358facbbc4ab134bbbba77cb91e0adee6ff0d6103403ff94a9b796c": http: server gave HTTP response to HTTPS client Failures: ExitCode was 1 expected 0 Expected no error This patch changes the signature to accept an "APIClientProvider" so that the Client is obtained the moment when used. We should look what exactly causes this situation, and if we can make sure that requesting the `Client()` will always produce the client with the expected configuration. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 4aecad4 commit 94615bb

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

cli/command/container/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
242242
return err
243243
}
244244
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && trustedRef != nil {
245-
return image.TagTrusted(ctx, dockerCli, trustedRef, taggedRef)
245+
return tagTrusted(ctx, dockerCli, trustedRef, taggedRef)
246246
}
247247
return nil
248248
}

cli/command/container/trust.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package container
2+
3+
import (
4+
"context"
5+
6+
"github.com/distribution/reference"
7+
"github.com/docker/cli/cli/command"
8+
"github.com/docker/cli/cli/trust"
9+
)
10+
11+
func tagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canonical, ref reference.NamedTagged) error {
12+
return trust.TagTrusted(ctx, cli, cli.Err(), trustedRef, ref)
13+
}

cli/command/image/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
406406
// Since the build was successful, now we must tag any of the resolved
407407
// images from the above Dockerfile rewrite.
408408
for _, resolved := range resolvedTags {
409-
if err := TagTrusted(ctx, dockerCli, resolved.digestRef, resolved.tagRef); err != nil {
409+
if err := tagTrusted(ctx, dockerCli, resolved.digestRef, resolved.tagRef); err != nil {
410410
return err
411411
}
412412
}

cli/command/image/trust.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
104104
return err
105105
}
106106

107-
if err := TagTrusted(ctx, cli, trustedRef, tagged); err != nil {
107+
if err := tagTrusted(ctx, cli, trustedRef, tagged); err != nil {
108108
return err
109109
}
110110
}
@@ -225,15 +225,20 @@ func convertTarget(t client.Target) (target, error) {
225225
}, nil
226226
}
227227

228-
// TagTrusted tags a trusted ref
228+
// TagTrusted tags a trusted ref. It is a shallow wrapper around APIClient.ImageTag
229+
// that updates the given image references to their familiar format for tagging
230+
// and printing.
231+
//
232+
// Deprecated: use [trust.TagTrusted] instead. This function was only used internally, and will be removed in the next release.
229233
func TagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canonical, ref reference.NamedTagged) error {
230-
// Use familiar references when interacting with client and output
231-
familiarRef := reference.FamiliarString(ref)
232-
trustedFamiliarRef := reference.FamiliarString(trustedRef)
233-
234-
_, _ = fmt.Fprintf(cli.Err(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
234+
return tagTrusted(ctx, cli, trustedRef, ref)
235+
}
235236

236-
return cli.Client().ImageTag(ctx, trustedFamiliarRef, familiarRef)
237+
// tagTrusted tags a trusted ref. It is a shallow wrapper around APIClient.ImageTag
238+
// that updates the given image references to their familiar format for tagging
239+
// and printing.
240+
func tagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canonical, ref reference.NamedTagged) error {
241+
return trust.TagTrusted(ctx, cli, cli.Err(), trustedRef, ref)
237242
}
238243

239244
// AuthResolver returns an auth resolver function from a command.Cli

cli/trust/trust_tag.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package trust
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"io"
7+
8+
"github.com/distribution/reference"
9+
"github.com/docker/docker/client"
10+
)
11+
12+
type APIClientProvider interface {
13+
Client() client.APIClient
14+
}
15+
16+
// TagTrusted tags a trusted ref. It is a shallow wrapper around [client.Client.ImageTag]
17+
// that updates the given image references to their familiar format for tagging
18+
// and printing.
19+
func TagTrusted(ctx context.Context, cli APIClientProvider, out io.Writer, trustedRef reference.Canonical, ref reference.NamedTagged) error {
20+
// Use familiar references when interacting with client and output
21+
familiarRef := reference.FamiliarString(ref)
22+
trustedFamiliarRef := reference.FamiliarString(trustedRef)
23+
24+
_, _ = fmt.Fprintf(out, "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
25+
return cli.Client().ImageTag(ctx, trustedFamiliarRef, familiarRef)
26+
}

0 commit comments

Comments
 (0)