Skip to content

Commit

Permalink
zarf package structures now store components as compressed tarballs
Browse files Browse the repository at this point in the history
  • Loading branch information
YrrepNoj committed Feb 3, 2023
1 parent 1af056a commit baaf479
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ func (p *Packager) loadZarfPkg() error {
return fmt.Errorf("unable to read the zarf.yaml in %s: %w", p.tmp.Base, err)
}

// Get a list of paths for the components of the package
components, err := os.ReadDir(p.tmp.Components)
if err != nil {
return fmt.Errorf("unable to get a list of components... %w", err)
}
for _, component := range components {
// If the components are compressed tarballs, un-compress them
componentPath := filepath.Join(p.tmp.Components, component.Name())
if !component.IsDir() && strings.HasSuffix(component.Name(), ".tar.zst") {
if err := archiver.Unarchive(componentPath, p.tmp.Components); err != nil {
return fmt.Errorf("unable to extract the component: %w", err)
}

// After extracting the component, remove the compressed tarball to release disk space
_ = os.Remove(filepath.Join(p.tmp.Components, component.Name()))
}
}

// If SBOM files exist, temporarily place them in the deploy directory
if err := sbom.OutputSBOMFiles(p.tmp, config.ZarfSBOMDir, ""); err != nil {
// Don't stop the deployment, let the user decide if they want to continue the deployment
Expand Down
17 changes: 17 additions & 0 deletions src/pkg/packager/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ func (p *Packager) Create(baseDir string) error {
sbom.Catalog(componentSBOMs, pulledImages, p.tmp.Images, p.tmp.Sboms)
}

// Process the component directories into compressed tarballs
// NOTE: This is purposefully being done after the SBOM cataloging
for _, component := range p.cfg.Pkg.Components {
// Make the component a tar.zst archive
componentPaths, _ := p.createComponentPaths(component)
componentName := fmt.Sprintf("%s.%s", component.Name, "tar.zst")
componentTarPath := filepath.Join(p.tmp.Components, componentName)
if err := archiver.Archive([]string{componentPaths.Base}, componentTarPath); err != nil {
return fmt.Errorf("unable to create package: %w", err)
}

// Remove the deflated component directory
if err := os.RemoveAll(componentPaths.Base); err != nil {
message.Debugf("unable to remove the component directory (%s): %s", componentPaths.Base, err.Error())
}
}

// In case the directory was changed, reset to prevent breaking relative target paths
if originalDir != "" {
_ = os.Chdir(originalDir)
Expand Down

0 comments on commit baaf479

Please sign in to comment.