Skip to content

Commit

Permalink
Merge branch 'main' into 2044-publish-ux-improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Racer159 authored Oct 3, 2023
2 parents 70a915d + 41a1464 commit 56404f2
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/pkg/layout/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (c *Components) Unarchive(component types.ZarfComponent) (err error) {
return nil
}

message.Debugf("Unarchiving %q", tb)
message.Debugf("Unarchiving %q", filepath.Base(tb))
if err := archiver.Unarchive(tb, c.Base); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (p *Packager) Deploy() (err error) {
message.Debug(err)
}

if err = p.source.LoadPackage(p.layout); err != nil {
if err = p.source.LoadPackage(p.layout, true); err != nil {
return fmt.Errorf("unable to load the package: %w", err)
}
if err = p.readZarfYAML(p.layout.ZarfYAML); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (p *Packager) Mirror() (err error) {
spinner := message.NewProgressSpinner("Mirroring Zarf package %s", p.cfg.PkgOpts.PackageSource)
defer spinner.Stop()

if err = p.source.LoadPackage(p.layout); err != nil {
if err = p.source.LoadPackage(p.layout, true); err != nil {
return fmt.Errorf("unable to load the package: %w", err)
}
if err = p.readZarfYAML(p.layout.ZarfYAML); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (p *Packager) Publish() (err error) {
return err
}
} else {
if err = p.source.LoadPackage(p.layout); err != nil {
if err = p.source.LoadPackage(p.layout, false); err != nil {
return fmt.Errorf("unable to load the package: %w", err)
}
if err = p.readZarfYAML(p.layout.ZarfYAML); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/sources/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ClusterSource struct {
// LoadPackage loads a package from a cluster.
//
// This is not implemented.
func (s *ClusterSource) LoadPackage(_ *layout.PackagePaths) error {
func (s *ClusterSource) LoadPackage(_ *layout.PackagePaths, _ bool) error {
return fmt.Errorf("not implemented")
}

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/sources/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// `sources.ValidatePackageSignature` and `sources.ValidatePackageIntegrity` can be leveraged for this purpose.
type PackageSource interface {
// LoadPackage loads a package from a source.
LoadPackage(dst *layout.PackagePaths) error
LoadPackage(dst *layout.PackagePaths, unarchiveAll bool) error

// LoadPackageMetadata loads a package's metadata from a source.
LoadPackageMetadata(dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) error
Expand Down
30 changes: 18 additions & 12 deletions src/pkg/packager/sources/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type OCISource struct {
}

// LoadPackage loads a package from an OCI registry.
func (s *OCISource) LoadPackage(dst *layout.PackagePaths) (err error) {
func (s *OCISource) LoadPackage(dst *layout.PackagePaths, unarchiveAll bool) (err error) {
var pkg types.ZarfPackage
layersToPull := []ocispec.Descriptor{}

Expand Down Expand Up @@ -83,22 +83,24 @@ func (s *OCISource) LoadPackage(dst *layout.PackagePaths) (err error) {
}
}

for _, component := range pkg.Components {
if err := dst.Components.Unarchive(component); err != nil {
if layout.IsNotLoaded(err) {
_, err := dst.Components.Create(component)
if err != nil {
if unarchiveAll {
for _, component := range pkg.Components {
if err := dst.Components.Unarchive(component); err != nil {
if layout.IsNotLoaded(err) {
_, err := dst.Components.Create(component)
if err != nil {
return err
}
} else {
return err
}
} else {
return err
}
}
}

if dst.SBOMs.Path != "" {
if err := dst.SBOMs.Unarchive(); err != nil {
return err
if dst.SBOMs.Path != "" {
if err := dst.SBOMs.Unarchive(); err != nil {
return err
}
}
}

Expand Down Expand Up @@ -174,6 +176,10 @@ func (s *OCISource) Collect(dir string) (string, error) {
return "", err
}

if err := ValidatePackageIntegrity(loaded, pkg.Metadata.AggregateChecksum, false); err != nil {
return "", err
}

isSkeleton := strings.HasSuffix(s.Repo().Reference.Reference, oci.SkeletonSuffix)
name := NameFromMetadata(&pkg, isSkeleton)

Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/sources/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *SplitTarballSource) Collect(dir string) (string, error) {
}

// LoadPackage loads a package from a split tarball.
func (s *SplitTarballSource) LoadPackage(dst *layout.PackagePaths) (err error) {
func (s *SplitTarballSource) LoadPackage(dst *layout.PackagePaths, unarchiveAll bool) (err error) {
tb, err := s.Collect(filepath.Dir(s.PackageSource))
if err != nil {
return err
Expand All @@ -117,7 +117,7 @@ func (s *SplitTarballSource) LoadPackage(dst *layout.PackagePaths) (err error) {
ts := &TarballSource{
s.ZarfPackageOptions,
}
return ts.LoadPackage(dst)
return ts.LoadPackage(dst, unarchiveAll)
}

// LoadPackageMetadata loads a package's metadata from a split tarball.
Expand Down
27 changes: 14 additions & 13 deletions src/pkg/packager/sources/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type TarballSource struct {
}

// LoadPackage loads a package from a tarball.
func (s *TarballSource) LoadPackage(dst *layout.PackagePaths) (err error) {
func (s *TarballSource) LoadPackage(dst *layout.PackagePaths, unarchiveAll bool) (err error) {
var pkg types.ZarfPackage

message.Debugf("Loading package from %q", s.PackageSource)
Expand Down Expand Up @@ -75,7 +75,6 @@ func (s *TarballSource) LoadPackage(dst *layout.PackagePaths) (err error) {
return err
}

message.Debugf("Loaded %q --> %q", path, dstPath)
return nil
})
if err != nil {
Expand All @@ -102,22 +101,24 @@ func (s *TarballSource) LoadPackage(dst *layout.PackagePaths) (err error) {
}
}

for _, component := range pkg.Components {
if err := dst.Components.Unarchive(component); err != nil {
if layout.IsNotLoaded(err) {
_, err := dst.Components.Create(component)
if err != nil {
if unarchiveAll {
for _, component := range pkg.Components {
if err := dst.Components.Unarchive(component); err != nil {
if layout.IsNotLoaded(err) {
_, err := dst.Components.Create(component)
if err != nil {
return err
}
} else {
return err
}
} else {
return err
}
}
}

if dst.SBOMs.Path != "" {
if err := dst.SBOMs.Unarchive(); err != nil {
return err
if dst.SBOMs.Path != "" {
if err := dst.SBOMs.Unarchive(); err != nil {
return err
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/sources/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *URLSource) Collect(dir string) (string, error) {
}

// LoadPackage loads a package from an http, https or sget URL.
func (s *URLSource) LoadPackage(dst *layout.PackagePaths) (err error) {
func (s *URLSource) LoadPackage(dst *layout.PackagePaths, unarchiveAll bool) (err error) {
tmp, err := utils.MakeTempDir(config.CommonOptions.TempDirectory)
if err != nil {
return err
Expand All @@ -69,7 +69,7 @@ func (s *URLSource) LoadPackage(dst *layout.PackagePaths) (err error) {
s.ZarfPackageOptions,
}

return ts.LoadPackage(dst)
return ts.LoadPackage(dst, unarchiveAll)
}

// LoadPackageMetadata loads a package's metadata from an http, https or sget URL.
Expand Down
4 changes: 4 additions & 0 deletions src/test/e2e/50_oci_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (suite *RegistryClientTestSuite) Test_0_Publish() {
suite.NoError(err, stdOut, stdErr)
suite.Contains(stdErr, "Published "+ref)

// Pull the package via OCI.
stdOut, stdErr, err = e2e.Zarf("package", "pull", "oci://"+ref+"/helm-charts:0.0.1-"+e2e.Arch, "--insecure")
suite.NoError(err, stdOut, stdErr)

// Publish w/ package missing `metadata.version` field.
example = filepath.Join(suite.PackagesDir, fmt.Sprintf("zarf-package-component-actions-%s.tar.zst", e2e.Arch))
_, stdErr, err = e2e.Zarf("package", "publish", example, "oci://"+ref, "--insecure")
Expand Down

0 comments on commit 56404f2

Please sign in to comment.