From 5e99a86b5a46bc08f58600fd0107ee7bc2079da7 Mon Sep 17 00:00:00 2001 From: razzle Date: Wed, 3 Jan 2024 14:30:10 -0500 Subject: [PATCH] fix: `lint-package-and-examples` target (#2208) ## Description - Fix make target `lint-packages-and-examples` - Remove `-skeleton` references - Some small variable renaming + spelling fixes ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [x] Other (security config, docs update, etc) ## Checklist before merging - [x] Test, docs, adr added or updated as needed - [x] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow) followed --------- Signed-off-by: razzle Co-authored-by: Wayne Starr --- Makefile | 2 +- examples/composable-packages/zarf.yaml | 2 +- src/pkg/packager/common.go | 6 +++--- src/pkg/packager/sources/split.go | 10 +++++----- src/pkg/packager/sources/tarball.go | 1 - src/pkg/packager/sources/utils.go | 4 ++++ src/test/e2e/12_lint_test.go | 2 +- src/test/packages/12-lint/linted-import/zarf.yaml | 2 +- src/test/packages/12-lint/zarf.yaml | 2 +- 9 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 5ab1738a69..6a6b216a01 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,7 @@ docs-and-schema: ## Generate the Zarf Documentation and Schema hack/gen-cli-docs.sh ZARF_CONFIG=hack/empty-config.toml hack/create-zarf-schema.sh -lint-packages-and-examples: build-cli-for-system ## Recursively lint all zarf.yaml files in the repo except for those dedicated to tests +lint-packages-and-examples: build ## Recursively lint all zarf.yaml files in the repo except for those dedicated to tests hack/lint_all_zarf_packages.sh $(ZARF_BIN) # INTERNAL: a shim used to build the agent image only if needed on Windows using the `test` command diff --git a/examples/composable-packages/zarf.yaml b/examples/composable-packages/zarf.yaml index 34f499d670..efd16ce6d9 100644 --- a/examples/composable-packages/zarf.yaml +++ b/examples/composable-packages/zarf.yaml @@ -31,7 +31,7 @@ components: # default: false # the initial value overrides the child component import: # The URL to the skeleton package containing this component's package definition - url: oci://🦄/dos-games:1.0.0-skeleton + url: oci://🦄/dos-games:1.0.0 # Example optional custom name to point to in the imported package (default is to use this component's name) name: baseline # Un'name'd Zarf primitives will be appended to the end of the primitive's list for that component. diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 3f127062ca..e1cbfb0a20 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -332,7 +332,7 @@ func (p *Packager) archivePackage(destinationTarball string) error { } spinner.Updatef("Wrote %s to %s", p.layout.Base, destinationTarball) - f, err := os.Stat(destinationTarball) + fi, err := os.Stat(destinationTarball) if err != nil { return fmt.Errorf("unable to read the package archive: %w", err) } @@ -341,7 +341,7 @@ func (p *Packager) archivePackage(destinationTarball string) error { chunkSize := p.cfg.CreateOpts.MaxPackageSizeMB * 1000 * 1000 // If a chunk size was specified and the package is larger than the chunk size, split it into chunks. - if p.cfg.CreateOpts.MaxPackageSizeMB > 0 && f.Size() > int64(chunkSize) { + if p.cfg.CreateOpts.MaxPackageSizeMB > 0 && fi.Size() > int64(chunkSize) { spinner.Updatef("Package is larger than %dMB, splitting into multiple files", p.cfg.CreateOpts.MaxPackageSizeMB) chunks, sha256sum, err := utils.SplitFile(destinationTarball, chunkSize) if err != nil { @@ -359,7 +359,7 @@ func (p *Packager) archivePackage(destinationTarball string) error { // Marshal the data into a json file. jsonData, err := json.Marshal(types.ZarfSplitPackageData{ Count: len(chunks), - Bytes: f.Size(), + Bytes: fi.Size(), Sha256Sum: sha256sum, }) if err != nil { diff --git a/src/pkg/packager/sources/split.go b/src/pkg/packager/sources/split.go index 296b26deb2..1aade2eee5 100644 --- a/src/pkg/packager/sources/split.go +++ b/src/pkg/packager/sources/split.go @@ -40,9 +40,9 @@ func (s *SplitTarballSource) Collect(dir string) (string, error) { // Ensure the files are in order so they are appended in the correct order sort.Strings(fileList) - reassmbled := filepath.Join(dir, filepath.Base(strings.Replace(s.PackageSource, ".part000", "", 1))) + reassembled := filepath.Join(dir, filepath.Base(strings.Replace(s.PackageSource, ".part000", "", 1))) // Create the new package - pkgFile, err := os.Create(reassmbled) + pkgFile, err := os.Create(reassembled) if err != nil { return "", fmt.Errorf("unable to create new package file: %s", err) } @@ -87,7 +87,7 @@ func (s *SplitTarballSource) Collect(dir string) (string, error) { } } - if err := utils.SHAsMatch(reassmbled, pkgData.Sha256Sum); err != nil { + if err := utils.SHAsMatch(reassembled, pkgData.Sha256Sum); err != nil { return "", fmt.Errorf("package integrity check failed: %w", err) } @@ -97,9 +97,9 @@ func (s *SplitTarballSource) Collect(dir string) (string, error) { } // communicate to the user that the package was reassembled - message.Infof("Reassembled package to: %q", reassmbled) + message.Infof("Reassembled package to: %q", reassembled) - return reassmbled, nil + return reassembled, nil } // LoadPackage loads a package from a split tarball. diff --git a/src/pkg/packager/sources/tarball.go b/src/pkg/packager/sources/tarball.go index e5b13a2749..e65d0b962a 100644 --- a/src/pkg/packager/sources/tarball.go +++ b/src/pkg/packager/sources/tarball.go @@ -45,7 +45,6 @@ func (s *TarballSource) LoadPackage(dst *layout.PackagePaths, unarchiveAll bool) pathsExtracted := []string{} - // Walk the package so that was can dynamically load a .tar or a .tar.zst without caring about filenames. err = archiver.Walk(s.PackageSource, func(f archiver.File) error { if f.IsDir() { return nil diff --git a/src/pkg/packager/sources/utils.go b/src/pkg/packager/sources/utils.go index 97337f4944..383cc262cd 100644 --- a/src/pkg/packager/sources/utils.go +++ b/src/pkg/packager/sources/utils.go @@ -92,6 +92,10 @@ func RenameFromMetadata(path string) (string, error) { return "", err } + if pkg.Metadata.Name == "" { + return "", fmt.Errorf("%q does not contain a zarf.yaml", path) + } + name := NameFromMetadata(&pkg, false) name = fmt.Sprintf("%s%s", name, ext) diff --git a/src/test/e2e/12_lint_test.go b/src/test/e2e/12_lint_test.go index a2d6443ed8..cf132c4068 100644 --- a/src/test/e2e/12_lint_test.go +++ b/src/test/e2e/12_lint_test.go @@ -52,7 +52,7 @@ func TestLint(t *testing.T) { require.Contains(t, strippedStderr, "image-in-good-flavor-component:unpinned") // Check reported filepaths - require.Contains(t, strippedStderr, "Linting package \"dos-games\" at oci://🦄/dos-games:1.0.0-skeleton") + require.Contains(t, strippedStderr, "Linting package \"dos-games\" at oci://🦄/dos-games:1.0.0") require.Contains(t, strippedStderr, fmt.Sprintf("Linting package \"lint\" at %s", testPackagePath)) }) diff --git a/src/test/packages/12-lint/linted-import/zarf.yaml b/src/test/packages/12-lint/linted-import/zarf.yaml index f5f21981f6..4a99f73e96 100644 --- a/src/test/packages/12-lint/linted-import/zarf.yaml +++ b/src/test/packages/12-lint/linted-import/zarf.yaml @@ -19,5 +19,5 @@ components: - name: oci-games-url import: - url: oci://🦄/dos-games:1.0.0-skeleton + url: oci://🦄/dos-games:1.0.0 name: baseline diff --git a/src/test/packages/12-lint/zarf.yaml b/src/test/packages/12-lint/zarf.yaml index efddf42eea..980fa78eeb 100644 --- a/src/test/packages/12-lint/zarf.yaml +++ b/src/test/packages/12-lint/zarf.yaml @@ -36,7 +36,7 @@ components: - name: oci-games-url import: - url: oci://🦄/dos-games:1.0.0-skeleton + url: oci://🦄/dos-games:1.0.0 name: baseline - name: oci-games-url