Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.2k
implement docker push -a/--all-tags#2220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,12 +9,15 @@ import ( | ||
| "github.com/docker/cli/cli/command" | ||
| "github.com/docker/cli/cli/streams" | ||
| "github.com/docker/distribution/reference" | ||
| "github.com/docker/docker/api/types" | ||
| "github.com/docker/docker/pkg/jsonmessage" | ||
| "github.com/docker/docker/registry" | ||
| "github.com/pkg/errors" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
| type pushOptions struct { | ||
| all bool | ||
| remote string | ||
| untrusted bool | ||
| quiet bool | ||
| @@ -35,6 +38,7 @@ func NewPushCommand(dockerCli command.Cli) *cobra.Command { | ||
| } | ||
| flags := cmd.Flags() | ||
| flags.BoolVarP(&opts.all, "all-tags", "a", false, "Push all tagged images in the repository") | ||
| flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output") | ||
| command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled()) | ||
| @@ -44,8 +48,16 @@ func NewPushCommand(dockerCli command.Cli) *cobra.Command { | ||
| // RunPush performs a push against the engine based on the specified options | ||
| func RunPush(dockerCli command.Cli, opts pushOptions) error { | ||
| ref, err := reference.ParseNormalizedNamed(opts.remote) | ||
| if err != nil { | ||
| switch { | ||
| case err != nil: | ||
| return err | ||
| case opts.all && !reference.IsNameOnly(ref): | ||
| return errors.New("tag can't be used with --all-tags/-a") | ||
| case !opts.all && reference.IsNameOnly(ref): | ||
| ref = reference.TagNameOnly(ref) | ||
| if tagged, ok := ref.(reference.Tagged); ok && !opts.quiet { | ||
| _, _ = fmt.Fprintf(dockerCli.Out(), "Using default tag: %s\n", tagged.Tag()) | ||
silvin-lubecki marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
| // Resolve the Repository name from fqn to RepositoryInfo | ||
| @@ -58,18 +70,28 @@ func RunPush(dockerCli command.Cli, opts pushOptions) error { | ||
| // Resolve the Auth config relevant for this server | ||
| authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index) | ||
| encodedAuth, err := command.EncodeAuthToBase64(authConfig) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "push") | ||
| if !opts.untrusted { | ||
| return TrustedPush(ctx, dockerCli, repoInfo, ref, authConfig, requestPrivilege) | ||
| options := types.ImagePushOptions{ | ||
| All: opts.all, | ||
| RegistryAuth: encodedAuth, | ||
| PrivilegeFunc: requestPrivilege, | ||
| } | ||
| responseBody, err := imagePushPrivileged(ctx, dockerCli, authConfig, ref, requestPrivilege) | ||
| responseBody, err := dockerCli.Client().ImagePush(ctx, reference.FamiliarString(ref), options) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer responseBody.Close() | ||
| if !opts.untrusted { | ||
| // TODO PushTrustedReference currently doesn't respect `--quiet` | ||
| return PushTrustedReference(dockerCli, repoInfo, ref, authConfig, responseBody) | ||
| } | ||
| if opts.quiet { | ||
| err = jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(ioutil.Discard), nil) | ||
| if err == nil { | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.