Skip to content

Commit

Permalink
podman load: support downloading files
Browse files Browse the repository at this point in the history
Support downloading files, for instance via
`podman load -i server.com/image.tar`.  The specified URL is downloaded
in the frontend and stored as a temp file that gets passed down to the
backend.

Also vendor in c/common@main to use the new `pkg/download`.

Fixes: containers#11970
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Nov 10, 2021
1 parent 5437568 commit 1ef66d6
Show file tree
Hide file tree
Showing 18 changed files with 276 additions and 78 deletions.
15 changes: 15 additions & 0 deletions cmd/podman/images/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/download"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/pkg/domain/entities"
Expand Down Expand Up @@ -69,6 +70,20 @@ func loadFlags(cmd *cobra.Command) {

func load(cmd *cobra.Command, args []string) error {
if len(loadOpts.Input) > 0 {
// Download the input file if needed.
if strings.HasPrefix(loadOpts.Input, "https://") || strings.HasPrefix(loadOpts.Input, "http://") {
tmpdir, err := util.DefaultContainerConfig().ImageCopyTmpDir()
if err != nil {
return err
}
tmpfile, err := download.FromURL(tmpdir, loadOpts.Input)
if err != nil {
return err
}
defer os.Remove(tmpfile)
loadOpts.Input = tmpfile
}

if _, err := os.Stat(loadOpts.Input); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions docs/source/markdown/podman-load.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Note: `:` is a restricted character and cannot be part of the file name.

#### **--input**, **-i**=*input*

Read from archive file, default is STDIN.
Load the specified input file instead of from stdin. The file can be on the local file system or on a server (e.g., https://server.com/archive.tar)

The remote client requires the use of this option.

Expand All @@ -49,7 +49,7 @@ $ podman load --quiet -i fedora.tar
```

```
$ podman load -q -i fedora.tar
$ podman load -q -i https://server.com/archive.tar
```

```
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/containernetworking/cni v1.0.1
github.com/containernetworking/plugins v1.0.1
github.com/containers/buildah v1.23.1
github.com/containers/common v0.46.1-0.20211109131927-c342e496bf76
github.com/containers/common v0.46.1-0.20211110143743-73e7b462c358
github.com/containers/conmon v2.0.20+incompatible
github.com/containers/image/v5 v5.16.1
github.com/containers/ocicrypt v1.1.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ github.com/containernetworking/plugins v1.0.1/go.mod h1:QHCfGpaTwYTbbH+nZXKVTxNB
github.com/containers/buildah v1.23.1 h1:Tpc9DsRuU+0Oofewpxb6OJVNQjCu7yloN/obUqzfDTY=
github.com/containers/buildah v1.23.1/go.mod h1:4WnrN0yrA7ab0ppgunixu2WM1rlD2rG8QLJAKbEkZlQ=
github.com/containers/common v0.44.2/go.mod h1:7sdP4vmI5Bm6FPFxb3lvAh1Iktb6tiO1MzjUzhxdoGo=
github.com/containers/common v0.46.1-0.20211109131927-c342e496bf76 h1:5aDACNS6Rz+6f6rpgbv5tVG/zv1rFoPX1CYAy4Vv6ZI=
github.com/containers/common v0.46.1-0.20211109131927-c342e496bf76/go.mod h1:bu8gizEkgAz6gXHvUw2cMtI5ErxB+fn/hv49RWk5N1A=
github.com/containers/common v0.46.1-0.20211110143743-73e7b462c358 h1:dK2AgGBdWspdQNw28Wc4peY25QeyYV4H9ViQaFaQ9XQ=
github.com/containers/common v0.46.1-0.20211110143743-73e7b462c358/go.mod h1:bu8gizEkgAz6gXHvUw2cMtI5ErxB+fn/hv49RWk5N1A=
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I=
github.com/containers/image/v5 v5.16.0/go.mod h1:XgTpfAPLRGOd1XYyCU5cISFr777bLmOerCSpt/v7+Q4=
Expand Down
20 changes: 20 additions & 0 deletions test/system/120-load.bats
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@ verify_iid_and_name() {
verify_iid_and_name $img_name
}

@test "podman load - from URL" {
get_iid_and_name
run_podman save $img_name -o $archive
run_podman rmi $iid

HOST_PORT=$(random_free_port)
SERVER=http://127.0.0.1:$HOST_PORT

# Bind-mount the archive to a container running httpd
run_podman run -d --name myweb -p "$HOST_PORT:80" \
-v $archive:/var/www/image.tar:Z \
-w /var/www \
$IMAGE /bin/busybox-extras httpd -f -p 80

run_podman load -i $SERVER/image.tar
verify_iid_and_name $img_name

run_podman rm -f -t0 myweb
}

@test "podman load - redirect corrupt payload" {
run_podman 125 load <<< "Danger, Will Robinson!! This is a corrupt tarball!"
is "$output" \
Expand Down
46 changes: 0 additions & 46 deletions vendor/github.com/containers/common/libimage/download.go

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/containers/common/libimage/runtime.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1ef66d6

Please sign in to comment.