Skip to content

Modern Docker Management, Designed for Everyone

refactor: redesign update all environments view (#2943)

Kyle Mendell2171849932d3
diff --git a/backend/internal/models/environment_update_job.go b/backend/internal/models/environment_update_job.go
index 74a63d70c..17dabb0dd 100644
--- a/backend/internal/models/environment_update_job.go
+++ b/backend/internal/models/environment_update_job.go
@@ -28,9 +28,13 @@ const (
type EnvironmentUpdateResultStatus string
const (
- // EnvironmentUpdateResultStatusPending is the initial state recorded for the
- // manager entry while its self-upgrade is in flight.
+ // EnvironmentUpdateResultStatusPending is the initial state recorded for an
+ // environment that is seeded into the job but not yet being processed (and for
+ // the manager entry while its self-upgrade is in flight).
EnvironmentUpdateResultStatusPending EnvironmentUpdateResultStatus = "pending"
+ // EnvironmentUpdateResultStatusUpdating means this environment is being processed
+ // right now; it drives the live per-environment progress indicator in the UI.
+ EnvironmentUpdateResultStatusUpdating EnvironmentUpdateResultStatus = "updating"
// EnvironmentUpdateResultStatusUpdated means the upgrade was triggered and the
// new version was confirmed.
EnvironmentUpdateResultStatusUpdated EnvironmentUpdateResultStatus = "updated"
diff --git a/backend/internal/services/system_upgrade_service.go b/backend/internal/services/system_upgrade_service.go
index b97625951..fcab820d2 100644
--- a/backend/internal/services/system_upgrade_service.go
+++ b/backend/internal/services/system_upgrade_service.go
@@ -453,6 +453,11 @@ func (s *SystemUpgradeService) StartUpdateAll(ctx context.Context, user models.U
FromVersion: info.CurrentVersion,
}
+ // Seed a pending row for every remote environment up front so the dialog can
+ // show the whole fleet immediately instead of popping rows in as each finishes.
+ // Best effort: the agents phase re-lists authoritatively and fills any gaps.
+ remoteResults := s.seedRemoteResultsInternal(ctx, env)
+
job := &models.EnvironmentUpdateJob{
UserID: user.ID,
Username: user.Username,
@@ -465,7 +470,7 @@ func (s *SystemUpgradeService) StartUpdateAll(ctx context.Context, user models.U
managerResult.Status = models.EnvironmentUpdateResultStatusPending
managerResult.ToVersion = job.ManagerTargetVersion
job.Status = models.EnvironmentUpdateJobStatusPendingRestart
- job.Results = models.EnvironmentUpdateResults{managerResult}
+ job.Results = append(models.EnvironmentUpdateResults{managerResult}, remoteResults...)
if err := s.db.WithContext(ctx).Create(job).Error; err != nil {
return nil, fmt.Errorf("create update-all job: %w", err)
@@ -485,7 +490,7 @@ func (s *SystemUpgradeService) StartUpdateAll(ctx context.Context, user models.U
// Manager already up to date — go straight to the agents phase.
managerResult.Status = models.EnvironmentUpdateResultStatusSkippedUpToDate
job.Status = models.EnvironmentUpdateJobStatusRunning
- job.Results = models.EnvironmentUpdateResults{managerResult}
+ job.Results = append(models.EnvironmentUpdateResults{managerResult}, remoteResults...)
if err := s.db.WithContext(ctx).Create(job).Error; err != nil {
return nil, fmt.Errorf("create update-all job: %w", err)
@@ -573,13 +578,19 @@ func (s *SystemUpgradeService) runAgentsPhaseInternal(ctx context.Context, jobID
}
for _, remote := range envs {
- result := models.EnvironmentUpdateResult{
- EnvironmentID: remote.ID,
- EnvironmentName: remote.Name,
+ // Find the row seeded at job start (or append one if seeding missed this
+ // environment) and mark it updating so the dialog shows a live indicator on
+ // the row currently being processed.
+ idx := upsertPendingResultInternal(job, remote.ID, remote.Name)
+ job.Results[idx].Status = models.EnvironmentUpdateResultStatusUpdating
+ if err := s.persistUpdateAllJobInternal(ctx, job); err != nil {
+ slog.WarnContext(ctx, "update-all: failed to persist updating status", "jobId", job.ID, "environmentId", remote.ID, "error", err)
}
+
+ result := job.Results[idx]
s.upgradeAgentInternal(ctx, env, remote.ID, &result)
+ job.Results[idx] = result
- job.Results = append(job.Results, result)
if err := s.persistUpdateAllJobInternal(ctx, job); err != nil {
slog.WarnContext(ctx, "update-all: failed to persist progress", "jobId", job.ID, "environmentId", remote.ID, "error", err)
}
@@ -596,6 +607,43 @@ func (s *SystemUpgradeService) runAgentsPhaseInternal(ctx context.Context, jobID
slog.InfoContext(ctx, "Update-all job completed", "jobId", job.ID, "environments", len(job.Results))
}
+// seedRemoteResultsInternal builds a pending result row for every remote environment
+// so the dialog can render the whole fleet immediately. Best effort: on error it
+// returns nil and the agents phase appends rows as it processes them.
+func (s *SystemUpgradeService) seedRemoteResultsInternal(ctx context.Context, env *EnvironmentService) models.EnvironmentUpdateResults {
+ envs, err := env.ListRemoteEnvironments(ctx)
+ if err != nil {
+ slog.WarnContext(ctx, "update-all: failed to pre-list remote environments for seeding", "error", err)
+ return nil
+ }
+ results := make(models.EnvironmentUpdateResults, 0, len(envs))
+ for _, remote := range envs {
+ results = append(results, models.EnvironmentUpdateResult{
+ EnvironmentID: remote.ID,
+ EnvironmentName: remote.Name,
+ Status: models.EnvironmentUpdateResultStatusPending,
+ })
+ }
+ return results
+}
+
+// upsertPendingResultInternal returns the index of the existing result row for envID,
+// appending a new pending row when seeding missed it (e.g. the seed list failed, or a
+// new environment was registered after the job started).
+func upsertPendingResultInternal(job *models.EnvironmentUpdateJob, envID, envName string) int {
+ for i := range job.Results {
+ if job.Results[i].EnvironmentID == envID {
+ return i
+ }
+ }
+ job.Results = append(job.Results, models.EnvironmentUpdateResult{
+ EnvironmentID: envID,
+ EnvironmentName: envName,
+ Status: models.EnvironmentUpdateResultStatusPending,
+ })
+ return len(job.Results) - 1
+}
+
// upgradeAgentInternal checks, triggers, and confirms a single remote environment's
// self-upgrade, recording the outcome on result.
func (s *SystemUpgradeService) upgradeAgentInternal(ctx context.Context, env *EnvironmentService, envID string, result *models.EnvironmentUpdateResult) {
@@ -724,9 +772,36 @@ func (s *SystemUpgradeService) markUpdateAllFailedInternal(ctx context.Context,
job.Status = models.EnvironmentUpdateJobStatusFailed
job.Error = &reason
job.CompletedAt = &completedAt
+ for i := range job.Results {
+ if job.Results[i].Status == models.EnvironmentUpdateResultStatusUpdating {
+ job.Results[i].Status = models.EnvironmentUpdateResultStatusFailed
+ job.Results[i].Error = reason
+ }
+ }
if err := s.persistUpdateAllJobInternal(ctx, job); err != nil {
slog.WarnContext(ctx, "update-all: failed to mark job failed", "jobId", job.ID, "error", err)
}
+
+ // Surface the failure in the events audit log; the success path logs via
+ // logUpdateAllEventInternal. LogUserEvent hardcodes an info-severity "completed"
+ // title, so create the event directly with error severity and the reason.
+ if _, err := s.eventService.CreateEvent(ctx, CreateEventRequest{
+ Type: models.EventTypeSystemUpgrade,
+ Severity: models.EventSeverityError,
+ Title: "Update all environments failed",
+ Description: reason,
+ UserID: new(job.UserID),
+ Username: new(job.Username),
+ Metadata: models.JSON{
+ "action": "update_all_environments",
+ "jobId": job.ID,
+ "environments": len(job.Results),
+ "reason": reason,
+ },
+ }); err != nil {
+ slog.WarnContext(ctx, "update-all: failed to log failure event", "jobId", job.ID, "error", err)
+ }
+
slog.WarnContext(ctx, "Update-all job failed", "jobId", job.ID, "reason", reason)
}
@@ -748,12 +823,39 @@ func (s *SystemUpgradeService) recordManagerResultInternal(job *models.Environme
}
func (s *SystemUpgradeService) logUpdateAllEventInternal(ctx context.Context, job *models.EnvironmentUpdateJob) {
+ failed := 0
+ for _, r := range job.Results {
+ if r.Status == models.EnvironmentUpdateResultStatusFailed {
+ failed++
+ }
+ }
+
metadata := models.JSON{
"action": "update_all_environments",
"jobId": job.ID,
"environments": len(job.Results),
+ "failed": failed,
}
- if err := s.eventService.LogUserEvent(ctx, models.EventTypeSystemUpgrade, job.UserID, job.Username, metadata); err != nil {
+
+ // All environments succeeded: log the standard completed (info) event.
+ if failed == 0 {
+ if err := s.eventService.LogUserEvent(ctx, models.EventTypeSystemUpgrade, job.UserID, job.Username, metadata); err != nil {
+ slog.WarnContext(ctx, "Failed to log update-all event", "jobId", job.ID, "error", err)
+ }
+ return
+ }
+
+ // The job ran to completion but some environments failed to update — record a
+ // warning-severity event so those failures still show in the audit log.
+ if _, err := s.eventService.CreateEvent(ctx, CreateEventRequest{
+ Type: models.EventTypeSystemUpgrade,
+ Severity: models.EventSeverityWarning,
+ Title: "Update all environments completed with errors",
+ Description: fmt.Sprintf("%d of %d environments failed to update", failed, len(job.Results)),
+ UserID: new(job.UserID),
+ Username: new(job.Username),
+ Metadata: metadata,
+ }); err != nil {
slog.WarnContext(ctx, "Failed to log update-all event", "jobId", job.ID, "error", err)
}
}
diff --git a/backend/internal/services/system_upgrade_update_all_test.go b/backend/internal/services/system_upgrade_update_all_test.go
index a7bdba857..7f1a60ec2 100644
--- a/backend/internal/services/system_upgrade_update_all_test.go
+++ b/backend/internal/services/system_upgrade_update_all_test.go
@@ -1,10 +1,15 @@
package services
import (
+ "context"
"testing"
"time"
+ "github.com/getarcaneapp/arcane/backend/v2/internal/database"
"github.com/getarcaneapp/arcane/backend/v2/internal/models"
+ glsqlite "github.com/glebarez/sqlite"
+ "github.com/stretchr/testify/require"
+ "gorm.io/gorm"
)
func TestUpdateAllResolveResumeAction(t *testing.T) {
@@ -69,3 +74,83 @@ func TestUpdateAllResolveResumeAction(t *testing.T) {
})
}
}
+
+func TestUpsertPendingResult(t *testing.T) {
+ job := &models.EnvironmentUpdateJob{
+ Results: models.EnvironmentUpdateResults{
+ {EnvironmentID: "0", EnvironmentName: "Local", Status: models.EnvironmentUpdateResultStatusUpdated},
+ {EnvironmentID: "abc", EnvironmentName: "palladium", Status: models.EnvironmentUpdateResultStatusPending},
+ },
+ }
+
+ // A seeded environment resolves to its existing row without appending.
+ if idx := upsertPendingResultInternal(job, "abc", "palladium"); idx != 1 {
+ t.Fatalf("existing env index = %d, want 1", idx)
+ }
+ if len(job.Results) != 2 {
+ t.Fatalf("results grew to %d, want 2", len(job.Results))
+ }
+
+ // A missing environment (seeding raced or a new env was registered) appends a
+ // fresh pending row and returns the new index.
+ idx := upsertPendingResultInternal(job, "xyz", "oracle-cloud")
+ if idx != 2 {
+ t.Fatalf("new env index = %d, want 2", idx)
+ }
+ if len(job.Results) != 3 {
+ t.Fatalf("results = %d, want 3", len(job.Results))
+ }
+ got := job.Results[2]
+ if got.EnvironmentID != "xyz" || got.EnvironmentName != "oracle-cloud" {
+ t.Fatalf("appended row = %+v, want id=xyz name=oracle-cloud", got)
+ }
+ if got.Status != models.EnvironmentUpdateResultStatusPending {
+ t.Fatalf("appended row status = %q, want pending", got.Status)
+ }
+}
+
+func TestUpdateAllFailedJobMarksUpdatingResultsFailed(t *testing.T) {
+ ctx := context.Background()
+ gormDB, err := gorm.Open(glsqlite.Open("file:"+t.Name()+"?mode=memory&cache=shared"), &gorm.Config{})
+ require.NoError(t, err)
+
+ db := &database.DB{DB: gormDB}
+ require.NoError(t, db.AutoMigrate(&models.EnvironmentUpdateJob{}, &models.Event{}))
+
+ svc := NewSystemUpgradeService(db, nil, nil, NewEventService(db, nil, nil), nil)
+ job := &models.EnvironmentUpdateJob{
+ Status: models.EnvironmentUpdateJobStatusRunning,
+ UserID: "user-1",
+ Username: "arcane",
+ Results: models.EnvironmentUpdateResults{
+ {EnvironmentID: "0", EnvironmentName: "Local", Status: models.EnvironmentUpdateResultStatusSkippedUpToDate},
+ {EnvironmentID: "remote-1", EnvironmentName: "palladium", Status: models.EnvironmentUpdateResultStatusUpdating},
+ {EnvironmentID: "remote-2", EnvironmentName: "oracle-cloud", Status: models.EnvironmentUpdateResultStatusPending},
+ {EnvironmentID: "remote-3", EnvironmentName: "parquetide", Status: models.EnvironmentUpdateResultStatusFailed, Error: "already failed"},
+ },
+ }
+ require.NoError(t, db.WithContext(ctx).Create(job).Error)
+
+ reason := "interrupted by manager restart"
+ svc.markUpdateAllFailedInternal(ctx, job, reason)
+
+ var got models.EnvironmentUpdateJob
+ require.NoError(t, db.WithContext(ctx).First(&got, "id = ?", job.ID).Error)
+ require.Equal(t, models.EnvironmentUpdateJobStatusFailed, got.Status)
+ require.NotNil(t, got.Error)
+ require.Equal(t, reason, *got.Error)
+ require.NotNil(t, got.CompletedAt)
+ require.Len(t, got.Results, 4)
+
+ require.Equal(t, models.EnvironmentUpdateResultStatusSkippedUpToDate, got.Results[0].Status)
+ require.Empty(t, got.Results[0].Error)
+
+ require.Equal(t, models.EnvironmentUpdateResultStatusFailed, got.Results[1].Status)
+ require.Equal(t, reason, got.Results[1].Error)
+
+ require.Equal(t, models.EnvironmentUpdateResultStatusPending, got.Results[2].Status)
+ require.Empty(t, got.Results[2].Error)
+
+ require.Equal(t, models.EnvironmentUpdateResultStatusFailed, got.Results[3].Status)
+ require.Equal(t, "already failed", got.Results[3].Error)
+}
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index 2ed5e5b21..de0a1eaab 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -1322,10 +1322,12 @@
"environments_update_all_confirm": "Update All",
"environments_update_all_manager_restarting": "Manager is restarting, reconnecting…",
"environments_update_all_in_progress": "Updating environments…",
+ "environments_update_all_progress": "{done} of {total}",
"environments_update_all_completed": "All environments processed",
"environments_update_all_failed": "Update all failed",
"environments_update_all_trigger_failed": "Failed to start update all",
"environments_update_all_status_pending": "Pending",
+ "environments_update_all_status_updating": "Updating…",
"environments_update_all_status_updated": "Updated",
"environments_update_all_status_triggered": "Update triggered",
"environments_update_all_status_skipped_up_to_date": "Already up to date",
diff --git a/frontend/src/lib/services/api/system-upgrade-service.ts b/frontend/src/lib/services/api/system-upgrade-service.ts
index 2e1578dc4..6a94cffe5 100644
--- a/frontend/src/lib/services/api/system-upgrade-service.ts
+++ b/frontend/src/lib/services/api/system-upgrade-service.ts
@@ -19,6 +19,7 @@ export interface HealthCheckResult {
export type UpdateAllEnvironmentStatus =
| 'pending'
+ | 'updating'
| 'updated'
| 'triggered'
| 'skipped_up_to_date'
diff --git a/frontend/src/routes/(app)/environments/update-all-dialog.svelte b/frontend/src/routes/(app)/environments/update-all-dialog.svelte
index b9c1456eb..b6d340f93 100644
--- a/frontend/src/routes/(app)/environments/update-all-dialog.svelte
+++ b/frontend/src/routes/(app)/environments/update-all-dialog.svelte
@@ -3,6 +3,7 @@
import * as ScrollArea from '$lib/components/ui/scroll-area';
import { Button } from '$lib/components/ui/button';
import Spinner from '$lib/components/ui/spinner/spinner.svelte';
+ import { cn } from '$lib/utils';
import { m } from '$lib/paraglide/messages';
import { toast } from 'svelte-sonner';
import { onDestroy } from 'svelte';
@@ -106,8 +107,16 @@
return m.environments_update_all_in_progress();
});
+ // "Done" is every environment that has reached a terminal state — i.e. anything
+ // that isn't still queued (pending) or actively being worked on (updating).
+ const totalCount = $derived(job?.results?.length ?? 0);
+ const doneCount = $derived(job?.results?.filter((r) => r.status !== 'pending' && r.status !== 'updating').length ?? 0);
+ const progressPct = $derived(totalCount > 0 ? Math.round((doneCount / totalCount) * 100) : 0);
+
function statusLabel(status: UpdateAllEnvironmentStatus): string {
switch (status) {
+ case 'updating':
+ return m.environments_update_all_status_updating();
case 'updated':
return m.environments_update_all_status_updated();
case 'triggered':
@@ -156,30 +165,70 @@
{/if}
{#if job?.results?.length}
+ {#if phase === 'running'}
+ <div class="space-y-1.5">
+ <div class="text-muted-foreground flex items-center justify-end text-xs">
+ <span>{m.environments_update_all_progress({ done: doneCount, total: totalCount })}</span>
+ </div>
+ <div class="bg-muted h-1.5 overflow-hidden rounded-full">
+ <div class="bg-primary h-full rounded-full transition-all duration-500" style="width: {progressPct}%"></div>
+ </div>
+ </div>
+ {/if}
+
<ScrollArea.Root class="max-h-72">
<ul class="divide-border divide-y">
{#each job.results as result (result.environmentId)}
- <li class="flex items-center justify-between gap-3 py-2 text-sm">
- <div class="flex min-w-0 flex-col">
- <span class="truncate font-medium">{result.environmentName}</span>
- {#if result.error}
- <span class="text-muted-foreground truncate text-xs">{result.error}</span>
- {/if}
- </div>
- <div class="flex shrink-0 items-center gap-2">
- {#if result.status === 'updated'}
- <SuccessIcon class="size-4 text-green-500" />
+ <li class="flex items-center gap-3 py-2.5 text-sm">
+ <span
+ class={cn(
+ 'flex size-7 shrink-0 items-center justify-center rounded-full border',
+ (result.status === 'updated' || result.status === 'triggered') &&
+ 'border-green-500/40 bg-green-500/10 text-green-600 dark:text-green-400',
+ result.status === 'updating' && 'border-primary/40 bg-primary/10 text-primary',
+ result.status === 'skipped_up_to_date' && 'border-border bg-muted/40 text-muted-foreground',
+ result.status === 'skipped_offline' &&
+ 'border-amber-500/40 bg-amber-500/10 text-amber-600 dark:text-amber-400',
+ result.status === 'failed' && 'border-destructive/40 bg-destructive/10 text-destructive',
+ result.status === 'pending' && 'border-border bg-muted/40 text-muted-foreground/60'
+ )}
+ >
+ {#if result.status === 'updated' || result.status === 'triggered'}
+ <SuccessIcon class="size-3.5" />
+ {:else if result.status === 'updating'}
+ <Spinner class="size-3.5" />
{:else if result.status === 'skipped_up_to_date'}
- <CheckIcon class="text-muted-foreground size-4" />
+ <CheckIcon class="size-3.5" />
{:else if result.status === 'skipped_offline'}
- <AlertIcon class="size-4 text-amber-500" />
+ <AlertIcon class="size-3.5" />
{:else if result.status === 'failed'}
- <AlertTriangleIcon class="text-destructive size-4" />
+ <AlertTriangleIcon class="size-3.5" />
{:else}
- <ClockIcon class="text-muted-foreground size-4" />
+ <ClockIcon class="size-3.5" />
+ {/if}
+ </span>
+
+ <div class="flex min-w-0 flex-1 flex-col">
+ <span class="truncate font-medium">{result.environmentName}</span>
+ {#if result.status === 'updating'}
+ <div class="bg-muted mt-1.5 h-1 overflow-hidden rounded-full">
+ <div class="update-all-capbar bg-primary h-full rounded-full"></div>
+ </div>
+ {:else if result.error}
+ <span class="text-muted-foreground truncate text-xs">{result.error}</span>
{/if}
- <span class="text-muted-foreground">{statusLabel(result.status)}</span>
</div>
+
+ <span
+ class={cn(
+ 'shrink-0 text-xs',
+ result.status === 'updating' ? 'text-primary' : 'text-muted-foreground',
+ result.status === 'skipped_offline' && 'text-amber-600 dark:text-amber-400',
+ result.status === 'failed' && 'text-destructive'
+ )}
+ >
+ {statusLabel(result.status)}
+ </span>
</li>
{/each}
</ul>
@@ -203,3 +252,21 @@
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
+
+<style>
+ /* Indeterminate, capped progress: a short segment slides across the track so a
+ busy environment never reads as "100% complete" while the upgrade is still
+ running (we have no real per-step percentage from the backend). */
+ @keyframes update-all-indeterminate {
+ 0% {
+ transform: translateX(-100%);
+ }
+ 100% {
+ transform: translateX(250%);
+ }
+ }
+ .update-all-capbar {
+ width: 40%;
+ animation: update-all-indeterminate 1.4s ease-in-out infinite;
+ }
+</style>