From c5f45ab85a2ea43887eba3c35bf09ae46d16814c Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Tue, 21 May 2024 15:21:45 -0600 Subject: [PATCH 1/9] updates for deploying remote bundle --- src/cmd/dev.go | 54 ++++++++++++++++++++++----------------- src/pkg/sources/remote.go | 15 +++++++++++ 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 3f266993..281d78d6 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -5,8 +5,7 @@ package cmd import ( - "os" - + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/uds-cli/src/config" "github.com/defenseunicorns/uds-cli/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/message" @@ -25,26 +24,26 @@ var devDeployCmd = &cobra.Command{ Args: cobra.MaximumNArgs(1), Short: lang.CmdDevDeployShort, Long: lang.CmdDevDeployLong, - PreRun: func(_ *cobra.Command, args []string) { - setBundleFile(args) - }, Run: func(_ *cobra.Command, args []string) { + config.Dev = true - // Create Bundle - srcDir, err := os.Getwd() - if err != nil { - message.Fatalf(err, "error reading the current working directory") - } + var src string if len(args) > 0 { - srcDir = args[0] + src = args[0] } + localBundle := helpers.IsDir(src) + if localBundle { - if len(srcDir) != 0 && srcDir[len(srcDir)-1] != '/' { - srcDir = srcDir + "/" - } + // Create Bundle + setBundleFile(args) + + if len(src) != 0 && src[len(src)-1] != '/' { + src = src + "/" + } - config.CommonOptions.Confirm = true - bundleCfg.CreateOpts.SourceDirectory = srcDir + config.CommonOptions.Confirm = true + bundleCfg.CreateOpts.SourceDirectory = src + } configureZarf() @@ -59,18 +58,23 @@ var devDeployCmd = &cobra.Command{ bndlClient := bundle.NewOrDie(&bundleCfg) defer bndlClient.ClearPaths() - // Check if local zarf packages need to be created - bndlClient.CreateZarfPkgs() - // Create dev bundle - config.Dev = true - if err := bndlClient.Create(); err != nil { - bndlClient.ClearPaths() - message.Fatalf(err, "Failed to create bundle: %s", err.Error()) + if localBundle { + // Check if local zarf packages need to be created + bndlClient.CreateZarfPkgs() + + if err := bndlClient.Create(); err != nil { + bndlClient.ClearPaths() + message.Fatalf(err, "Failed to create bundle: %s", err.Error()) + } } // Deploy dev bundle - bndlClient.SetDevSource(srcDir) + if localBundle { + bndlClient.SetDevSource(src) + } else { + bundleCfg.DeployOpts.Source = src + } deploy(bndlClient) }, } @@ -80,4 +84,6 @@ func init() { rootCmd.AddCommand(devCmd) devCmd.AddCommand(devDeployCmd) devDeployCmd.Flags().StringArrayVarP(&bundleCfg.DeployOpts.Packages, "packages", "p", []string{}, lang.CmdBundleDeployFlagPackages) + devDeployCmd.Flags().BoolVarP(&config.CommonOptions.Confirm, "confirm", "c", false, lang.CmdBundleDeployFlagConfirm) + } diff --git a/src/pkg/sources/remote.go b/src/pkg/sources/remote.go index 2b280c03..42450444 100644 --- a/src/pkg/sources/remote.go +++ b/src/pkg/sources/remote.go @@ -52,6 +52,11 @@ func (r *RemoteBundle) LoadPackage(dst *layout.PackagePaths, filter filters.Comp return zarfTypes.ZarfPackage{}, nil, err } + // if in dev mode and package is a zarf init config, return an empty package + if config.Dev && pkg.Kind == zarfTypes.ZarfInitConfig { + return zarfTypes.ZarfPackage{}, nil, nil + } + pkg.Components, err = filter.Apply(pkg) if err != nil { return pkg, nil, err @@ -85,6 +90,16 @@ func (r *RemoteBundle) LoadPackage(dst *layout.PackagePaths, filter filters.Comp } } addNamespaceOverrides(&pkg, r.nsOverrides) + + if config.Dev { + pkg.Metadata.YOLO = true + // strip out all images and repos + for idx := range pkg.Components { + pkg.Components[idx].Images = []string{} + pkg.Components[idx].Repos = []string{} + } + } + // ensure we're using the correct package name as specified by the bundle pkg.Metadata.Name = r.PkgName return pkg, nil, err From 67eddfac29a6b1ff6f7e018463aa61c9f611eec1 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Tue, 21 May 2024 16:44:01 -0600 Subject: [PATCH 2/9] update testing for remote dev deploy --- src/test/e2e/commands_test.go | 4 ++-- src/test/e2e/dev_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/test/e2e/commands_test.go b/src/test/e2e/commands_test.go index 891cf145..b840f9cf 100644 --- a/src/test/e2e/commands_test.go +++ b/src/test/e2e/commands_test.go @@ -112,8 +112,8 @@ func deploy(t *testing.T, tarballPath string) (stdout string, stderr string) { return stdout, stderr } -func devDeploy(t *testing.T, tarballPath string) (stdout string, stderr string) { - cmd := strings.Split(fmt.Sprintf("dev deploy %s", tarballPath), " ") +func devDeploy(t *testing.T, bundlePath string) (stdout string, stderr string) { + cmd := strings.Split(fmt.Sprintf("dev deploy %s --confirm", bundlePath), " ") stdout, stderr, err := e2e.UDS(cmd...) require.NoError(t, err) return stdout, stderr diff --git a/src/test/e2e/dev_test.go b/src/test/e2e/dev_test.go index c01fe8dd..58d6ffe5 100644 --- a/src/test/e2e/dev_test.go +++ b/src/test/e2e/dev_test.go @@ -49,4 +49,17 @@ func TestDevDeploy(t *testing.T) { remove(t, bundlePath) }) + + t.Run("Test dev deploy with remote bundle", func(t *testing.T) { + + bundle := "oci://ghcr.io/defenseunicorns/packages/uds-cli/test/publish/ghcr-test:0.0.1" + + devDeploy(t, bundle) + + deployments, _, _ := e2e.UDS(cmd...) + require.Contains(t, deployments, "podinfo") + require.Contains(t, deployments, "nginx") + + remove(t, bundle) + }) } From 6396eb272e7f64687d6ee422da80e6752c87db83 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Tue, 21 May 2024 16:49:46 -0600 Subject: [PATCH 3/9] add docs --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4165461f..1f3395da 100644 --- a/README.md +++ b/README.md @@ -278,18 +278,19 @@ UDS CLI includes a vendored version of Zarf inside of its binary. To use Zarf, s ## Dev Mode > [!NOTE] -> Dev mode is a BETA feature and currently only works with local bundles +> Dev mode is a BETA feature Dev mode facilitates faster dev cycles when developing and testing bundles ``` -uds dev deploy +uds dev deploy | ``` The `dev deploy` command performs the following operations -- Creates Zarf packages for all local packages in a bundle + +- (If local bundle) Creates Zarf packages for all local packages in a bundle - Creates the Zarf tarball in the same directory as the `zarf.yaml` - Will only create the Zarf tarball if one does not already exist - Ignores any `kind: ZarfInitConfig` packages in the bundle -- Creates a bundle from the newly created Zarf packages +- (If local bundle) Creates a bundle from the newly created Zarf packages - Deploys the bundle in [YOLO](https://docs.zarf.dev/faq/#what-is-yolo-mode-and-why-would-i-use-it) mode, eliminating the need to do a `zarf init` From efefcf4d20af19fc684a976630d6ac072aa99bc2 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Tue, 21 May 2024 20:13:47 -0600 Subject: [PATCH 4/9] clean up --- src/cmd/dev.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 281d78d6..7ae21def 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -27,16 +27,20 @@ var devDeployCmd = &cobra.Command{ Run: func(_ *cobra.Command, args []string) { config.Dev = true - var src string + // Get bundle source + src := "" if len(args) > 0 { src = args[0] } + + // Check if source is a local bundle localBundle := helpers.IsDir(src) - if localBundle { + if localBundle { // Create Bundle setBundleFile(args) + // Ensure source ends with a slash if len(src) != 0 && src[len(src)-1] != '/' { src = src + "/" } @@ -64,17 +68,18 @@ var devDeployCmd = &cobra.Command{ bndlClient.CreateZarfPkgs() if err := bndlClient.Create(); err != nil { - bndlClient.ClearPaths() message.Fatalf(err, "Failed to create bundle: %s", err.Error()) } } - // Deploy dev bundle + // Set dev source if localBundle { bndlClient.SetDevSource(src) } else { bundleCfg.DeployOpts.Source = src } + + // Deploy bundle deploy(bndlClient) }, } From a0092e1d43b643231fa05119e5264d0a0924f30e Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Wed, 22 May 2024 09:47:58 -0600 Subject: [PATCH 5/9] address pr comments --- README.md | 4 ++-- src/cmd/dev.go | 5 ----- src/pkg/bundle/dev.go | 5 ----- src/pkg/sources/common.go | 14 +++++++++++++- src/pkg/sources/remote.go | 7 +------ src/pkg/sources/tarball.go | 7 +------ 6 files changed, 17 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 1f3395da..85050f1b 100644 --- a/README.md +++ b/README.md @@ -288,9 +288,9 @@ uds dev deploy | The `dev deploy` command performs the following operations -- (If local bundle) Creates Zarf packages for all local packages in a bundle +- If local bundle: Creates Zarf packages for all local packages in a bundle - Creates the Zarf tarball in the same directory as the `zarf.yaml` - Will only create the Zarf tarball if one does not already exist - Ignores any `kind: ZarfInitConfig` packages in the bundle -- (If local bundle) Creates a bundle from the newly created Zarf packages + - Creates a bundle from the newly created Zarf packages - Deploys the bundle in [YOLO](https://docs.zarf.dev/faq/#what-is-yolo-mode-and-why-would-i-use-it) mode, eliminating the need to do a `zarf init` diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 7ae21def..2b001411 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -40,11 +40,6 @@ var devDeployCmd = &cobra.Command{ // Create Bundle setBundleFile(args) - // Ensure source ends with a slash - if len(src) != 0 && src[len(src)-1] != '/' { - src = src + "/" - } - config.CommonOptions.Confirm = true bundleCfg.CreateOpts.SourceDirectory = src } diff --git a/src/pkg/bundle/dev.go b/src/pkg/bundle/dev.go index c36aa4dd..099001c6 100644 --- a/src/pkg/bundle/dev.go +++ b/src/pkg/bundle/dev.go @@ -60,11 +60,6 @@ func (b *Bundle) CreateZarfPkgs() { // SetDevSource sets the source for the bundle when in dev mode func (b *Bundle) SetDevSource(srcDir string) { - srcDir = filepath.Dir(srcDir) - // Add a trailing slash if it's missing - if len(srcDir) != 0 && srcDir[len(srcDir)-1] != '/' { - srcDir = srcDir + "/" - } filename := fmt.Sprintf("%s%s-%s-%s.tar.zst", config.BundlePrefix, b.bundle.Metadata.Name, b.bundle.Metadata.Architecture, b.bundle.Metadata.Version) b.cfg.DeployOpts.Source = filepath.Join(srcDir, filename) } diff --git a/src/pkg/sources/common.go b/src/pkg/sources/common.go index 21ee1e04..34f67b71 100644 --- a/src/pkg/sources/common.go +++ b/src/pkg/sources/common.go @@ -4,7 +4,9 @@ // Package sources contains Zarf packager sources package sources -import zarfTypes "github.com/defenseunicorns/zarf/src/types" +import ( + zarfTypes "github.com/defenseunicorns/zarf/src/types" +) // addNamespaceOverrides checks if pkg components have charts with namespace overrides and adds them func addNamespaceOverrides(pkg *zarfTypes.ZarfPackage, nsOverrides NamespaceOverrideMap) { @@ -21,3 +23,13 @@ func addNamespaceOverrides(pkg *zarfTypes.ZarfPackage, nsOverrides NamespaceOver } } } + +// YOLOPackage sets the YOLO flag on a package and strips out all images and repos +func YOLOPackage(pkg *zarfTypes.ZarfPackage) { + pkg.Metadata.YOLO = true + // strip out all images and repos + for idx := range pkg.Components { + pkg.Components[idx].Images = []string{} + pkg.Components[idx].Repos = []string{} + } +} diff --git a/src/pkg/sources/remote.go b/src/pkg/sources/remote.go index 42450444..120c9f57 100644 --- a/src/pkg/sources/remote.go +++ b/src/pkg/sources/remote.go @@ -92,12 +92,7 @@ func (r *RemoteBundle) LoadPackage(dst *layout.PackagePaths, filter filters.Comp addNamespaceOverrides(&pkg, r.nsOverrides) if config.Dev { - pkg.Metadata.YOLO = true - // strip out all images and repos - for idx := range pkg.Components { - pkg.Components[idx].Images = []string{} - pkg.Components[idx].Repos = []string{} - } + YOLOPackage(&pkg) } // ensure we're using the correct package name as specified by the bundle diff --git a/src/pkg/sources/tarball.go b/src/pkg/sources/tarball.go index dcd22a5a..6079257f 100644 --- a/src/pkg/sources/tarball.go +++ b/src/pkg/sources/tarball.go @@ -96,12 +96,7 @@ func (t *TarballBundle) LoadPackage(dst *layout.PackagePaths, filter filters.Com addNamespaceOverrides(&pkg, t.nsOverrides) if config.Dev { - pkg.Metadata.YOLO = true - // strip out all images and repos - for idx := range pkg.Components { - pkg.Components[idx].Images = []string{} - pkg.Components[idx].Repos = []string{} - } + YOLOPackage(&pkg) } packageSpinner.Successf("Loaded bundled Zarf package: %s", t.PkgName) From 4f476c253bbb6445a9ac2d01598c269f5ddd64a5 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Fri, 24 May 2024 12:59:43 -0600 Subject: [PATCH 6/9] update yolo function name --- src/pkg/sources/common.go | 4 ++-- src/pkg/sources/remote.go | 2 +- src/pkg/sources/tarball.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pkg/sources/common.go b/src/pkg/sources/common.go index 34f67b71..7f47b252 100644 --- a/src/pkg/sources/common.go +++ b/src/pkg/sources/common.go @@ -24,8 +24,8 @@ func addNamespaceOverrides(pkg *zarfTypes.ZarfPackage, nsOverrides NamespaceOver } } -// YOLOPackage sets the YOLO flag on a package and strips out all images and repos -func YOLOPackage(pkg *zarfTypes.ZarfPackage) { +// setAsYOLO sets the YOLO flag on a package and strips out all images and repos +func setAsYOLO(pkg *zarfTypes.ZarfPackage) { pkg.Metadata.YOLO = true // strip out all images and repos for idx := range pkg.Components { diff --git a/src/pkg/sources/remote.go b/src/pkg/sources/remote.go index 120c9f57..6641a173 100644 --- a/src/pkg/sources/remote.go +++ b/src/pkg/sources/remote.go @@ -92,7 +92,7 @@ func (r *RemoteBundle) LoadPackage(dst *layout.PackagePaths, filter filters.Comp addNamespaceOverrides(&pkg, r.nsOverrides) if config.Dev { - YOLOPackage(&pkg) + setAsYOLO(&pkg) } // ensure we're using the correct package name as specified by the bundle diff --git a/src/pkg/sources/tarball.go b/src/pkg/sources/tarball.go index 6079257f..68d33b6f 100644 --- a/src/pkg/sources/tarball.go +++ b/src/pkg/sources/tarball.go @@ -96,7 +96,7 @@ func (t *TarballBundle) LoadPackage(dst *layout.PackagePaths, filter filters.Com addNamespaceOverrides(&pkg, t.nsOverrides) if config.Dev { - YOLOPackage(&pkg) + setAsYOLO(&pkg) } packageSpinner.Successf("Loaded bundled Zarf package: %s", t.PkgName) From f13f47379912dbc0f11805a1f14d4f39240300e4 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Fri, 24 May 2024 13:18:32 -0600 Subject: [PATCH 7/9] update function naming for clarity --- src/cmd/dev.go | 2 +- src/pkg/bundle/dev.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 2b001411..0c04c761 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -69,7 +69,7 @@ var devDeployCmd = &cobra.Command{ // Set dev source if localBundle { - bndlClient.SetDevSource(src) + bndlClient.SetDeploySource(src) } else { bundleCfg.DeployOpts.Source = src } diff --git a/src/pkg/bundle/dev.go b/src/pkg/bundle/dev.go index 099001c6..64d2d10f 100644 --- a/src/pkg/bundle/dev.go +++ b/src/pkg/bundle/dev.go @@ -58,8 +58,8 @@ func (b *Bundle) CreateZarfPkgs() { } } -// SetDevSource sets the source for the bundle when in dev mode -func (b *Bundle) SetDevSource(srcDir string) { +// SetDeploySource sets the source for the bundle when in dev mode +func (b *Bundle) SetDeploySource(srcDir string) { filename := fmt.Sprintf("%s%s-%s-%s.tar.zst", config.BundlePrefix, b.bundle.Metadata.Name, b.bundle.Metadata.Architecture, b.bundle.Metadata.Version) b.cfg.DeployOpts.Source = filepath.Join(srcDir, filename) } From 4f8b87e4750d730fa55e2bdcdc443a2de60a89a9 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Sun, 26 May 2024 12:22:39 -0600 Subject: [PATCH 8/9] add --set flag to dev deploy --- src/cmd/dev.go | 2 +- src/test/e2e/dev_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 0c04c761..5b7fc8e5 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -85,5 +85,5 @@ func init() { devCmd.AddCommand(devDeployCmd) devDeployCmd.Flags().StringArrayVarP(&bundleCfg.DeployOpts.Packages, "packages", "p", []string{}, lang.CmdBundleDeployFlagPackages) devDeployCmd.Flags().BoolVarP(&config.CommonOptions.Confirm, "confirm", "c", false, lang.CmdBundleDeployFlagConfirm) - + devDeployCmd.Flags().StringToStringVar(&bundleCfg.DeployOpts.SetVariables, "set", nil, lang.CmdBundleDeployFlagSet) } diff --git a/src/test/e2e/dev_test.go b/src/test/e2e/dev_test.go index 58d6ffe5..8c954744 100644 --- a/src/test/e2e/dev_test.go +++ b/src/test/e2e/dev_test.go @@ -62,4 +62,12 @@ func TestDevDeploy(t *testing.T) { remove(t, bundle) }) + + t.Run("Test dev deploy with --set flag", func(t *testing.T) { + bundleDir := "src/test/bundles/02-variables" + bundleTarballPath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-variables-%s-0.0.1.tar.zst", e2e.Arch)) + _, stderr := runCmd(t, "dev deploy "+bundleTarballPath+" --set ANIMAL=Longhorns --set COUNTRY=Texas --confirm -l=debug") + require.Contains(t, stderr, "This fun-fact was imported: Longhorns are the national animal of Texas") + require.NotContains(t, stderr, "This fun-fact was imported: Unicorns are the national animal of Scotland") + }) } From 55012585cea9ff044235ce26c039dc0785602699 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Tue, 28 May 2024 10:12:49 -0600 Subject: [PATCH 9/9] fix --set test --- src/test/e2e/dev_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/e2e/dev_test.go b/src/test/e2e/dev_test.go index 8c954744..4ff3254a 100644 --- a/src/test/e2e/dev_test.go +++ b/src/test/e2e/dev_test.go @@ -66,8 +66,9 @@ func TestDevDeploy(t *testing.T) { t.Run("Test dev deploy with --set flag", func(t *testing.T) { bundleDir := "src/test/bundles/02-variables" bundleTarballPath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-variables-%s-0.0.1.tar.zst", e2e.Arch)) - _, stderr := runCmd(t, "dev deploy "+bundleTarballPath+" --set ANIMAL=Longhorns --set COUNTRY=Texas --confirm -l=debug") + _, stderr := runCmd(t, "dev deploy "+bundleDir+" --set ANIMAL=Longhorns --set COUNTRY=Texas --confirm -l=debug") require.Contains(t, stderr, "This fun-fact was imported: Longhorns are the national animal of Texas") require.NotContains(t, stderr, "This fun-fact was imported: Unicorns are the national animal of Scotland") + remove(t, bundleTarballPath) }) }