Skip to content

Commit

Permalink
fix: support dest path for import-http
Browse files Browse the repository at this point in the history
Fixes issue project-stacker#456

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
  • Loading branch information
rchincha committed May 1, 2023
1 parent b4f7294 commit 665ce09
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/stacker/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func acquireUrl(c types.StackerConfig, storage types.Storage, i string, cache st
return "", errors.Errorf("The requested hash of %s import is different than the actual hash: %s != %s",
i, expectedHash, remoteHash)
}
return Download(cache, i, progress, expectedHash, remoteHash, remoteSize, mode, uid, gid)
return Download(cache, i, progress, expectedHash, remoteHash, remoteSize, idest, mode, uid, gid)
} else if url.Scheme == "stacker" {
// we always Grab() things from stacker://, because we need to
// mount the container's rootfs to get them and don't
Expand Down
9 changes: 7 additions & 2 deletions pkg/stacker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ import (

// download with caching support in the specified cache dir.
func Download(cacheDir string, url string, progress bool, expectedHash, remoteHash, remoteSize string,
mode *fs.FileMode, uid, gid int,
idest string, mode *fs.FileMode, uid, gid int,
) (string, error) {
name := path.Join(cacheDir, path.Base(url))
var name string
if idest != "" && idest[len(idest)-1:] != "/" {
name = path.Join(cacheDir, path.Base(idest))
} else {
name = path.Join(cacheDir, path.Base(url))
}

if fi, err := os.Stat(name); err == nil {
// Couldn't get remoteHash then use cached copy of import
Expand Down
19 changes: 19 additions & 0 deletions test/import-http.bats
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,23 @@ function teardown() {
[ "$(sha reference/nm_orig)" == "$(sha dest/img/rootfs/root/nm)" ]
}

@test "importing to a dest" {
cat > img/stacker1.yaml <<EOF
centos_base:
from:
type: oci
url: $CENTOS_OCI
import:
- path: https://www.cisco.com/favicon.ico
dest: /dest/icon
run: |
[ -f /dest/icon ]
[ ! -f /dest/favicon.ico ]
[ ! -f /stacker/favicon.ico ]
EOF
# Build base image
stacker build -f img/stacker1.yaml
umoci ls --layout oci
}

# Ideally there would tests to hit/miss cache for servers which provide a hash

0 comments on commit 665ce09

Please sign in to comment.