-
Notifications
You must be signed in to change notification settings - Fork 68
Cli deploy flags #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Cli deploy flags #32
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a274acf
Application settings as CLI deploy flags
kevinmcconnell dfffe84
Separate deploy & update
kevinmcconnell 2ff1559
Make `once list` output nicer
kevinmcconnell 9ce8abc
Show nicer progress when CLI deploying/updating
kevinmcconnell acb1844
Commands should specify app by host, not name
kevinmcconnell 9d180f2
Validate backup paths
kevinmcconnell e757325
Validate that auto backup has a backup path
kevinmcconnell 86825ba
Validate non-empty image ref
kevinmcconnell 80fe9e4
Set flags directly in update tests
kevinmcconnell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
| package command | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| tea "charm.land/bubbletea/v2" | ||
| "charm.land/lipgloss/v2" | ||
|
|
||
| "github.com/basecamp/once/internal/docker" | ||
| "github.com/basecamp/once/internal/ui" | ||
| ) | ||
|
|
||
| type cliProgress struct { | ||
| label string | ||
| stage string | ||
| progress ui.Progress | ||
| progressChan chan docker.DeployProgress | ||
| err error | ||
| width int | ||
|
|
||
| task func(docker.DeployProgressCallback) error | ||
| } | ||
|
|
||
| type cliProgressDoneMsg struct{ err error } | ||
| type cliProgressUpdateMsg struct{ p docker.DeployProgress } | ||
|
|
||
| func newCLIProgress(label string, task func(docker.DeployProgressCallback) error) *cliProgress { | ||
| return &cliProgress{ | ||
| label: label, | ||
| stage: "preparing", | ||
| progress: ui.NewProgress(0, lipgloss.BrightBlue), | ||
| progressChan: make(chan docker.DeployProgress, 16), | ||
| task: task, | ||
| } | ||
| } | ||
|
|
||
| func (m *cliProgress) Run() error { | ||
| _, err := tea.NewProgram(m).Run() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if m.err != nil { | ||
| fmt.Printf("%s: %s\n", m.label, lipgloss.NewStyle().Foreground(lipgloss.Red).Render("failed")) | ||
| } else { | ||
| fmt.Printf("%s: %s\n", m.label, lipgloss.NewStyle().Foreground(lipgloss.Green).Render("done")) | ||
| } | ||
|
|
||
| return m.err | ||
| } | ||
|
|
||
| func (m *cliProgress) Init() tea.Cmd { | ||
| return tea.Batch( | ||
| m.runTask(), | ||
| m.waitForProgress(), | ||
| m.progress.Init(), | ||
| ) | ||
| } | ||
|
|
||
| func (m *cliProgress) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
| switch msg := msg.(type) { | ||
| case tea.WindowSizeMsg: | ||
| m.width = msg.Width | ||
| m.progress = m.progress.SetWidth(m.barWidth()) | ||
| return m, nil | ||
|
|
||
| case cliProgressUpdateMsg: | ||
| switch msg.p.Stage { | ||
| case docker.DeployStageDownloading: | ||
| m.stage = "downloading" | ||
| m.progress = m.progress.SetPercent(msg.p.Percentage) | ||
| case docker.DeployStageStarting: | ||
| m.stage = "starting" | ||
| m.progress = m.progress.SetPercent(-1) | ||
| } | ||
| return m, m.waitForProgress() | ||
|
|
||
| case cliProgressDoneMsg: | ||
| m.err = msg.err | ||
| return m, tea.Quit | ||
|
|
||
| case ui.ProgressTickMsg: | ||
| var cmd tea.Cmd | ||
| m.progress, cmd = m.progress.Update(msg) | ||
| return m, cmd | ||
| } | ||
|
|
||
| return m, nil | ||
| } | ||
|
|
||
| func (m *cliProgress) View() tea.View { | ||
| prefix := m.label + " " + m.stage + ": " | ||
| return tea.NewView(prefix + m.progress.View()) | ||
| } | ||
|
|
||
| // Private | ||
|
|
||
| func (m *cliProgress) barWidth() int { | ||
| prefixWidth := len(m.label) + 1 + len(m.stage) + 2 // " " + stage + ": " | ||
| w := m.width - prefixWidth | ||
| if w < 10 { | ||
| w = 10 | ||
| } | ||
| return w | ||
| } | ||
|
|
||
| func (m *cliProgress) runTask() tea.Cmd { | ||
| return func() tea.Msg { | ||
| callback := func(p docker.DeployProgress) { | ||
| m.progressChan <- p | ||
| } | ||
| err := m.task(callback) | ||
| return cliProgressDoneMsg{err: err} | ||
| } | ||
| } | ||
|
|
||
| func (m *cliProgress) waitForProgress() tea.Cmd { | ||
| return func() tea.Msg { | ||
| p := <-m.progressChan | ||
| return cliProgressUpdateMsg{p: p} | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cliProgress.Updatedoesn't handledocker.DeployStageFinished, so the UI stage/progress can remain stuck on "starting" (with indeterminate progress) even after deploy has completed, until the program quits. Consider adding aDeployStageFinishedcase to set a sensible final stage (or transition to a new stage like "verifying") and/or set percent to 100.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the TUI exits at that stage, so it shouldn't be trying to displaying anything.