Skip to content

Commit

Permalink
chore: removes bubbletea tui (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd committed May 21, 2024
1 parent 7f2af5b commit 216bf15
Show file tree
Hide file tree
Showing 25 changed files with 69 additions and 1,082 deletions.
28 changes: 28 additions & 0 deletions adr/0004-tui.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,31 @@ The UDS CLI team has decided to refactor the existing TUI implementation with [B

## Consequences
This refactor is large and will be implemented one `uds` operation at time, starting with operations most likely to be performed during and after bundle installation.

# Amendment 1

Date: 20 May 2024

## Status

Accepted

## Context

After experimenting with BubbleTea for a few months and creating a prototype for `uds deploy`, the team has decided to revert back to using the Zarf TUI. Our original assumption was that the simplified (and beautiful!) TUI would make our downstream users' lives easier, but this has been invalidated. Turns out, most if not all downstream users are using UDS CLI in a CI environment and/or inside a Maru task, which is incompatible with BubbleTea (noting that it may be possible to make BubbleTea look better in CI but the output just isn't helpful).

### Example
For historical context, here is a screenshot of the BubbleTea TUI:
![tui](../docs/.images/bubbletea-tui.png)


### Technical Problems
Although the basis for this amendment was user feedback, it's helpful to also note technical issues with BubbleTea that we encountered:
- If BubbleTea panics, this is a chance that the terminal will be left in a bad state. The team attempted to get around this issue by introducing a panic handler that called `reset` before exiting the program, but this solution felt hacky and was heavy-handed. Also, this is potentially disastrous if invoked in a regulated/classified environment where terminals aren't standard.
- Dev'ing was cumbersome because for any change to the TUI code (even things like color changes), the entire program had to be re-compiled, which is very slow.
- There isn't a great way to test the TUI. Although the Charm team has an experimental testing lib, it's not very mature and the team found it difficult to use. We did find ways to test the TUI but it didn't inspire as much confidence as we would have liked.

## Decision
- The UDS CLI team will revert back to using the Zarf TUI by removing the BubbleTea TUI code.
- We have decided to keep the `uds logs` feature for now because we believe it still provides value
- Potentially in the future, we will evaluate other scroll-based (non-interactive) TUI approaches
Binary file added docs/.images/bubbletea-tui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ go 1.21.10
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.10.0
github.com/defenseunicorns/maru-runner v0.1.1
github.com/defenseunicorns/pkg/helpers v1.1.2
github.com/defenseunicorns/pkg/oci v0.0.2
github.com/defenseunicorns/zarf v0.33.0
github.com/fatih/color v1.16.0
github.com/fsnotify/fsnotify v1.7.0
github.com/goccy/go-yaml v1.11.3
github.com/mholt/archiver/v3 v3.5.1
Expand All @@ -25,7 +21,6 @@ require (
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/mod v0.17.0
golang.org/x/sync v0.7.0
golang.org/x/term v0.20.0
helm.sh/helm/v3 v3.14.4
oras.land/oras-go/v2 v2.5.0
)
Expand Down Expand Up @@ -147,7 +142,10 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/charmbracelet/bubbles v0.16.1 // indirect
github.com/charmbracelet/bubbletea v0.25.0 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/charmbracelet/lipgloss v0.9.1 // indirect
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 // indirect
github.com/clbanning/mxj/v2 v2.7.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
Expand Down Expand Up @@ -198,6 +196,7 @@ require (
github.com/facebookincubator/nvdtools v0.1.5 // indirect
github.com/fairwindsops/pluto/v5 v5.18.4 // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fluxcd/helm-controller/api v0.37.4 // indirect
Expand Down Expand Up @@ -469,6 +468,7 @@ require (
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,14 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chai2010/gettext-go v1.0.2 h1:1Lwwip6Q2QGsAdl/ZKPCwTe9fe0CjlUbqj5bFNSjIRk=
github.com/chai2010/gettext-go v1.0.2/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHeQQ+5AjwawxA=
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY=
github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc=
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 h1:krfRl01rzPzxSxyLyrChD+U+MzsBXbm0OwYYB67uF+4=
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589/go.mod h1:OuDyvmLnMCwa2ep4Jkm6nyA0ocJuZlGyk2gGseVzERM=
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import (
"embed"

"github.com/defenseunicorns/uds-cli/src/cmd"
"github.com/defenseunicorns/uds-cli/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/packager/lint"
)

//go:embed zarf.schema.json
var zarfSchema embed.FS

func main() {
defer utils.GracefulPanic()
lint.ZarfSchema = zarfSchema
cmd.Execute()
}
30 changes: 13 additions & 17 deletions src/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,19 @@ import (
"path/filepath"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/defenseunicorns/pkg/helpers"
"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"
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) {
// deploy performs validation, confirmation and deployment of a bundle
func deploy(bndlClient *bundle.Bundle) {
_, _, _, err := bndlClient.PreDeployValidation()
if err != nil {
message.Fatalf(err, "Failed to validate bundle: %s", err.Error())
Expand All @@ -42,9 +30,6 @@ func deployWithoutTea(bndlClient *bundle.Bundle) {
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 {
Expand All @@ -53,6 +38,17 @@ func deployWithoutTea(bndlClient *bundle.Bundle) {
}
}

// 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 setBundleFile(args []string) {
pathToBundleFile := ""
if len(args) > 0 {
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ var devDeployCmd = &cobra.Command{

// Deploy dev bundle
bndlClient.SetDevSource(srcDir)

deployWithoutTea(bndlClient)
deploy(bndlClient)
},
}

Expand Down
2 changes: 0 additions & 2 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func init() {
v.SetDefault(V_INSECURE, false)
v.SetDefault(V_TMP_DIR, "")
v.SetDefault(V_BNDL_OCI_CONCURRENCY, 3)
v.SetDefault(V_NO_TEA, false) // by default use the BubbleTea TUI

homeDir, _ := os.UserHomeDir()
v.SetDefault(V_UDS_CACHE, filepath.Join(homeDir, config.UDSCache))
Expand All @@ -88,5 +87,4 @@ func init() {
rootCmd.PersistentFlags().StringVar(&config.CommonOptions.TempDirectory, "tmpdir", v.GetString(V_TMP_DIR), lang.RootCmdFlagTempDir)
rootCmd.PersistentFlags().BoolVar(&config.CommonOptions.Insecure, "insecure", v.GetBool(V_INSECURE), lang.RootCmdFlagInsecure)
rootCmd.PersistentFlags().IntVar(&config.CommonOptions.OCIConcurrency, "oci-concurrency", v.GetInt(V_BNDL_OCI_CONCURRENCY), lang.CmdBundleFlagConcurrency)
rootCmd.PersistentFlags().BoolVar(&config.CommonOptions.NoTea, "no-tea", v.GetBool(V_NO_TEA), lang.RootCmdNoTea)
}
27 changes: 3 additions & 24 deletions src/cmd/uds.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ import (
"strings"

"github.com/AlecAivazis/survey/v2"
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/zarf/src/pkg/message"
goyaml "github.com/goccy/go-yaml"
"github.com/spf13/cobra"
"golang.org/x/term"
)

var createCmd = &cobra.Command{
Expand Down Expand Up @@ -68,29 +65,11 @@ var deployCmd = &cobra.Command{
return
}
}
// create new bundle client

// create new bundle client and deploy
bndlClient := bundle.NewOrDie(&bundleCfg)
defer bndlClient.ClearPaths()

// don't use bubbletea if --no-tea flag is set
if config.CommonOptions.NoTea {
deployWithoutTea(bndlClient)
return
}

// start up bubbletea
m := deploy.InitModel(bndlClient)

// detect tty so CI/containers don't break
if term.IsTerminal(int(os.Stdout.Fd())) {
deploy.Program = tea.NewProgram(&m)
} else {
deploy.Program = tea.NewProgram(&m, tea.WithInput(nil))
}

if _, err := deploy.Program.Run(); err != nil {
message.Fatalf(err, "TUI program error: %s", err.Error())
}
deploy(bndlClient)
},
}

Expand Down
1 change: 0 additions & 1 deletion src/cmd/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const (
V_TMP_DIR = "options.tmp_dir"
V_INSECURE = "options.insecure"
V_BNDL_OCI_CONCURRENCY = "options.oci_concurrency"
V_NO_TEA = "options.no_tea"

// Bundle create config keys
V_BNDL_CREATE_OUTPUT = "create.output"
Expand Down
1 change: 0 additions & 1 deletion src/config/lang/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const (
RootCmdFlagLogLevel = "Log level when running UDS-CLI. Valid options are: warn, info, debug, trace"
RootCmdErrInvalidLogLevel = "Invalid log level. Valid options are: warn, info, debug, trace."
RootCmdFlagArch = "Architecture for UDS bundles and Zarf packages"
RootCmdNoTea = "Don't use the BubbleTea TUI"

// logs
CmdBundleLogsShort = "View most recent UDS CLI logs"
Expand Down
10 changes: 1 addition & 9 deletions src/pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/defenseunicorns/pkg/helpers"
"github.com/defenseunicorns/uds-cli/src/config"
"github.com/defenseunicorns/uds-cli/src/pkg/bundle/tui/deploy"
"github.com/defenseunicorns/uds-cli/src/pkg/sources"
"github.com/defenseunicorns/uds-cli/src/types"
zarfConfig "github.com/defenseunicorns/zarf/src/config"
Expand Down Expand Up @@ -77,11 +76,8 @@ func deployPackages(packages []types.Package, resume bool, b *Bundle) error {
packagesToDeploy = packages
}

// let TUI know how many packages are being deployed
deploy.Program.Send(fmt.Sprintf("totalPackages:%d", len(packagesToDeploy)))

// deploy each package
for i, pkg := range packagesToDeploy {
for _, pkg := range packagesToDeploy {
sha := strings.Split(pkg.Ref, "@sha256:")[1] // using appended SHA from create!
pkgTmp, err := utils.MakeTempDir(config.CommonOptions.TempDirectory)
if err != nil {
Expand Down Expand Up @@ -138,14 +134,10 @@ func deployPackages(packages []types.Package, resume bool, b *Bundle) error {
return err
}

deploy.Program.Send(fmt.Sprintf("newPackage:%s:%d", pkg.Name, i))

if err := pkgClient.Deploy(); err != nil {
return err
}

deploy.Program.Send(fmt.Sprintf("complete:%d", i))

// save exported vars
pkgExportedVars := make(map[string]string)
for _, exp := range pkg.Exports {
Expand Down
32 changes: 0 additions & 32 deletions src/pkg/bundle/tui/common.go

This file was deleted.

Loading

0 comments on commit 216bf15

Please sign in to comment.