Skip to content

Commit

Permalink
image/load: Add --platform
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
  • Loading branch information
vvoland authored and thaJeztah committed Sep 24, 2024
1 parent d46cd25 commit dcb56bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
24 changes: 22 additions & 2 deletions cli/command/image/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package image

import (
"context"
"fmt"
"io"

"github.com/containerd/platforms"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
Expand All @@ -15,8 +18,9 @@ import (
)

type loadOptions struct {
input string
quiet bool
input string
quiet bool
platform string
}

// NewLoadCommand creates a new `docker load` command
Expand All @@ -40,6 +44,13 @@ func NewLoadCommand(dockerCli command.Cli) *cobra.Command {

flags.StringVarP(&opts.input, "input", "i", "", "Read from tar archive file, instead of STDIN")
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress the load output")
flags.StringVar(&opts.platform, "platform", "",
`Pick a single-platform to be loaded if the image is multi-platform.
Full multi-platform image will be load if not specified.
Format: os[/arch[/variant]]
Example: "linux/amd64"`)
flags.SetAnnotation("platform", "version", []string{"1.47"})

return cmd
}
Expand Down Expand Up @@ -68,6 +79,15 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error
loadOpts.Quiet = true
}

if opts.platform != "" {
p, err := platforms.Parse(opts.platform)
if err != nil {
_, _ = fmt.Fprintf(dockerCli.Err(), "Invalid platform %s", opts.platform)
return err
}
loadOpts.Platform = &p
}

response, err := dockerCli.Client().ImageLoad(ctx, input, loadOpts)
if err != nil {
return err
Expand Down
9 changes: 5 additions & 4 deletions docs/reference/commandline/image_load.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Load an image from a tar archive or STDIN

### Options

| Name | Type | Default | Description |
|:------------------------------------|:---------|:--------|:---------------------------------------------|
| [`-i`](#input), [`--input`](#input) | `string` | | Read from tar archive file, instead of STDIN |
| `-q`, `--quiet` | `bool` | | Suppress the load output |
| Name | Type | Default | Description |
|:------------------------------------|:---------|:--------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`-i`](#input), [`--input`](#input) | `string` | | Read from tar archive file, instead of STDIN |
| `--platform` | `string` | | Pick a single-platform to be loaded if the image is multi-platform.<br>Full multi-platform image will be load if not specified.<br><br>Format: os[/arch[/variant]]<br>Example: `linux/amd64` |
| `-q`, `--quiet` | `bool` | | Suppress the load output |


<!---MARKER_GEN_END-->
Expand Down
9 changes: 5 additions & 4 deletions docs/reference/commandline/load.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Load an image from a tar archive or STDIN

### Options

| Name | Type | Default | Description |
|:----------------|:---------|:--------|:---------------------------------------------|
| `-i`, `--input` | `string` | | Read from tar archive file, instead of STDIN |
| `-q`, `--quiet` | `bool` | | Suppress the load output |
| Name | Type | Default | Description |
|:----------------|:---------|:--------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `-i`, `--input` | `string` | | Read from tar archive file, instead of STDIN |
| `--platform` | `string` | | Pick a single-platform to be loaded if the image is multi-platform.<br>Full multi-platform image will be load if not specified.<br><br>Format: os[/arch[/variant]]<br>Example: `linux/amd64` |
| `-q`, `--quiet` | `bool` | | Suppress the load output |


<!---MARKER_GEN_END-->
Expand Down

0 comments on commit dcb56bd

Please sign in to comment.