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: pulling not respecting "uncompressed" setting in metadata #3472

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 src/internal/packager2/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func LoadPackage(ctx context.Context, opt LoadOptions) (*layout.PackageLayout, e
isPartial := false
switch srcType {
case "oci":
isPartial, err = pullOCI(ctx, opt.Source, tarPath, opt.Shasum, opt.Filter)
isPartial, tarPath, err = pullOCI(ctx, opt.Source, tmpDir, opt.Shasum, opt.Filter)
if err != nil {
return nil, err
}
Expand Down
33 changes: 20 additions & 13 deletions src/internal/packager2/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Pull(ctx context.Context, src, dir, shasum string, filter filters.Component
isPartial := false
switch u.Scheme {
case "oci":
isPartial, err = pullOCI(ctx, src, tmpPath, shasum, filter)
isPartial, tmpPath, err = pullOCI(ctx, src, tmpDir, shasum, filter)
if err != nil {
return err
}
Expand Down Expand Up @@ -101,10 +101,10 @@ func Pull(ctx context.Context, src, dir, shasum string, filter filters.Component
return nil
}

func pullOCI(ctx context.Context, src, tarPath, shasum string, filter filters.ComponentFilterStrategy) (bool, error) {
func pullOCI(ctx context.Context, src, tarDir, shasum string, filter filters.ComponentFilterStrategy) (bool, string, error) {
tmpDir, err := utils.MakeTempDir(config.CommonOptions.TempDirectory)
if err != nil {
return false, err
return false, "", err
}
defer os.Remove(tmpDir)
if shasum != "" {
Expand All @@ -113,48 +113,52 @@ func pullOCI(ctx context.Context, src, tarPath, shasum string, filter filters.Co
arch := config.GetArch()
remote, err := zoci.NewRemote(ctx, src, oci.PlatformForArch(arch))
if err != nil {
return false, err
return false, "", err
}
desc, err := remote.ResolveRoot(ctx)
if err != nil {
return false, fmt.Errorf("could not fetch images index: %w", err)
return false, "", fmt.Errorf("could not fetch images index: %w", err)
}
layersToPull := []ocispec.Descriptor{}
isPartial := false
tarPath := filepath.Join(tarDir, "data.tar")
if supportsFiltering(desc.Platform) {
root, err := remote.FetchRoot(ctx)
if err != nil {
return false, err
return false, "", err
}
if len(root.Layers) != len(layersToPull) {
isPartial = true
}
pkg, err := remote.FetchZarfYAML(ctx)
if err != nil {
return false, err
return false, "", err
}
pkg.Components, err = filter.Apply(pkg)
if err != nil {
return false, err
return false, "", err
}
layersToPull, err = remote.LayersFromRequestedComponents(ctx, pkg.Components)
if err != nil {
return false, err
return false, "", err
}
if !pkg.Metadata.Uncompressed {
tarPath = fmt.Sprintf("%s.zst", tarPath)
}
}
_, err = remote.PullPackage(ctx, tmpDir, config.CommonOptions.OCIConcurrency, layersToPull...)
if err != nil {
return false, err
return false, "", err
}
allTheLayers, err := filepath.Glob(filepath.Join(tmpDir, "*"))
if err != nil {
return false, err
return false, "", err
}
err = archiver.Archive(allTheLayers, tarPath)
if err != nil {
return false, err
return false, "", err
}
return isPartial, nil
return isPartial, tarPath, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AustinAbro321 does this look like a the direction that you wanted to go?

}

func pullHTTP(ctx context.Context, src, tarPath, shasum string) error {
Expand Down Expand Up @@ -236,6 +240,9 @@ func nameFromMetadata(path string) (string, error) {
} else if pkg.Metadata.Version != "" {
name = fmt.Sprintf("%s-%s", name, pkg.Metadata.Version)
}
if pkg.Metadata.Uncompressed {
return fmt.Sprintf("%s.tar", name), nil
}
return fmt.Sprintf("%s.tar.zst", name), nil
}

Expand Down