Skip to content

Commit

Permalink
image/history: Add --platform flag
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Gronowski <[email protected]>
  • Loading branch information
vvoland committed Aug 8, 2024
1 parent 8167526 commit b3139f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cli/command/image/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package image

import (
"context"

"fmt"
"github.com/containerd/platforms"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
Expand All @@ -13,7 +14,8 @@ import (
)

type historyOptions struct {
image string
image string
platform string

human bool
quiet bool
Expand Down Expand Up @@ -45,12 +47,28 @@ func NewHistoryCommand(dockerCli command.Cli) *cobra.Command {
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only show image IDs")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output")
flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp)
flags.StringVar(&opts.platform, "platform", "",
`Specify a platform from a multi-platform image to show the history for.
If the platform is not specified, the host platform is preferred if it's available, otherwise any available platform is used.
Format: os[/arch[/variant]]
Example: "linux/amd64"`)

return cmd
}

func runHistory(ctx context.Context, dockerCli command.Cli, opts historyOptions) error {
history, err := dockerCli.Client().ImageHistory(ctx, opts.image, image.HistoryOptions{})
var options image.HistoryOptions
if opts.platform != "" {
p, err := platforms.Parse(opts.platform)
if err != nil {
_, _ = fmt.Fprintf(dockerCli.Err(), "Invalid platform %s", opts.platform)
return err
}
options.Platform = &p
}

history, err := dockerCli.Client().ImageHistory(ctx, opts.image, options)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions docs/reference/commandline/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Show the history of an image
| `--format` | `string` | | Format output using a custom template:<br>'table': Print output in table format with column headers (default)<br>'table TEMPLATE': Print output in table format using the given Go template<br>'json': Print in JSON format<br>'TEMPLATE': Print output using the given Go template.<br>Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
| `-H`, `--human` | `bool` | `true` | Print sizes and dates in human readable format |
| `--no-trunc` | `bool` | | Don't truncate output |
| `--platform` | `string` | | Specify a platform from a multi-platform image to show the history for.<br>If the platform is not specified, the host platform is preferred if it's available, otherwise any available platform is used.<br><br>Format: os[/arch[/variant]]<br>Example: `linux/amd64` |
| `-q`, `--quiet` | `bool` | | Only show image IDs |


Expand Down
1 change: 1 addition & 0 deletions docs/reference/commandline/image_history.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Show the history of an image
| [`--format`](#format) | `string` | | Format output using a custom template:<br>'table': Print output in table format with column headers (default)<br>'table TEMPLATE': Print output in table format using the given Go template<br>'json': Print in JSON format<br>'TEMPLATE': Print output using the given Go template.<br>Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
| `-H`, `--human` | `bool` | `true` | Print sizes and dates in human readable format |
| `--no-trunc` | `bool` | | Don't truncate output |
| `--platform` | `string` | | Specify a platform from a multi-platform image to show the history for.<br>If the platform is not specified, the host platform is preferred if it's available, otherwise any available platform is used.<br><br>Format: os[/arch[/variant]]<br>Example: `linux/amd64` |
| `-q`, `--quiet` | `bool` | | Only show image IDs |


Expand Down

0 comments on commit b3139f5

Please sign in to comment.