-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: UncleGedd <42304551+UncleGedd@users.noreply.github.com>
- Loading branch information
Showing
15 changed files
with
373 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The UDS Authors | ||
|
||
// Package cmd contains the CLI commands for UDS. | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/defenseunicorns/uds-cli/src/config" | ||
"github.com/defenseunicorns/uds-cli/src/config/lang" | ||
"github.com/defenseunicorns/uds-cli/src/pkg/bundle" | ||
"github.com/defenseunicorns/uds-cli/src/pkg/bundle/tui/deploy" | ||
"github.com/defenseunicorns/uds-cli/src/pkg/utils" | ||
zarfConfig "github.com/defenseunicorns/zarf/src/config" | ||
"github.com/defenseunicorns/zarf/src/pkg/message" | ||
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers" | ||
zarfTypes "github.com/defenseunicorns/zarf/src/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// configureZarf copies configs from UDS-CLI to Zarf | ||
func configureZarf() { | ||
zarfConfig.CommonOptions = zarfTypes.ZarfCommonOptions{ | ||
Insecure: config.CommonOptions.Insecure, | ||
TempDirectory: config.CommonOptions.TempDirectory, | ||
OCIConcurrency: config.CommonOptions.OCIConcurrency, | ||
Confirm: config.CommonOptions.Confirm, | ||
CachePath: config.CommonOptions.CachePath, // use uds-cache instead of zarf-cache | ||
} | ||
} | ||
|
||
func deployWithoutTea(bndlClient *bundle.Bundle) { | ||
_, _, _, err := bndlClient.PreDeployValidation() | ||
if err != nil { | ||
message.Fatalf(err, "Failed to validate bundle: %s", err.Error()) | ||
} | ||
// confirm deployment | ||
if ok := bndlClient.ConfirmBundleDeploy(); !ok { | ||
message.Fatal(nil, "bundle deployment cancelled") | ||
} | ||
// create an empty program and kill it, this makes Program.Send a no-op | ||
deploy.Program = tea.NewProgram(nil) | ||
deploy.Program.Kill() | ||
|
||
// deploy the bundle | ||
if err := bndlClient.Deploy(); err != nil { | ||
bndlClient.ClearPaths() | ||
message.Fatalf(err, "Failed to deploy bundle: %s", err.Error()) | ||
} | ||
} | ||
|
||
func setBundleFile(args []string) { | ||
pathToBundleFile := "" | ||
if len(args) > 0 { | ||
if !helpers.IsDir(args[0]) { | ||
message.Fatalf(nil, "(%q) is not a valid path to a directory", args[0]) | ||
} | ||
pathToBundleFile = filepath.Join(args[0]) | ||
} | ||
// Handle .yaml or .yml | ||
bundleYml := strings.Replace(config.BundleYAML, ".yaml", ".yml", 1) | ||
if _, err := os.Stat(filepath.Join(pathToBundleFile, config.BundleYAML)); err == nil { | ||
bundleCfg.CreateOpts.BundleFile = config.BundleYAML | ||
} else if _, err = os.Stat(filepath.Join(pathToBundleFile, bundleYml)); err == nil { | ||
bundleCfg.CreateOpts.BundleFile = bundleYml | ||
} else { | ||
message.Fatalf(err, "Neither %s or %s found", config.BundleYAML, bundleYml) | ||
} | ||
} | ||
|
||
func cliSetup(cmd *cobra.Command) { | ||
match := map[string]message.LogLevel{ | ||
"warn": message.WarnLevel, | ||
"info": message.InfoLevel, | ||
"debug": message.DebugLevel, | ||
"trace": message.TraceLevel, | ||
} | ||
|
||
printViperConfigUsed() | ||
|
||
// No log level set, so use the default | ||
if logLevel != "" { | ||
if lvl, ok := match[logLevel]; ok { | ||
message.SetLogLevel(lvl) | ||
message.Debug("Log level set to " + logLevel) | ||
} else { | ||
message.Warn(lang.RootCmdErrInvalidLogLevel) | ||
} | ||
} | ||
|
||
if !config.SkipLogFile && !config.ListTasks { | ||
err := utils.ConfigureLogs(cmd) | ||
if err != nil { | ||
message.Fatalf(err, "Error configuring logs") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The UDS Authors | ||
|
||
// Package cmd contains the CLI commands for UDS. | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/defenseunicorns/uds-cli/src/config" | ||
"github.com/defenseunicorns/uds-cli/src/config/lang" | ||
"github.com/defenseunicorns/zarf/src/pkg/message" | ||
|
||
"github.com/defenseunicorns/uds-cli/src/pkg/bundle" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var devCmd = &cobra.Command{ | ||
Use: "dev", | ||
Short: lang.CmdDevShort, | ||
} | ||
|
||
var devDeployCmd = &cobra.Command{ | ||
Use: "deploy", | ||
Args: cobra.MaximumNArgs(1), | ||
Short: lang.CmdDevDeployShort, | ||
PreRun: func(_ *cobra.Command, args []string) { | ||
setBundleFile(args) | ||
}, | ||
Run: func(_ *cobra.Command, args []string) { | ||
|
||
// Create Bundle | ||
srcDir, err := os.Getwd() | ||
if err != nil { | ||
message.Fatalf(err, "error reading the current working directory") | ||
} | ||
if len(args) > 0 { | ||
srcDir = args[0] | ||
} | ||
|
||
if len(srcDir) != 0 && srcDir[len(srcDir)-1] != '/' { | ||
srcDir = srcDir + "/" | ||
} | ||
|
||
config.CommonOptions.Confirm = true | ||
bundleCfg.CreateOpts.SourceDirectory = srcDir | ||
configureZarf() | ||
|
||
// load uds-config if it exists | ||
if v.ConfigFileUsed() != "" { | ||
if err := loadViperConfig(); err != nil { | ||
message.Fatalf(err, "Failed to load uds-config: %s", err.Error()) | ||
return | ||
} | ||
} | ||
|
||
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()) | ||
} | ||
|
||
// Deploy dev bundle | ||
bndlClient.SetDevSource(srcDir) | ||
|
||
deployWithoutTea(bndlClient) | ||
}, | ||
} | ||
|
||
func init() { | ||
initViper() | ||
rootCmd.AddCommand(devCmd) | ||
devCmd.AddCommand(devDeployCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.