diff --git a/README.md b/README.md index 1b8721d3..d1356af2 100644 --- a/README.md +++ b/README.md @@ -109,11 +109,11 @@ Inspect the `uds-bundle.yaml` of a bundle 1. From your local filesystem: `uds inspect uds-bundle-.tar.zst` #### Viewing Images in a Bundle -It is possible derive images from a `uds-bundle.yaml`. This can be useful for situations where you need to know what images will be bundled before you actually create the bundle. This is accomplished with the `--list-images`. For example: +It is possible to derive images from a `uds-bundle.yaml`. This can be useful for situations where you need to know what images will be bundled before you actually create the bundle. This is accomplished with the `--list-images` flag. For example: `uds inspect ./uds-bundle.yaml --list-images` -This command will return a list of images derived from the bundle's packages and taking into account optional and required package components. +This command will return a list of images derived from the bundle's packages, taking into account optional and required package components. #### Viewing SBOMs There are 2 additional flags for the `uds inspect` command you can use to extract and view SBOMs: @@ -163,7 +163,7 @@ When deploying a local bundle, the bundle's architecture will be used for compar > [!NOTE] > It is possible to override the bundle architecture used at validation time by using the `--architecture` / `-a` flag. -If, for example, you have a multi-arch remote bundle that you want to deploy from an arm64 machine to an amd64 cluster, the validation with fail because the system arch does not match the cluster arch. However, you can pull the correct bundle version by specificying the arch with the command line architecture flag. +If, for example, you have a multi-arch remote bundle that you want to deploy from an arm64 machine to an amd64 cluster, the validation with fail because the system arch does not match the cluster arch. However, you can pull the correct bundle version by specifying the arch with the command line architecture flag. e.g. `uds deploy -a amd64 --confirm` diff --git a/src/pkg/bundle/inspect.go b/src/pkg/bundle/inspect.go index bae9035f..fd64f8b5 100644 --- a/src/pkg/bundle/inspect.go +++ b/src/pkg/bundle/inspect.go @@ -13,6 +13,7 @@ import ( "github.com/defenseunicorns/pkg/oci" "github.com/defenseunicorns/uds-cli/src/config" "github.com/defenseunicorns/uds-cli/src/pkg/utils" + "github.com/defenseunicorns/uds-cli/src/types" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/packager/filters" zarfSources "github.com/defenseunicorns/zarf/src/pkg/packager/sources" @@ -28,23 +29,10 @@ import ( func (b *Bundle) Inspect() error { // handle --list-images flag if b.cfg.InspectOpts.ListImages { - err := utils.CheckYAMLSourcePath(b.cfg.InspectOpts.Source) + err := b.listImages() if err != nil { return err } - - if err := utils.ReadYAMLStrict(b.cfg.InspectOpts.Source, &b.bundle); err != nil { - return err - } - - // find images in the packages taking into account optional components - imgs, err := b.getPackageImages() - if err != nil { - return err - } - - formattedImgs := pterm.Color(color.FgHiMagenta).Sprintf(strings.Join(imgs, "\n")) - pterm.Printfln("\n%s\n", formattedImgs) return nil } @@ -90,45 +78,35 @@ func (b *Bundle) Inspect() error { return nil } +func (b *Bundle) listImages() error { + if err := utils.CheckYAMLSourcePath(b.cfg.InspectOpts.Source); err != nil { + return err + } + + if err := utils.ReadYAMLStrict(b.cfg.InspectOpts.Source, &b.bundle); err != nil { + return err + } + + // find images in the packages taking into account optional components + imgs, err := b.getPackageImages() + if err != nil { + return err + } + + formattedImgs := pterm.Color(color.FgHiMagenta).Sprintf(strings.Join(imgs, "\n")) + pterm.Printfln("\n%s\n", formattedImgs) + return nil +} + func (b *Bundle) getPackageImages() ([]string, error) { // use a map to track the images for easy de-duping imgMap := make(map[string]string) for _, pkg := range b.bundle.Packages { // get package source - var source zarfSources.PackageSource - if pkg.Repository != "" { - // handle remote packages - url := fmt.Sprintf("oci://%s:%s", pkg.Repository, pkg.Ref) - platform := ocispec.Platform{ - Architecture: config.GetArch(), - OS: oci.MultiOS, - } - remote, err := zoci.NewRemote(url, platform) - if err != nil { - return nil, err - } - - source = &zarfSources.OCISource{ - ZarfPackageOptions: &zarfTypes.ZarfPackageOptions{}, - Remote: remote, - } - } else if pkg.Path != "" { - // handle local packages - err := os.Chdir(filepath.Dir(b.cfg.InspectOpts.Source)) // change to the bundle's directory - if err != nil { - return nil, err - } - - bundleArch := config.GetArch(b.bundle.Metadata.Architecture) - tarballName := fmt.Sprintf("zarf-package-%s-%s-%s.tar.zst", pkg.Name, bundleArch, pkg.Ref) - source = &zarfSources.TarballSource{ - ZarfPackageOptions: &zarfTypes.ZarfPackageOptions{ - PackageSource: filepath.Join(pkg.Path, tarballName), - }, - } - } else { - return nil, fmt.Errorf("package %s is missing a repository or path", pkg.Name) + source, err := b.getSource(pkg) + if err != nil { + return nil, err } tmpDir, err := zarfUtils.MakeTempDir(config.CommonOptions.TempDirectory) @@ -168,3 +146,41 @@ func (b *Bundle) getPackageImages() ([]string, error) { return images, nil } + +func (b *Bundle) getSource(pkg types.Package) (zarfSources.PackageSource, error) { + var source zarfSources.PackageSource + if pkg.Repository != "" { + // handle remote packages + url := fmt.Sprintf("oci://%s:%s", pkg.Repository, pkg.Ref) + platform := ocispec.Platform{ + Architecture: config.GetArch(), + OS: oci.MultiOS, + } + remote, err := zoci.NewRemote(url, platform) + if err != nil { + return nil, err + } + + source = &zarfSources.OCISource{ + ZarfPackageOptions: &zarfTypes.ZarfPackageOptions{}, + Remote: remote, + } + } else if pkg.Path != "" { + // handle local packages + err := os.Chdir(filepath.Dir(b.cfg.InspectOpts.Source)) // change to the bundle's directory + if err != nil { + return nil, err + } + + bundleArch := config.GetArch(b.bundle.Metadata.Architecture) + tarballName := fmt.Sprintf("zarf-package-%s-%s-%s.tar.zst", pkg.Name, bundleArch, pkg.Ref) + source = &zarfSources.TarballSource{ + ZarfPackageOptions: &zarfTypes.ZarfPackageOptions{ + PackageSource: filepath.Join(pkg.Path, tarballName), + }, + } + } else { + return nil, fmt.Errorf("package %s is missing a repository or path", pkg.Name) + } + return source, nil +} diff --git a/src/pkg/utils/utils.go b/src/pkg/utils/utils.go index 5cf17699..21793953 100644 --- a/src/pkg/utils/utils.go +++ b/src/pkg/utils/utils.go @@ -205,8 +205,8 @@ func CheckYAMLSourcePath(source string) error { return fmt.Errorf("source must have .yaml or yml file extension") } // Check if the file exists - if _, err := os.Stat(source); os.IsNotExist(err) { - return fmt.Errorf("file %s does not exist", source) + if isInvalid := helpers.InvalidPath(source); isInvalid { + return fmt.Errorf("file %s does not exist or has incorrect permissions", source) } return nil diff --git a/src/types/bundle.go b/src/types/bundle.go index 358ba78e..a64496b4 100644 --- a/src/types/bundle.go +++ b/src/types/bundle.go @@ -32,7 +32,6 @@ type UDSBundle struct { type Package struct { Name string `json:"name" jsonschema:"name=Name of the Zarf package"` Description string `json:"description,omitempty" jsonschema:"description=Description of the Zarf package"` - Images []string `json:"images,omitempty" jsonschema:"description=List of images included in the Zarf package"` Repository string `json:"repository,omitempty" jsonschema:"description=The repository to import the package from"` Path string `json:"path,omitempty" jsonschema:"description=The local path to import the package from"` Ref string `json:"ref" jsonschema:"description=Ref (tag) of the Zarf package"` diff --git a/uds.schema.json b/uds.schema.json index 8ca65ba7..96c03734 100644 --- a/uds.schema.json +++ b/uds.schema.json @@ -132,13 +132,6 @@ "type": "string", "description": "Description of the Zarf package" }, - "images": { - "items": { - "type": "string" - }, - "type": "array", - "description": "List of images included in the Zarf package" - }, "repository": { "type": "string", "description": "The repository to import the package from"