From 8a3e67755039ae452dcf65b28fdb719dae4e2854 Mon Sep 17 00:00:00 2001 From: razzle Date: Tue, 15 Aug 2023 17:51:41 -0500 Subject: [PATCH] Fix deploying packages w/ no component tarballs (#1973) ## Related Issue Fixes #1963 ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) --------- Signed-off-by: razzle Co-authored-by: Wayne Starr --- src/pkg/packager/common.go | 9 ++++----- src/test/e2e/50_oci_package_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 77073774be..0d93429bf0 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -339,11 +339,11 @@ func (p *Packager) loadZarfPkg() error { } // Get a list of paths for the components of the package - components, err := os.ReadDir(p.tmp.Components) - if err != nil { + componentTarballs, err := os.ReadDir(p.tmp.Components) + if err != nil && !utils.InvalidPath(p.tmp.Components) { return fmt.Errorf("unable to get a list of components... %w", err) } - for _, path := range components { + for _, path := range componentTarballs { // If the components are tarballs, extract them! componentPath := filepath.Join(p.tmp.Components, path.Name()) if !path.IsDir() && strings.HasSuffix(path.Name(), ".tar") { @@ -357,8 +357,7 @@ func (p *Packager) loadZarfPkg() error { } // If a SBOM tar file exist, temporarily place them in the deploy directory - _, tarErr := os.Stat(p.tmp.SbomTar) - if tarErr == nil { + if !utils.InvalidPath(p.tmp.SbomTar) { if err = archiver.Unarchive(p.tmp.SbomTar, p.tmp.Sboms); err != nil { return fmt.Errorf("unable to extract the sbom data from the component: %w", err) } diff --git a/src/test/e2e/50_oci_package_test.go b/src/test/e2e/50_oci_package_test.go index 0b8295e655..1d8bbd0cad 100644 --- a/src/test/e2e/50_oci_package_test.go +++ b/src/test/e2e/50_oci_package_test.go @@ -10,11 +10,13 @@ import ( "path/filepath" "strings" "testing" + "time" "github.com/defenseunicorns/zarf/src/pkg/oci" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "oras.land/oras-go/v2/registry" + "oras.land/oras-go/v2/registry/remote" ) type RegistryClientTestSuite struct { @@ -163,6 +165,20 @@ func (suite *RegistryClientTestSuite) Test_5_Copy() { dst.WithInsecureConnection(true) dst.WithContext(ctx) + reg, err := remote.NewRegistry(strings.Split(dstRef, "/")[0]) + suite.NoError(err) + reg.PlainHTTP = true + attempt := 0 + for attempt <= 5 { + err = reg.Ping(ctx) + if err == nil { + break + } + attempt++ + time.Sleep(2 * time.Second) + } + require.Less(t, attempt, 5, "failed to ping registry") + err = oci.CopyPackage(ctx, src, dst, nil, 5) suite.NoError(err)