Compare commits

..

1 Commits

Author SHA1 Message Date
30d3dbc796
feat: improved deploy progress reporting
All checks were successful
continuous-integration/drone/push Build is passing
See #478
2025-03-23 10:04:06 +01:00
3 changed files with 56 additions and 50 deletions

View File

@ -115,14 +115,16 @@ Pass "--all-services/-a" to restart all services.`,
log.Fatal(err)
}
if err := stack.WaitOnServices(
cmd.Context(),
cl,
[]ui.ServiceMeta{{Name: stackServiceName, ID: service.ID}},
app.Name,
app.Server,
f,
); err != nil {
waitOpts := stack.WaitOpts{
Services: []ui.ServiceMeta{{Name: stackServiceName, ID: service.ID}},
AppName: app.Name,
ServerName: app.Server,
Filters: f,
NoLog: true,
Quiet: true,
}
if err := stack.WaitOnServices(cmd.Context(), cl, waitOpts); err != nil {
log.Fatal(err)
}
@ -133,14 +135,7 @@ Pass "--all-services/-a" to restart all services.`,
log.Fatal(err)
}
if err := stack.WaitOnServices(
cmd.Context(),
cl,
[]ui.ServiceMeta{{Name: stackServiceName, ID: service.ID}},
app.Name,
app.Server,
f,
); err != nil {
if err := stack.WaitOnServices(cmd.Context(), cl, waitOpts); err != nil {
log.Fatal(err)
}

View File

@ -73,7 +73,7 @@ type stream struct {
reader *io.PipeReader
writer *io.PipeWriter
status string
attempts int
retries int
health string
rollback bool
}
@ -158,13 +158,13 @@ func DeployInitialModel(
r, w := io.Pipe()
d := json.NewDecoder(r)
streams = append(streams, stream{
Name: service.Name,
id: service.ID,
reader: r,
writer: w,
decoder: d,
attempts: 0,
health: "?",
Name: service.Name,
id: service.ID,
reader: r,
writer: w,
decoder: d,
retries: -1, // NOTE(d1): skip first attempt
health: "?",
})
}
@ -295,7 +295,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !strings.Contains(currentStatus, "starting") &&
strings.Contains(newStatus, "starting") {
(*m.Streams)[idx].attempts += 1
(*m.Streams)[idx].retries += 1
}
if (*m.Streams)[idx].rollback {
@ -338,10 +338,15 @@ func (m Model) View() string {
status = "rolled back"
}
output := fmt.Sprintf("%s: %s (attempts: %v, healthcheck: %s)",
retries := 0
if stream.retries > 0 {
retries = stream.retries
}
output := fmt.Sprintf("%s: %s (retries: %v, healthcheck: %s)",
formatter.BoldStyle.Render(short),
status,
stream.attempts,
retries,
stream.health,
)

View File

@ -300,14 +300,14 @@ func deployCompose(
return nil
}
if err := WaitOnServices(
ctx,
cl,
serviceIDs,
appName,
serverName,
filters,
); err != nil {
waitOpts := WaitOpts{
Services: serviceIDs,
AppName: appName,
ServerName: serverName,
Filters: filters,
}
if err := WaitOnServices(ctx, cl, waitOpts); err != nil {
return err
}
@ -535,19 +535,23 @@ func timestamp() string {
return strings.Replace(ts, ":", "", -1) // get rid of offensive colons
}
func WaitOnServices(
ctx context.Context,
cl *dockerClient.Client,
services []ui.ServiceMeta,
appName string,
serverName string,
filters filters.Args,
) error {
type WaitOpts struct {
AppName string
Filters filters.Args
NoLog bool
Quiet bool
ServerName string
Services []ui.ServiceMeta
}
func WaitOnServices(ctx context.Context, cl *dockerClient.Client, opts WaitOpts) error {
timeout := time.Duration(WaitTimeout) * time.Second
model := ui.DeployInitialModel(ctx, cl, services, appName, timeout, filters)
model := ui.DeployInitialModel(ctx, cl, opts.Services, opts.AppName, timeout, opts.Filters)
tui := tea.NewProgram(model)
log.Info("polling deployment status")
if !opts.Quiet {
log.Info("polling deployment status")
}
m, err := log.Without(
func() (tea.Model, error) {
@ -576,14 +580,14 @@ func WaitOnServices(
}
}
if len(*deployModel.Logs) > 0 {
if len(*deployModel.Logs) > 0 && !opts.NoLog {
logsPath := filepath.Join(
config.LOGS_DIR,
serverName,
fmt.Sprintf("%s_%s", appName, timestamp()),
opts.ServerName,
fmt.Sprintf("%s_%s", opts.AppName, timestamp()),
)
if err := os.MkdirAll(filepath.Join(config.LOGS_DIR, serverName), 0764); err != nil {
if err := os.MkdirAll(filepath.Join(config.LOGS_DIR, opts.ServerName), 0764); err != nil {
return fmt.Errorf("waitOnServices: error creating log dir: %s", err)
}
@ -604,7 +608,9 @@ func WaitOnServices(
return stdlibErr.Join(errs...)
}
log.Info("deploy succeeded 🟢")
if !opts.Quiet {
log.Info("deploy succeeded 🟢")
}
return nil
}