Skip to content

Commit

Permalink
Fix deploying packages w/ no component tarballs (#1973)
Browse files Browse the repository at this point in the history
## Related Issue

Fixes #1963 

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

---------

Signed-off-by: razzle <harry@razzle.cloud>
Co-authored-by: Wayne Starr <Racer159@users.noreply.github.com>
  • Loading branch information
Noxsios and Racer159 committed Aug 15, 2023
1 parent b73f581 commit 8a3e677
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/e2e/50_oci_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8a3e677

Please sign in to comment.