Skip to content
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

fix: support dest path for import-http #466

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
rchincha marked this conversation as resolved.
Show resolved Hide resolved
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