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

Adds http.disableUnpack flag to retain archive #104

Merged
merged 1 commit into from
Feb 15, 2022
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: 2 additions & 0 deletions examples/http/vendir.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ directories:
path: k8s-simple-app-plain
- http: {}
path: k8s-simple-app-digested
- http: {}
path: k8s-simple-app-archived
path: vendor
kind: LockConfig
5 changes: 5 additions & 0 deletions examples/http/vendir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ directories:
http:
url: https://dk-shared-assets.s3.amazonaws.com/k8s-simple-app-example-master.zip
sha256: "82685cca45be6b93deb929debe1513cc73110af2f1d4a00b9d0f18f20a104a98"

- path: k8s-simple-app-archived
http:
url: https://dk-shared-assets.s3.amazonaws.com/k8s-simple-app-example-master.zip
disableUnpack: true
Binary file not shown.
2 changes: 2 additions & 0 deletions pkg/vendir/config/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ type DirectoryContentsHTTP struct {
// Secret may include one or more keys: username, password
// +optional
SecretRef *DirectoryContentsLocalRef `json:"secretRef,omitempty"`
// +optional
DisableUnpack bool `json:"disableUnpack,omitempty"`
}

type DirectoryContentsImage struct {
Expand Down
21 changes: 16 additions & 5 deletions pkg/vendir/fetch/http/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"

ctlconf "github.com/vmware-tanzu/carvel-vendir/pkg/vendir/config"
ctlfetch "github.com/vmware-tanzu/carvel-vendir/pkg/vendir/fetch"
Expand Down Expand Up @@ -44,16 +46,25 @@ func (t *Sync) Sync(dstPath string, tempArea ctlfetch.TempArea) (ctlconf.LockDir
return lockConf, fmt.Errorf("Downloading URL: %s", err)
}

incomingTmpPath, err := tempArea.NewTempDir("http")
incomingTmpPath := filepath.Dir(tmpFile.Name())
archivePath := filepath.Join(incomingTmpPath, path.Base(t.opts.URL))
err = os.Rename(tmpFile.Name(), archivePath)
if err != nil {
return lockConf, err
}

defer os.RemoveAll(incomingTmpPath)
if !t.opts.DisableUnpack {
incomingTmpPath, err = tempArea.NewTempDir("http")
if err != nil {
return lockConf, err
}

_, err = ctlfetch.NewArchive(tmpFile.Name(), true, t.opts.URL).Unpack(incomingTmpPath)
if err != nil {
return lockConf, fmt.Errorf("Unpacking archive: %s", err)
defer os.RemoveAll(incomingTmpPath)

_, err = ctlfetch.NewArchive(archivePath, true, t.opts.URL).Unpack(incomingTmpPath)
if err != nil {
return lockConf, fmt.Errorf("Unpacking archive: %s", err)
}
}

err = ctlfetch.MoveDir(incomingTmpPath, dstPath)
Expand Down