Skip to content

Modern Docker Management, Designed for Everyone

feat: full background activity tasks (#2434)

Kyle Mendell3d2c9efed76c
diff --git a/backend/api/api.go b/backend/api/api.go
index 1452ef40e..e78eecca5 100644
--- a/backend/api/api.go
+++ b/backend/api/api.go
@@ -146,6 +146,7 @@ type Services struct {
Font *services.FontService
Project *services.ProjectService
Event *services.EventService
+ Activity *services.ActivityService
Version *services.VersionService
Environment *services.EnvironmentService
Settings *services.SettingsService
@@ -319,6 +320,7 @@ func registerHandlers(api huma.API, svc *Services) {
var fontSvc *services.FontService
var projectSvc *services.ProjectService
var eventSvc *services.EventService
+ var activitySvc *services.ActivityService
var versionSvc *services.VersionService
var environmentSvc *services.EnvironmentService
var settingsSvc *services.SettingsService
@@ -358,6 +360,7 @@ func registerHandlers(api huma.API, svc *Services) {
fontSvc = svc.Font
projectSvc = svc.Project
eventSvc = svc.Event
+ activitySvc = svc.Activity
versionSvc = svc.Version
environmentSvc = svc.Environment
settingsSvc = svc.Settings
@@ -394,28 +397,29 @@ func registerHandlers(api huma.API, svc *Services) {
handlers.RegisterRoles(api, roleSvc)
handlers.RegisterAppImages(api, appImagesSvc)
handlers.RegisterFonts(api, fontSvc)
- handlers.RegisterProjects(api, projectSvc)
handlers.RegisterUsers(api, userSvc, authSvc)
+ handlers.RegisterProjects(api, projectSvc, activitySvc)
handlers.RegisterVersion(api, versionSvc)
handlers.RegisterEvents(api, eventSvc, apiKeySvc)
+ handlers.RegisterActivities(api, activitySvc, environmentSvc)
handlers.RegisterOidc(api, authSvc, oidcSvc, roleSvc, userSvc, cfg)
handlers.RegisterEnvironments(api, environmentSvc, settingsSvc, apiKeySvc, eventSvc, cfg)
handlers.RegisterContainerRegistries(api, containerRegistrySvc, environmentSvc)
handlers.RegisterTemplates(api, templateSvc, environmentSvc)
- handlers.RegisterImages(api, dockerSvc, imageSvc, imageUpdateSvc, settingsSvc, buildSvc)
+ handlers.RegisterImages(api, dockerSvc, imageSvc, imageUpdateSvc, settingsSvc, buildSvc, activitySvc)
handlers.RegisterBuildWorkspaces(api, buildWorkspaceSvc)
handlers.RegisterImageUpdates(api, imageUpdateSvc, imageSvc)
handlers.RegisterSettings(api, settingsSvc, settingsSearchSvc, environmentSvc, cfg)
handlers.RegisterJobSchedules(api, jobScheduleSvc, environmentSvc)
- handlers.RegisterVolumes(api, dockerSvc, volumeSvc)
- handlers.RegisterContainers(api, containerSvc, dockerSvc, settingsSvc)
+ handlers.RegisterVolumes(api, dockerSvc, volumeSvc, activitySvc)
+ handlers.RegisterContainers(api, containerSvc, dockerSvc, settingsSvc, activitySvc)
handlers.RegisterPorts(api, portSvc)
- handlers.RegisterNetworks(api, networkSvc, dockerSvc)
+ handlers.RegisterNetworks(api, networkSvc, dockerSvc, activitySvc)
handlers.RegisterSwarm(api, swarmSvc, environmentSvc, eventSvc, cfg)
handlers.RegisterNotifications(api, notificationSvc, cfg)
handlers.RegisterUpdater(api, updaterSvc)
handlers.RegisterCustomize(api, customizeSearchSvc)
- handlers.RegisterSystem(api, dockerSvc, systemSvc, systemUpgradeSvc, cfg)
+ handlers.RegisterSystem(api, dockerSvc, systemSvc, systemUpgradeSvc, cfg, activitySvc)
handlers.RegisterGitRepositories(api, gitRepositorySvc)
handlers.RegisterGitOpsSyncs(api, gitOpsSyncSvc)
handlers.RegisterWebhooks(api, webhookSvc)
diff --git a/backend/api/handlers/activities.go b/backend/api/handlers/activities.go
new file mode 100644
index 000000000..27cbed91a
--- /dev/null
+++ b/backend/api/handlers/activities.go
@@ -0,0 +1,485 @@
+package handlers
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "net/http"
+ "net/url"
+ "strconv"
+ "time"
+
+ "github.com/danielgtaylor/huma/v2"
+ humamw "github.com/getarcaneapp/arcane/backend/api/middleware"
+ "github.com/getarcaneapp/arcane/backend/internal/services"
+ "github.com/getarcaneapp/arcane/backend/pkg/authz"
+ "github.com/getarcaneapp/arcane/backend/pkg/pagination"
+ "github.com/getarcaneapp/arcane/types/activity"
+ "github.com/getarcaneapp/arcane/types/base"
+ "gorm.io/gorm"
+)
+
+type ActivityHandler struct {
+ activityService *services.ActivityService
+ environmentService *services.EnvironmentService
+}
+
+type ListActivitiesInput struct {
+ EnvironmentID string `path:"id" doc:"Environment ID"`
+ Search string `query:"search" doc:"Search query"`
+ Sort string `query:"sort" doc:"Column to sort by"`
+ Order string `query:"order" default:"desc" doc:"Sort direction"`
+ Start int `query:"start" default:"0" doc:"Start index"`
+ Limit int `query:"limit" default:"50" doc:"Limit"`
+ Status string `query:"status" doc:"Filter by activity status"`
+ Type string `query:"type" doc:"Filter by activity type"`
+ ResourceType string `query:"resourceType" doc:"Filter by resource type"`
+}
+
+type ListActivitiesOutput struct {
+ Body base.Paginated[activity.Activity]
+}
+
+type GetActivityInput struct {
+ EnvironmentID string `path:"id" doc:"Environment ID"`
+ ActivityID string `path:"activityId" doc:"Activity ID"`
+ Limit int `query:"limit" default:"500" doc:"Maximum messages to return"`
+}
+
+type GetActivityOutput struct {
+ Body base.ApiResponse[activity.Detail]
+}
+
+type ClearActivityHistoryInput struct {
+ EnvironmentID string `path:"id" doc:"Environment ID"`
+}
+
+type ClearActivityHistoryOutput struct {
+ Body base.ApiResponse[activity.ClearHistoryResult]
+}
+
+type StreamActivitiesInput struct {
+ EnvironmentID string `path:"id" doc:"Environment ID"`
+ Limit int `query:"limit" default:"50" doc:"Initial snapshot limit"`
+}
+
+func RegisterActivities(api huma.API, activityService *services.ActivityService, environmentService *services.EnvironmentService) {
+ h := &ActivityHandler{
+ activityService: activityService,
+ environmentService: environmentService,
+ }
+
+ huma.Register(api, huma.Operation{
+ OperationID: "list-activities",
+ Method: http.MethodGet,
+ Path: "/environments/{id}/activities",
+ Summary: "List background activities",
+ Description: "Get current and recent background activities for an environment",
+ Tags: []string{"Activities"},
+ Security: []map[string][]string{
+ {"BearerAuth": {}},
+ {"ApiKeyAuth": {}},
+ },
+ Middlewares: humamw.RequirePermission(api, authz.PermActivitiesRead),
+ }, h.ListActivities)
+
+ huma.Register(api, huma.Operation{
+ OperationID: "get-activity",
+ Method: http.MethodGet,
+ Path: "/environments/{id}/activities/{activityId}",
+ Summary: "Get background activity",
+ Description: "Get a background activity with its recent output messages",
+ Tags: []string{"Activities"},
+ Security: []map[string][]string{
+ {"BearerAuth": {}},
+ {"ApiKeyAuth": {}},
+ },
+ Middlewares: humamw.RequirePermission(api, authz.PermActivitiesRead),
+ }, h.GetActivity)
+
+ huma.Register(api, huma.Operation{
+ OperationID: "stream-activities",
+ Method: http.MethodGet,
+ Path: "/environments/{id}/activities/stream",
+ Summary: "Stream background activities",
+ Description: "Stream background activity updates as JSON lines",
+ Tags: []string{"Activities"},
+ Security: []map[string][]string{
+ {"BearerAuth": {}},
+ {"ApiKeyAuth": {}},
+ },
+ Middlewares: humamw.RequirePermission(api, authz.PermActivitiesRead),
+ }, h.StreamActivities)
+
+ huma.Register(api, huma.Operation{
+ OperationID: "clear-activity-history",
+ Method: http.MethodDelete,
+ Path: "/environments/{id}/activities/history",
+ Summary: "Clear background activity history",
+ Description: "Delete completed background activity history for an environment",
+ Tags: []string{"Activities"},
+ Security: []map[string][]string{
+ {"BearerAuth": {}},
+ {"ApiKeyAuth": {}},
+ },
+ Middlewares: humamw.RequirePermission(api, authz.PermActivitiesDelete),
+ }, h.ClearHistory)
+}
+
+func (h *ActivityHandler) ListActivities(ctx context.Context, input *ListActivitiesInput) (*ListActivitiesOutput, error) {
+ if input.EnvironmentID != "0" {
+ return h.proxyListActivitiesInternal(ctx, input)
+ }
+ if h.activityService == nil {
+ return nil, huma.Error500InternalServerError("service not available")
+ }
+
+ params := buildPaginationParamsInternal(input.Start, input.Limit, input.Sort, input.Order, input.Search)
+ if input.Status != "" {
+ params.Filters["status"] = input.Status
+ }
+ if input.Type != "" {
+ params.Filters["type"] = input.Type
+ }
+ if input.ResourceType != "" {
+ params.Filters["resourceType"] = input.ResourceType
+ }
+
+ activities, paginationResp, err := h.activityService.ListActivitiesPaginated(ctx, input.EnvironmentID, params)
+ if err != nil {
+ return nil, huma.Error500InternalServerError(err.Error())
+ }
+ h.applyActivitySourceLabelsInternal(ctx, input.EnvironmentID, activities)
+
+ return &ListActivitiesOutput{
+ Body: base.Paginated[activity.Activity]{
+ Success: true,
+ Data: activities,
+ Pagination: base.PaginationResponse{
+ TotalPages: paginationResp.TotalPages,
+ TotalItems: paginationResp.TotalItems,
+ CurrentPage: paginationResp.CurrentPage,
+ ItemsPerPage: paginationResp.ItemsPerPage,
+ GrandTotalItems: paginationResp.GrandTotalItems,
+ },
+ },
+ }, nil
+}
+
+func (h *ActivityHandler) GetActivity(ctx context.Context, input *GetActivityInput) (*GetActivityOutput, error) {
+ if input.EnvironmentID != "0" {
+ return h.proxyGetActivityInternal(ctx, input)
+ }
+ if h.activityService == nil {
+ return nil, huma.Error500InternalServerError("service not available")
+ }
+ if input.ActivityID == "" {
+ return nil, huma.Error400BadRequest("activity id is required")
+ }
+
+ detail, err := h.activityService.GetActivityDetail(ctx, input.EnvironmentID, input.ActivityID, input.Limit)
+ if err != nil {
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ return nil, huma.Error404NotFound("activity not found")
+ }
+ return nil, huma.Error500InternalServerError(err.Error())
+ }
+ h.applyActivitySourceLabelInternal(ctx, input.EnvironmentID, &detail.Activity)
+
+ return &GetActivityOutput{
+ Body: base.ApiResponse[activity.Detail]{
+ Success: true,
+ Data: *detail,
+ },
+ }, nil
+}
+
+func (h *ActivityHandler) StreamActivities(ctx context.Context, input *StreamActivitiesInput) (*huma.StreamResponse, error) {
+ if h.activityService == nil {
+ return nil, huma.Error500InternalServerError("service not available")
+ }
+
+ return &huma.StreamResponse{
+ Body: func(humaCtx huma.Context) { //nolint:contextcheck // streaming work must use humaCtx.Context()
+ humaCtx.SetHeader("Content-Type", "application/x-json-stream")
+ humaCtx.SetHeader("Cache-Control", "no-cache")
+ humaCtx.SetHeader("Connection", "keep-alive")
+ humaCtx.SetHeader("X-Accel-Buffering", "no")
+
+ writer := humaCtx.BodyWriter()
+ encoder := json.NewEncoder(writer)
+ flush := func() {
+ if f, ok := writer.(http.Flusher); ok {
+ f.Flush()
+ }
+ }
+
+ if input.EnvironmentID != "0" {
+ h.streamRemoteActivitySnapshotsInternal(humaCtx.Context(), input, encoder, flush)
+ return
+ }
+
+ h.streamLocalActivitiesInternal(humaCtx.Context(), input, encoder, flush)
+ },
+ }, nil
+}
+
+func (h *ActivityHandler) streamLocalActivitiesInternal(
+ ctx context.Context,
+ input *StreamActivitiesInput,
+ encoder *json.Encoder,
+ flush func(),
+) {
+ sendSnapshot := func() bool {
+ activities, _, err := h.activityService.ListActivitiesPaginated(ctx, input.EnvironmentID, pagination.QueryParams{
+ PaginationParams: pagination.PaginationParams{Limit: resolveActivityStreamLimitInternal(input.Limit)},
+ })
+ if err != nil {
+ return false
+ }
+ h.applyActivitySourceLabelsInternal(ctx, input.EnvironmentID, activities)
+ if err := encoder.Encode(activity.StreamEvent{
+ Type: "snapshot",
+ Activities: activities,
+ Timestamp: time.Now(),
+ }); err != nil {
+ return false
+ }
+ flush()
+ return true
+ }
+ if !sendSnapshot() {
+ return
+ }
+
+ events, missedEvents, unsubscribe := h.activityService.Subscribe(input.EnvironmentID)
+ defer unsubscribe()
+
+ ticker := time.NewTicker(15 * time.Second)
+ defer ticker.Stop()
+
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ case event, ok := <-events:
+ if !ok {
+ return
+ }
+ h.applyActivityStreamEventSourceLabelInternal(ctx, input.EnvironmentID, &event)
+ if err := encoder.Encode(event); err != nil {
+ return
+ }
+ flush()
+ case <-ticker.C:
+ if missedEvents() && !sendSnapshot() {
+ return
+ }
+ if err := encoder.Encode(activity.StreamEvent{
+ Type: "heartbeat",
+ Timestamp: time.Now(),
+ }); err != nil {
+ return
+ }
+ flush()
+ }
+ }
+}
+
+func (h *ActivityHandler) ClearHistory(ctx context.Context, input *ClearActivityHistoryInput) (*ClearActivityHistoryOutput, error) {
+ if input.EnvironmentID != "0" {
+ return h.proxyClearHistoryInternal(ctx, input)
+ }
+ if h.activityService == nil {
+ return nil, huma.Error500InternalServerError("service not available")
+ }
+
+ deleted, err := h.activityService.DeleteHistory(ctx, input.EnvironmentID)
+ if err != nil {
+ return nil, huma.Error500InternalServerError(err.Error())
+ }
+
+ return &ClearActivityHistoryOutput{
+ Body: base.ApiResponse[activity.ClearHistoryResult]{
+ Success: true,
+ Data: activity.ClearHistoryResult{Deleted: deleted},
+ },
+ }, nil
+}
+
+func (h *ActivityHandler) streamRemoteActivitySnapshotsInternal(
+ ctx context.Context,
+ input *StreamActivitiesInput,
+ encoder *json.Encoder,
+ flush func(),
+) {
+ pollTicker := time.NewTicker(5 * time.Second)
+ defer pollTicker.Stop()
+ heartbeatTicker := time.NewTicker(15 * time.Second)
+ defer heartbeatTicker.Stop()
+
+ sendSnapshot := func(ctx context.Context) bool {
+ output, err := h.proxyListActivitiesInternal(ctx, &ListActivitiesInput{
+ EnvironmentID: input.EnvironmentID,
+ Start: 0,
+ Limit: resolveActivityStreamLimitInternal(input.Limit),
+ Order: "desc",
+ })
+ if err != nil {
+ return false
+ }
+ if err := encoder.Encode(activity.StreamEvent{
+ Type: "snapshot",
+ Activities: output.Body.Data,
+ Timestamp: time.Now(),
+ }); err != nil {
+ return false
+ }
+ flush()
+ return true
+ }
+
+ if !sendSnapshot(ctx) {
+ return
+ }
+
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ case <-pollTicker.C:
+ if !sendSnapshot(ctx) {
+ return
+ }
+ case <-heartbeatTicker.C:
+ if err := encoder.Encode(activity.StreamEvent{
+ Type: "heartbeat",
+ Timestamp: time.Now(),
+ }); err != nil {
+ return
+ }
+ flush()
+ }
+ }
+}
+
+func (h *ActivityHandler) proxyListActivitiesInternal(ctx context.Context, input *ListActivitiesInput) (*ListActivitiesOutput, error) {
+ if h.environmentService == nil {
+ return nil, huma.Error500InternalServerError("environment service not available")
+ }
+ path := "/api/environments/0/activities?" + activityListQueryInternal(input).Encode()
+ out, err := proxyRemoteJSONInternal[base.Paginated[activity.Activity]](ctx, h.environmentService, input.EnvironmentID, http.MethodGet, path, nil)
+ if err != nil {
+ return nil, err
+ }
+ h.applyActivitySourceLabelsInternal(ctx, input.EnvironmentID, out.Data)
+ return &ListActivitiesOutput{Body: *out}, nil
+}
+
+func (h *ActivityHandler) proxyGetActivityInternal(ctx context.Context, input *GetActivityInput) (*GetActivityOutput, error) {
+ if h.environmentService == nil {
+ return nil, huma.Error500InternalServerError("environment service not available")
+ }
+ path := fmt.Sprintf("/api/environments/0/activities/%s?limit=%d", url.PathEscape(input.ActivityID), input.Limit)
+ out, err := proxyRemoteJSONInternal[base.ApiResponse[activity.Detail]](ctx, h.environmentService, input.EnvironmentID, http.MethodGet, path, nil)
+ if err != nil {
+ return nil, err
+ }
+ h.applyActivitySourceLabelInternal(ctx, input.EnvironmentID, &out.Data.Activity)
+ return &GetActivityOutput{Body: *out}, nil
+}
+
+func (h *ActivityHandler) proxyClearHistoryInternal(ctx context.Context, input *ClearActivityHistoryInput) (*ClearActivityHistoryOutput, error) {
+ if h.environmentService == nil {
+ return nil, huma.Error500InternalServerError("environment service not available")
+ }
+ out, err := proxyRemoteJSONInternal[base.ApiResponse[activity.ClearHistoryResult]](ctx, h.environmentService, input.EnvironmentID, http.MethodDelete, "/api/environments/0/activities/history", nil)
+ if err != nil {
+ return nil, err
+ }
+ return &ClearActivityHistoryOutput{Body: *out}, nil
+}
+
+func (h *ActivityHandler) applyActivitySourceLabelsInternal(ctx context.Context, environmentID string, activities []activity.Activity) {
+ sourceID, sourceName := h.resolveActivitySourceInternal(ctx, environmentID)
+ for i := range activities {
+ applyActivitySourceInternal(&activities[i], sourceID, sourceName)
+ }
+}
+
+func (h *ActivityHandler) applyActivitySourceLabelInternal(ctx context.Context, environmentID string, item *activity.Activity) {
+ sourceID, sourceName := h.resolveActivitySourceInternal(ctx, environmentID)
+ applyActivitySourceInternal(item, sourceID, sourceName)
+}
+
+func (h *ActivityHandler) applyActivityStreamEventSourceLabelInternal(ctx context.Context, environmentID string, event *activity.StreamEvent) {
+ if event == nil {
+ return
+ }
+ sourceID, sourceName := h.resolveActivitySourceInternal(ctx, environmentID)
+ if event.Activity != nil {
+ applyActivitySourceInternal(event.Activity, sourceID, sourceName)
+ }
+ for i := range event.Activities {
+ applyActivitySourceInternal(&event.Activities[i], sourceID, sourceName)
+ }
+}
+
+func (h *ActivityHandler) resolveActivitySourceInternal(ctx context.Context, environmentID string) (string, string) {
+ if environmentID == "" {
+ environmentID = "0"
+ }
+ if h.environmentService != nil {
+ if env, err := h.environmentService.GetEnvironmentByID(ctx, environmentID); err == nil && env != nil {
+ return env.ID, env.Name
+ }
+ }
+ if environmentID == "0" {
+ return "0", "Local"
+ }
+ return environmentID, environmentID
+}
+
+func applyActivitySourceInternal(item *activity.Activity, sourceID, sourceName string) {
+ if item == nil {
+ return
+ }
+ item.SourceEnvironmentID = sourceID
+ item.SourceEnvironmentName = sourceName
+}
+
+func activityListQueryInternal(input *ListActivitiesInput) url.Values {
+ values := url.Values{}
+ values.Set("start", strconv.Itoa(input.Start))
+ values.Set("limit", strconv.Itoa(input.Limit))
+ if input.Search != "" {
+ values.Set("search", input.Search)
+ }
+ if input.Sort != "" {
+ values.Set("sort", input.Sort)
+ }
+ if input.Order != "" {
+ values.Set("order", input.Order)
+ }
+ if input.Status != "" {
+ values.Set("status", input.Status)
+ }
+ if input.Type != "" {
+ values.Set("type", input.Type)
+ }
+ if input.ResourceType != "" {
+ values.Set("resourceType", input.ResourceType)
+ }
+ return values
+}
+
+func resolveActivityStreamLimitInternal(limit int) int {
+ if limit <= 0 {
+ return 50
+ }
+ if limit > 100 {
+ return 100
+ }
+ return limit
+}
diff --git a/backend/api/handlers/activities_test.go b/backend/api/handlers/activities_test.go
new file mode 100644
index 000000000..f9be5ff53
--- /dev/null
+++ b/backend/api/handlers/activities_test.go
@@ -0,0 +1,99 @@
+package handlers
+
+import (
+ "context"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+ "time"
+
+ glsqlite "github.com/glebarez/sqlite"
+ "github.com/stretchr/testify/require"
+ "gorm.io/gorm"
+
+ "github.com/getarcaneapp/arcane/backend/internal/database"
+ "github.com/getarcaneapp/arcane/backend/internal/models"
+ "github.com/getarcaneapp/arcane/backend/internal/services"
+)
+
+func setupActivityHandlerTestDBInternal(t *testing.T) *database.DB {
+ t.Helper()
+
+ db, err := gorm.Open(glsqlite.Open(":memory:"), &gorm.Config{})
+ require.NoError(t, err)
+ require.NoError(t, db.AutoMigrate(
+ &models.Activity{},
+ &models.ActivityMessage{},
+ &models.Environment{},
+ &models.SettingVariable{},
+ ))
+ return &database.DB{DB: db}
+}
+
+func TestActivityHandlerClearHistoryDeletesSelectedEnvironmentOnlyInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityHandlerTestDBInternal(t)
+ activityService := services.NewActivityService(db)
+ handler := &ActivityHandler{activityService: activityService}
+
+ completed, err := activityService.StartActivity(ctx, services.StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
+ require.NoError(t, err)
+ _, err = activityService.CompleteActivity(ctx, completed.ID, models.ActivityStatusSuccess, "done", nil)
+ require.NoError(t, err)
+
+ running, err := activityService.StartActivity(ctx, services.StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
+ require.NoError(t, err)
+ remoteCompleted, err := activityService.StartActivity(ctx, services.StartActivityRequest{EnvironmentID: "remote-1", Type: models.ActivityTypeResourceAction})
+ require.NoError(t, err)
+ _, err = activityService.CompleteActivity(ctx, remoteCompleted.ID, models.ActivityStatusSuccess, "done", nil)
+ require.NoError(t, err)
+
+ out, err := handler.ClearHistory(ctx, &ClearActivityHistoryInput{EnvironmentID: "0"})
+ require.NoError(t, err)
+ require.EqualValues(t, 1, out.Body.Data.Deleted)
+
+ var remaining []models.Activity
+ require.NoError(t, db.Find(&remaining).Error)
+ require.Len(t, remaining, 2)
+ require.ElementsMatch(t, []string{running.ID, remoteCompleted.ID}, []string{remaining[0].ID, remaining[1].ID})
+}
+
+func TestActivityHandlerClearHistoryProxiesRemoteEnvironmentInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityHandlerTestDBInternal(t)
+ settingsService, err := services.NewSettingsService(ctx, db)
+ require.NoError(t, err)
+
+ token := "remote-token"
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ require.Equal(t, http.MethodDelete, r.Method)
+ require.Equal(t, "/api/environments/0/activities/history", r.URL.Path)
+ require.Equal(t, token, r.Header.Get("X-API-Key"))
+ require.Equal(t, token, r.Header.Get("X-Arcane-Agent-Token"))
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"success":true,"data":{"deleted":7}}`))
+ }))
+ defer server.Close()
+
+ now := time.Now()
+ require.NoError(t, db.Create(&models.Environment{
+ BaseModel: models.BaseModel{
+ ID: "remote-1",
+ CreatedAt: now,
+ UpdatedAt: &now,
+ },
+ Name: "Remote",
+ ApiUrl: server.URL,
+ Status: string(models.EnvironmentStatusOnline),
+ Enabled: true,
+ AccessToken: &token,
+ }).Error)
+
+ handler := &ActivityHandler{
+ environmentService: services.NewEnvironmentService(db, server.Client(), nil, nil, settingsService, nil),
+ }
+
+ out, err := handler.ClearHistory(ctx, &ClearActivityHistoryInput{EnvironmentID: "remote-1"})
+ require.NoError(t, err)
+ require.EqualValues(t, 7, out.Body.Data.Deleted)
+}
diff --git a/backend/api/handlers/containers.go b/backend/api/handlers/containers.go
index 0f00bcc1b..a7a80d4e8 100644
--- a/backend/api/handlers/containers.go
+++ b/backend/api/handlers/containers.go
@@ -2,6 +2,7 @@ package handlers
import (
"context"
+ "io"
"maps"
"net/http"
"net/netip"
@@ -10,10 +11,14 @@ import (
"github.com/danielgtaylor/huma/v2"
humamw "github.com/getarcaneapp/arcane/backend/api/middleware"
"github.com/getarcaneapp/arcane/backend/internal/common"
+ "github.com/getarcaneapp/arcane/backend/internal/models"
"github.com/getarcaneapp/arcane/backend/internal/services"
"github.com/getarcaneapp/arcane/backend/pkg/authz"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane"
+ activitylib "github.com/getarcaneapp/arcane/backend/pkg/libarcane/activity"
"github.com/getarcaneapp/arcane/backend/pkg/pagination"
+ "github.com/getarcaneapp/arcane/backend/pkg/projects"
+ "github.com/getarcaneapp/arcane/backend/pkg/utils"
"github.com/getarcaneapp/arcane/types/base"
containertypes "github.com/getarcaneapp/arcane/types/container"
dockercontainer "github.com/moby/moby/api/types/container"
@@ -24,6 +29,7 @@ type ContainerHandler struct {
containerService *services.ContainerService
dockerService *services.DockerClientService
settingsService *services.SettingsService
+ activityService *services.ActivityService
}
// Paginated response
@@ -136,11 +142,12 @@ type SetAutoUpdateOutput struct {
Body ContainerActionResponse
}
-func RegisterContainers(api huma.API, containerSvc *services.ContainerService, dockerSvc *services.DockerClientService, settingsSvc *services.SettingsService) {
+func RegisterContainers(api huma.API, containerSvc *services.ContainerService, dockerSvc *services.DockerClientService, settingsSvc *services.SettingsService, activitySvc *services.ActivityService) {
h := &ContainerHandler{
containerService: containerSvc,
dockerService: dockerSvc,
settingsService: settingsSvc,
+ activityService: activitySvc,
}
huma.Register(api, huma.Operation{
@@ -615,14 +622,17 @@ func (h *ContainerHandler) StartContainer(ctx context.Context, input *ContainerA
return nil, huma.Error401Unauthorized("not authenticated")
}
+ activityID := activitylib.StartHandlerActivityForUser(ctx, h.activityService, input.EnvironmentID, models.ActivityTypeContainerStart, "container", input.ContainerID, input.ContainerID, user, "Starting container", "Container start requested", models.JSON{"containerID": input.ContainerID})
if err := h.containerService.StartContainer(ctx, input.ContainerID, *user); err != nil {
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container started", err)
return nil, huma.Error500InternalServerError((&common.ContainerStartError{Err: err}).Error())
}
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container started", nil)
return &ContainerActionOutput{
Body: ContainerActionResponse{
Success: true,
- Data: base.MessageResponse{Message: "Container started successfully"},
+ Data: base.MessageResponse{Message: "Container started successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
},
}, nil
}
@@ -637,14 +647,17 @@ func (h *ContainerHandler) StopContainer(ctx context.Context, input *ContainerAc
return nil, huma.Error401Unauthorized("not authenticated")
}
+ activityID := activitylib.StartHandlerActivityForUser(ctx, h.activityService, input.EnvironmentID, models.ActivityTypeContainerStop, "container", input.ContainerID, input.ContainerID, user, "Stopping container", "Container stop requested", models.JSON{"containerID": input.ContainerID})
if err := h.containerService.StopContainer(ctx, input.ContainerID, *user); err != nil {
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container stopped", err)
return nil, huma.Error500InternalServerError((&common.ContainerStopError{Err: err}).Error())
}
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container stopped", nil)
return &ContainerActionOutput{
Body: ContainerActionResponse{
Success: true,
- Data: base.MessageResponse{Message: "Container stopped successfully"},
+ Data: base.MessageResponse{Message: "Container stopped successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
},
}, nil
}
@@ -659,14 +672,17 @@ func (h *ContainerHandler) RestartContainer(ctx context.Context, input *Containe
return nil, huma.Error401Unauthorized("not authenticated")
}
+ activityID := activitylib.StartHandlerActivityForUser(ctx, h.activityService, input.EnvironmentID, models.ActivityTypeContainerRestart, "container", input.ContainerID, input.ContainerID, user, "Restarting container", "Container restart requested", models.JSON{"containerID": input.ContainerID})
if err := h.containerService.RestartContainer(ctx, input.ContainerID, *user); err != nil {
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container restarted", err)
return nil, huma.Error500InternalServerError((&common.ContainerRestartError{Err: err}).Error())
}
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container restarted", nil)
return &ContainerActionOutput{
Body: ContainerActionResponse{
Success: true,
- Data: base.MessageResponse{Message: "Container restarted successfully"},
+ Data: base.MessageResponse{Message: "Container restarted successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
},
}, nil
}
@@ -681,14 +697,23 @@ func (h *ContainerHandler) RedeployContainer(ctx context.Context, input *Contain
return nil, huma.Error401Unauthorized("not authenticated")
}
- newContainerID, err := h.containerService.RedeployContainer(ctx, input.ContainerID, *user)
+ activityID := activitylib.StartHandlerActivityForUser(ctx, h.activityService, input.EnvironmentID, models.ActivityTypeContainerRedeploy, "container", input.ContainerID, input.ContainerID, user, "Starting redeploy", "Container redeploy requested", models.JSON{"containerID": input.ContainerID})
+ activityWriter := activitylib.NewWriter(ctx, h.activityService, activityID, io.Discard, "Redeploying container")
+ redeployCtx := context.WithValue(ctx, projects.ProgressWriterKey{}, activityWriter)
+ newContainerID, err := h.containerService.RedeployContainer(redeployCtx, input.ContainerID, *user)
if err != nil {
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container redeploy failed", err)
return nil, huma.Error500InternalServerError((&common.ContainerRedeployError{Err: err}).Error())
}
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container redeployed", nil)
// Fetch full container details to return (consistent with other endpoints)
details, inspectErr := h.containerService.GetContainerDetails(ctx, newContainerID)
if inspectErr == nil {
+ details.ActivityID = utils.StringPtrFromTrimmed(activityID)
+
return &GetContainerOutput{
Body: ContainerDetailsResponse{
Success: true,
@@ -703,7 +728,8 @@ func (h *ContainerHandler) RedeployContainer(ctx context.Context, input *Contain
Body: ContainerDetailsResponse{
Success: true,
Data: containertypes.Details{
- ID: newContainerID,
+ ID: newContainerID,
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
},
},
}, nil
@@ -719,14 +745,17 @@ func (h *ContainerHandler) DeleteContainer(ctx context.Context, input *DeleteCon
return nil, huma.Error401Unauthorized("not authenticated")
}
+ activityID := activitylib.StartHandlerActivityForUser(ctx, h.activityService, input.EnvironmentID, models.ActivityTypeContainerDelete, "container", input.ContainerID, input.ContainerID, user, "Deleting container", "Container delete requested", models.JSON{"containerID": input.ContainerID, "force": input.Force, "removeVolumes": input.RemoveVolumes})
if err := h.containerService.DeleteContainer(ctx, input.ContainerID, input.Force, input.RemoveVolumes, *user); err != nil {
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container deleted", err)
return nil, huma.Error500InternalServerError((&common.ContainerDeleteError{Err: err}).Error())
}
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Container deleted", nil)
return &DeleteContainerOutput{
Body: ContainerActionResponse{
Success: true,
- Data: base.MessageResponse{Message: "Container deleted successfully"},
+ Data: base.MessageResponse{Message: "Container deleted successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
},
}, nil
}
diff --git a/backend/api/handlers/images.go b/backend/api/handlers/images.go
index 35d533e29..c3b377c1b 100644
--- a/backend/api/handlers/images.go
+++ b/backend/api/handlers/images.go
@@ -11,8 +11,10 @@ import (
"github.com/danielgtaylor/huma/v2"
humamw "github.com/getarcaneapp/arcane/backend/api/middleware"
"github.com/getarcaneapp/arcane/backend/internal/common"
+ "github.com/getarcaneapp/arcane/backend/internal/models"
"github.com/getarcaneapp/arcane/backend/internal/services"
"github.com/getarcaneapp/arcane/backend/pkg/authz"
+ activitylib "github.com/getarcaneapp/arcane/backend/pkg/libarcane/activity"
"github.com/getarcaneapp/arcane/backend/pkg/pagination"
"github.com/getarcaneapp/arcane/types/base"
"github.com/getarcaneapp/arcane/types/image"
@@ -27,6 +29,7 @@ type ImageHandler struct {
imageUpdateService *services.ImageUpdateService
settingsService *services.SettingsService
buildService *services.BuildService
+ activityService *services.ActivityService
}
// --- Huma Input/Output Wrappers ---
@@ -150,13 +153,14 @@ type UploadImageOutput struct {
}
// RegisterImages registers image management routes using Huma.
-func RegisterImages(api huma.API, dockerService *services.DockerClientService, imageService *services.ImageService, imageUpdateService *services.ImageUpdateService, settingsService *services.SettingsService, buildService *services.BuildService) {
+func RegisterImages(api huma.API, dockerService *services.DockerClientService, imageService *services.ImageService, imageUpdateService *services.ImageUpdateService, settingsService *services.SettingsService, buildService *services.BuildService, activityService *services.ActivityService) {
h := &ImageHandler{
dockerService: dockerService,
imageService: imageService,
imageUpdateService: imageUpdateService,
settingsService: settingsService,
buildService: buildService,
+ activityService: activityService,
}
huma.Register(api, huma.Operation{
@@ -444,12 +448,34 @@ func (h *ImageHandler) PullImage(ctx context.Context, input *PullImageInput) (*h
humaCtx.SetHeader("Connection", "keep-alive")
humaCtx.SetHeader("X-Accel-Buffering", "no")
- writer := humaCtx.BodyWriter()
+ rawWriter := humaCtx.BodyWriter()
+ activityID := activitylib.StartHandlerActivityForUser(
+ humaCtx.Context(),
+ h.activityService,
+ input.EnvironmentID,
+ models.ActivityTypeImagePull,
+ "image",
+ "",
+ fullImageName,
+ user,
+ "Pulling image",
+ "Image pull started",
+ models.JSON{"imageName": fullImageName},
+ )
+ activitylib.WriteStartedLine(rawWriter, activityID)
+ if f, ok := rawWriter.(http.Flusher); ok {
+ f.Flush()
+ }
+ writer := activitylib.NewWriter(humaCtx.Context(), h.activityService, activityID, rawWriter, "Pulling image")
if err := h.imageService.PullImage(humaCtx.Context(), fullImageName, writer, *user, credentials); err != nil {
+ activitylib.FlushWriter(writer)
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Image pull failed", err)
_, _ = fmt.Fprintf(writer, `{"error":%q}`+"\n", err.Error())
return
}
+ activitylib.FlushWriter(writer)
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Image pull completed", nil)
},
}, nil
}
@@ -476,11 +502,38 @@ func (h *ImageHandler) BuildImage(ctx context.Context, input *BuildImageInput) (
humaCtx.SetHeader("Connection", "keep-alive")
humaCtx.SetHeader("X-Accel-Buffering", "no")
- writer := humaCtx.BodyWriter()
+ rawWriter := humaCtx.BodyWriter()
+ resourceName := strings.Join(input.Body.Tags, ", ")
+ if strings.TrimSpace(resourceName) == "" {
+ resourceName = input.Body.ContextDir
+ }
+ activityID := activitylib.StartHandlerActivityForUser(
+ humaCtx.Context(),
+ h.activityService,
+ input.EnvironmentID,
+ models.ActivityTypeImageBuild,
+ "image",
+ "",
+ resourceName,
+ user,
+ "Building image",
+ "Image build started",
+ models.JSON{"contextDir": input.Body.ContextDir, "tags": input.Body.Tags},
+ )
+ activitylib.WriteStartedLine(rawWriter, activityID)
+ if f, ok := rawWriter.(http.Flusher); ok {
+ f.Flush()
+ }
+
+ writer := activitylib.NewWriter(humaCtx.Context(), h.activityService, activityID, rawWriter, "Building image")
if _, err := h.buildService.BuildImage(humaCtx.Context(), input.EnvironmentID, input.Body, writer, "", user); err != nil {
+ activitylib.FlushWriter(writer)
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Image build failed", err)
_, _ = fmt.Fprintf(writer, `{"error":%q}`+"\n", err.Error())
return
}
+ activitylib.FlushWriter(writer)
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Image build completed", nil)
},
}, nil
}
diff --git a/backend/api/handlers/networks.go b/backend/api/handlers/networks.go
index f0a80c118..81a8fc348 100644
--- a/backend/api/handlers/networks.go
+++ b/backend/api/handlers/networks.go
@@ -11,9 +11,12 @@ import (
"github.com/danielgtaylor/huma/v2"
humamw "github.com/getarcaneapp/arcane/backend/api/middleware"
"github.com/getarcaneapp/arcane/backend/internal/common"
+ "github.com/getarcaneapp/arcane/backend/internal/models"
"github.com/getarcaneapp/arcane/backend/internal/services"
"github.com/getarcaneapp/arcane/backend/pkg/authz"
+ activitylib "github.com/getarcaneapp/arcane/backend/pkg/libarcane/activity"
"github.com/getarcaneapp/arcane/backend/pkg/pagination"
+ "github.com/getarcaneapp/arcane/backend/pkg/utils"
"github.com/getarcaneapp/arcane/backend/pkg/utils/mapper"
"github.com/getarcaneapp/arcane/types/base"
networktypes "github.com/getarcaneapp/arcane/types/network"
@@ -21,8 +24,9 @@ import (
)
type NetworkHandler struct {
- networkService *services.NetworkService
- dockerService *services.DockerClientService
+ networkService *services.NetworkService
+ dockerService *services.DockerClientService
+ activityService *services.ActivityService
}
type NetworkPaginatedResponse struct {
@@ -133,10 +137,11 @@ type PruneNetworksOutput struct {
}
// RegisterNetworks registers network endpoints.
-func RegisterNetworks(api huma.API, networkSvc *services.NetworkService, dockerSvc *services.DockerClientService) {
+func RegisterNetworks(api huma.API, networkSvc *services.NetworkService, dockerSvc *services.DockerClientService, activitySvc *services.ActivityService) {
h := &NetworkHandler{
- networkService: networkSvc,
- dockerService: dockerSvc,
+ networkService: networkSvc,
+ dockerService: dockerSvc,
+ activityService: activitySvc,
}
huma.Register(api, huma.Operation{
@@ -279,7 +284,26 @@ func (h *NetworkHandler) CreateNetwork(ctx context.Context, input *CreateNetwork
// Convert to Docker SDK options
dockerOptions := input.Body.Options.ToDockerCreateOptions()
- response, err := h.networkService.CreateNetwork(ctx, input.Body.Name, dockerOptions, *user)
+ var response *dockernetwork.CreateResponse
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "network",
+ ResourceID: input.Body.Name,
+ ResourceName: input.Body.Name,
+ User: user,
+ Step: "Creating network",
+ Message: "Creating network",
+ SuccessMessage: "Network created successfully",
+ Metadata: models.JSON{
+ "action": "create_network",
+ "driver": input.Body.Options.Driver,
+ },
+ }, func() error {
+ var createErr error
+ response, createErr = h.networkService.CreateNetwork(ctx, input.Body.Name, dockerOptions, *user)
+ return createErr
+ })
if err != nil {
return nil, huma.Error500InternalServerError((&common.NetworkCreationError{Err: err}).Error())
}
@@ -288,6 +312,7 @@ func (h *NetworkHandler) CreateNetwork(ctx context.Context, input *CreateNetwork
if err != nil {
return nil, huma.Error500InternalServerError((&common.NetworkMappingError{Err: err}).Error())
}
+ out.ActivityID = utils.StringPtrFromTrimmed(activityID)
return &CreateNetworkOutput{
Body: NetworkCreatedApiResponse{
@@ -405,20 +430,49 @@ func (h *NetworkHandler) DeleteNetwork(ctx context.Context, input *DeleteNetwork
return nil, huma.Error401Unauthorized("not authenticated")
}
- if err := h.networkService.RemoveNetwork(ctx, input.NetworkID, *user); err != nil {
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "network",
+ ResourceID: input.NetworkID,
+ ResourceName: input.NetworkID,
+ User: user,
+ Step: "Removing network",
+ Message: "Removing network",
+ SuccessMessage: "Network removed successfully",
+ Metadata: models.JSON{
+ "action": "remove_network",
+ },
+ }, func() error {
+ return h.networkService.RemoveNetwork(ctx, input.NetworkID, *user)
+ })
+ if err != nil {
return nil, huma.Error500InternalServerError((&common.NetworkRemovalError{Err: err}).Error())
}
return &DeleteNetworkOutput{
Body: NetworkMessageApiResponse{
Success: true,
- Data: base.MessageResponse{Message: "Network removed successfully"},
+ Data: base.MessageResponse{Message: "Network removed successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
},
}, nil
}
func (h *NetworkHandler) PruneNetworks(ctx context.Context, input *PruneNetworksInput) (*PruneNetworksOutput, error) {
- report, err := h.networkService.PruneNetworks(ctx)
+ var report *dockernetwork.PruneReport
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "network",
+ Step: "Pruning unused networks",
+ Message: "Pruning unused networks",
+ SuccessMessage: "Networks pruned successfully",
+ Metadata: models.JSON{"action": "prune_networks"},
+ }, func() error {
+ var pruneErr error
+ report, pruneErr = h.networkService.PruneNetworks(ctx)
+ return pruneErr
+ })
if err != nil {
return nil, huma.Error500InternalServerError((&common.NetworkPruneError{Err: err}).Error())
}
@@ -427,6 +481,7 @@ func (h *NetworkHandler) PruneNetworks(ctx context.Context, input *PruneNetworks
if err != nil {
return nil, huma.Error500InternalServerError((&common.NetworkMappingError{Err: err}).Error())
}
+ out.ActivityID = utils.StringPtrFromTrimmed(activityID)
return &PruneNetworksOutput{
Body: NetworkPruneResponse{
diff --git a/backend/api/handlers/projects.go b/backend/api/handlers/projects.go
index 451413028..051b6758d 100644
--- a/backend/api/handlers/projects.go
+++ b/backend/api/handlers/projects.go
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
+ "io"
"log/slog"
"net/http"
"time"
@@ -11,8 +12,10 @@ import (
"github.com/danielgtaylor/huma/v2"
humamw "github.com/getarcaneapp/arcane/backend/api/middleware"
"github.com/getarcaneapp/arcane/backend/internal/common"
+ "github.com/getarcaneapp/arcane/backend/internal/models"
"github.com/getarcaneapp/arcane/backend/internal/services"
"github.com/getarcaneapp/arcane/backend/pkg/authz"
+ activitylib "github.com/getarcaneapp/arcane/backend/pkg/libarcane/activity"
"github.com/getarcaneapp/arcane/backend/pkg/pagination"
projects "github.com/getarcaneapp/arcane/backend/pkg/projects"
"github.com/getarcaneapp/arcane/backend/pkg/utils"
@@ -23,7 +26,8 @@ import (
// ProjectHandler provides Huma-based project management endpoints.
type ProjectHandler struct {
- projectService *services.ProjectService
+ projectService *services.ProjectService
+ activityService *services.ActivityService
}
// --- Huma Input/Output Wrappers ---
@@ -203,9 +207,10 @@ type PullProgressEvent struct {
// RegisterProjects registers project management routes using Huma.
// Note: WebSocket and streaming endpoints remain as Gin handlers.
-func RegisterProjects(api huma.API, projectService *services.ProjectService) {
+func RegisterProjects(api huma.API, projectService *services.ProjectService, activityService *services.ActivityService) {
h := &ProjectHandler{
- projectService: projectService,
+ projectService: projectService,
+ activityService: activityService,
}
huma.Register(api, huma.Operation{
@@ -594,8 +599,26 @@ func (h *ProjectHandler) DeployProject(ctx context.Context, input *DeployProject
humaCtx.SetHeader("Connection", "keep-alive")
humaCtx.SetHeader("X-Accel-Buffering", "no")
- writer := humaCtx.BodyWriter()
+ rawWriter := humaCtx.BodyWriter()
+ activityID := activitylib.StartHandlerActivityForUser(
+ humaCtx.Context(),
+ h.activityService,
+ input.EnvironmentID,
+ models.ActivityTypeProjectDeploy,
+ "project",
+ input.ProjectID,
+ input.ProjectID,
+ user,
+ "Starting deployment",
+ "Project deployment started",
+ models.JSON{"projectID": input.ProjectID},
+ )
+ activitylib.WriteStartedLine(rawWriter, activityID)
+ if f, ok := rawWriter.(http.Flusher); ok {
+ f.Flush()
+ }
+ writer := activitylib.NewWriter(humaCtx.Context(), h.activityService, activityID, rawWriter, "Deploying project")
_, _ = writer.Write([]byte(`{"type":"deploy","phase":"begin"}` + "\n"))
if f, ok := writer.(http.Flusher); ok {
f.Flush()
@@ -603,6 +626,8 @@ func (h *ProjectHandler) DeployProject(ctx context.Context, input *DeployProject
deployCtx := context.WithValue(humaCtx.Context(), projects.ProgressWriterKey{}, writer)
if err := h.projectService.DeployProject(deployCtx, input.ProjectID, *user, input.Body); err != nil {
+ activitylib.FlushWriter(writer)
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Project deployment failed", err)
_, _ = fmt.Fprintf(writer, `{"error":%q}`+"\n", err.Error())
if f, ok := writer.(http.Flusher); ok {
f.Flush()
@@ -614,6 +639,7 @@ func (h *ProjectHandler) DeployProject(ctx context.Context, input *DeployProject
if f, ok := writer.(http.Flusher); ok {
f.Flush()
}
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Project deployment completed", nil)
},
}, nil
}
@@ -629,19 +655,27 @@ func (h *ProjectHandler) DownProject(ctx context.Context, input *DownProjectInpu
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
}
- if err := h.projectService.DownProject(ctx, input.ProjectID, *user); err != nil {
+ activityID := activitylib.StartHandlerActivityForUser(ctx, h.activityService, input.EnvironmentID, models.ActivityTypeProjectDown, "project", input.ProjectID, input.ProjectID, user, "Stopping project", "Project stop requested", models.JSON{"projectID": input.ProjectID})
+ activityWriter := activitylib.NewWriter(ctx, h.activityService, activityID, io.Discard, "Stopping project")
+ downCtx := context.WithValue(ctx, projects.ProgressWriterKey{}, activityWriter)
+ if err := h.projectService.DownProject(downCtx, input.ProjectID, *user); err != nil {
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Project stopped", err)
var archivedErr *common.ProjectArchivedError
if errors.As(err, &archivedErr) {
return nil, huma.Error400BadRequest((&common.ProjectDownError{Err: err}).Error())
}
return nil, huma.Error500InternalServerError((&common.ProjectDownError{Err: err}).Error())
}
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Project stopped", nil)
return &DownProjectOutput{
Body: base.ApiResponse[base.MessageResponse]{
Success: true,
Data: base.MessageResponse{
- Message: "Project brought down successfully",
+ Message: "Project brought down successfully",
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
},
},
}, nil
@@ -658,7 +692,23 @@ func (h *ProjectHandler) CreateProject(ctx context.Context, input *CreateProject
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
}
- proj, err := h.projectService.CreateProject(ctx, input.Body.Name, input.Body.ComposeContent, input.Body.EnvContent, *user)
+ var proj *models.Project
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "project",
+ ResourceID: input.Body.Name,
+ ResourceName: input.Body.Name,
+ User: user,
+ Step: "Creating project",
+ Message: "Creating project",
+ SuccessMessage: "Project created successfully",
+ Metadata: models.JSON{"action": "create_project"},
+ }, func() error {
+ var createErr error
+ proj, createErr = h.projectService.CreateProject(ctx, input.Body.Name, input.Body.ComposeContent, input.Body.EnvContent, *user)
+ return createErr
+ })
if err != nil {
return nil, huma.Error500InternalServerError((&common.ProjectCreationError{Err: err}).Error())
}
@@ -676,6 +726,7 @@ func (h *ProjectHandler) CreateProject(ctx context.Context, input *CreateProject
response.GitOpsManagedBy = proj.GitOpsManagedBy
response.IsArchived = proj.IsArchived
response.ArchivedAt = proj.ArchivedAt
+ response.ActivityID = utils.StringPtrFromTrimmed(activityID)
return &CreateProjectOutput{
Body: base.ApiResponse[project.CreateReponse]{
@@ -809,19 +860,39 @@ func (h *ProjectHandler) RedeployProject(ctx context.Context, input *RedeployPro
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
}
- if err := h.projectService.RedeployProject(ctx, input.ProjectID, *user, input.Body); err != nil {
+ activityID := activitylib.StartHandlerActivityForUser(
+ ctx,
+ h.activityService,
+ input.EnvironmentID,
+ models.ActivityTypeProjectRedeploy,
+ "project",
+ input.ProjectID,
+ input.ProjectID,
+ user,
+ "Starting redeploy",
+ "Project redeploy started",
+ models.JSON{"projectID": input.ProjectID},
+ )
+ activityWriter := activitylib.NewWriter(ctx, h.activityService, activityID, io.Discard, "Redeploying project")
+ redeployCtx := context.WithValue(ctx, projects.ProgressWriterKey{}, activityWriter)
+ if err := h.projectService.RedeployProject(redeployCtx, input.ProjectID, *user, input.Body); err != nil {
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Project redeploy failed", err)
var archivedErr *common.ProjectArchivedError
if errors.As(err, &archivedErr) {
return nil, huma.Error400BadRequest(err.Error())
}
return nil, huma.Error400BadRequest((&common.ProjectRedeploymentError{Err: err}).Error())
}
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Project redeploy completed", nil)
return &RedeployProjectOutput{
Body: base.ApiResponse[base.MessageResponse]{
Success: true,
Data: base.MessageResponse{
- Message: "Project redeployed successfully",
+ Message: "Project redeployed successfully",
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
},
},
}, nil
@@ -852,15 +923,23 @@ func (h *ProjectHandler) DestroyProject(ctx context.Context, input *DestroyProje
"projectID", input.ProjectID)
}
- if err := h.projectService.DestroyProject(ctx, input.ProjectID, removeFiles, removeVolumes, *user); err != nil {
+ activityID := activitylib.StartHandlerActivityForUser(ctx, h.activityService, input.EnvironmentID, models.ActivityTypeProjectDestroy, "project", input.ProjectID, input.ProjectID, user, "Destroying project", "Project destroy requested", models.JSON{"projectID": input.ProjectID, "removeFiles": removeFiles, "removeVolumes": removeVolumes})
+ activityWriter := activitylib.NewWriter(ctx, h.activityService, activityID, io.Discard, "Destroying project")
+ destroyCtx := context.WithValue(ctx, projects.ProgressWriterKey{}, activityWriter)
+ if err := h.projectService.DestroyProject(destroyCtx, input.ProjectID, removeFiles, removeVolumes, *user); err != nil {
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Project destroyed", err)
return nil, huma.Error500InternalServerError((&common.ProjectDestroyError{Err: err}).Error())
}
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Project destroyed", nil)
return &DestroyProjectOutput{
Body: base.ApiResponse[base.MessageResponse]{
Success: true,
Data: base.MessageResponse{
- Message: "Project destroyed successfully",
+ Message: "Project destroyed successfully",
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
},
},
}, nil
@@ -881,7 +960,22 @@ func (h *ProjectHandler) UpdateProject(ctx context.Context, input *UpdateProject
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
}
- if _, err := h.projectService.UpdateProject(ctx, input.ProjectID, input.Body.Name, input.Body.ComposeContent, input.Body.EnvContent, *user); err != nil {
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "project",
+ ResourceID: input.ProjectID,
+ ResourceName: utils.DerefString(input.Body.Name),
+ User: user,
+ Step: "Updating project",
+ Message: "Updating project",
+ SuccessMessage: "Project updated successfully",
+ Metadata: models.JSON{"action": "update_project", "projectID": input.ProjectID},
+ }, func() error {
+ _, updateErr := h.projectService.UpdateProject(ctx, input.ProjectID, input.Body.Name, input.Body.ComposeContent, input.Body.EnvContent, *user)
+ return updateErr
+ })
+ if err != nil {
return nil, huma.Error400BadRequest((&common.ProjectUpdateError{Err: err}).Error())
}
@@ -889,6 +983,7 @@ func (h *ProjectHandler) UpdateProject(ctx context.Context, input *UpdateProject
if err != nil {
return nil, huma.Error500InternalServerError((&common.ProjectDetailsError{Err: err}).Error())
}
+ details.ActivityID = utils.StringPtrFromTrimmed(activityID)
return &UpdateProjectOutput{
Body: base.ApiResponse[project.Details]{
@@ -913,7 +1008,25 @@ func (h *ProjectHandler) UpdateProjectInclude(ctx context.Context, input *Update
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
}
- if err := h.projectService.UpdateProjectIncludeFile(ctx, input.ProjectID, input.Body.RelativePath, input.Body.Content, *user); err != nil {
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "project",
+ ResourceID: input.ProjectID,
+ ResourceName: input.ProjectID,
+ User: user,
+ Step: "Updating project file",
+ Message: "Updating project include file",
+ SuccessMessage: "Project file updated successfully",
+ Metadata: models.JSON{
+ "action": "update_project_include",
+ "projectID": input.ProjectID,
+ "relativePath": input.Body.RelativePath,
+ },
+ }, func() error {
+ return h.projectService.UpdateProjectIncludeFile(ctx, input.ProjectID, input.Body.RelativePath, input.Body.Content, *user)
+ })
+ if err != nil {
return nil, huma.Error400BadRequest((&common.ProjectUpdateError{Err: err}).Error())
}
@@ -921,6 +1034,7 @@ func (h *ProjectHandler) UpdateProjectInclude(ctx context.Context, input *Update
if err != nil {
return nil, huma.Error500InternalServerError((&common.ProjectDetailsError{Err: err}).Error())
}
+ details.ActivityID = utils.StringPtrFromTrimmed(activityID)
return &UpdateProjectIncludeOutput{
Body: base.ApiResponse[project.Details]{
@@ -945,19 +1059,27 @@ func (h *ProjectHandler) RestartProject(ctx context.Context, input *RestartProje
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
}
- if err := h.projectService.RestartProject(ctx, input.ProjectID, *user); err != nil {
+ activityID := activitylib.StartHandlerActivityForUser(ctx, h.activityService, input.EnvironmentID, models.ActivityTypeProjectRestart, "project", input.ProjectID, input.ProjectID, user, "Restarting project", "Project restart requested", models.JSON{"projectID": input.ProjectID})
+ activityWriter := activitylib.NewWriter(ctx, h.activityService, activityID, io.Discard, "Restarting project")
+ restartCtx := context.WithValue(ctx, projects.ProgressWriterKey{}, activityWriter)
+ if err := h.projectService.RestartProject(restartCtx, input.ProjectID, *user); err != nil {
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Project restarted", err)
var archivedErr *common.ProjectArchivedError
if errors.As(err, &archivedErr) {
return nil, huma.Error400BadRequest(err.Error())
}
return nil, huma.Error400BadRequest((&common.ProjectRestartError{Err: err}).Error())
}
+ activitylib.FlushWriter(activityWriter)
+ activitylib.CompleteHandlerActivity(ctx, h.activityService, activityID, "Project restarted", nil)
return &RestartProjectOutput{
Body: base.ApiResponse[base.MessageResponse]{
Success: true,
Data: base.MessageResponse{
- Message: "Project restarted successfully",
+ Message: "Project restarted successfully",
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
},
},
}, nil
@@ -1041,14 +1163,31 @@ func (h *ProjectHandler) PullProjectImages(ctx context.Context, input *PullProje
humaCtx.SetHeader("Connection", "keep-alive")
humaCtx.SetHeader("X-Accel-Buffering", "no")
- writer := humaCtx.BodyWriter()
-
+ rawWriter := humaCtx.BodyWriter()
+ activityID := activitylib.StartHandlerActivityForUser(
+ humaCtx.Context(),
+ h.activityService,
+ input.EnvironmentID,
+ models.ActivityTypeProjectPull,
+ "project",
+ input.ProjectID,
+ input.ProjectID,
+ user,
+ "Pulling project images",
+ "Project image pull started",
+ models.JSON{"projectID": input.ProjectID},
+ )
+ activitylib.WriteStartedLine(rawWriter, activityID)
+
+ writer := activitylib.NewWriter(humaCtx.Context(), h.activityService, activityID, rawWriter, "Pulling project images")
_, _ = writer.Write([]byte(`{"status":"starting project image pull"}` + "\n"))
if f, ok := writer.(http.Flusher); ok {
f.Flush()
}
if err := h.projectService.PullProjectImages(humaCtx.Context(), input.ProjectID, writer, *user, nil); err != nil {
+ activitylib.FlushWriter(writer)
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Project image pull failed", err)
_, _ = fmt.Fprintf(writer, `{"error":%q}`+"\n", err.Error())
if f, ok := writer.(http.Flusher); ok {
f.Flush()
@@ -1060,6 +1199,7 @@ func (h *ProjectHandler) PullProjectImages(ctx context.Context, input *PullProje
if f, ok := writer.(http.Flusher); ok {
f.Flush()
}
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Project image pull completed", nil)
},
}, nil
}
@@ -1094,13 +1234,31 @@ func (h *ProjectHandler) BuildProjectImages(ctx context.Context, input *BuildPro
humaCtx.SetHeader("Connection", "keep-alive")
humaCtx.SetHeader("X-Accel-Buffering", "no")
- writer := humaCtx.BodyWriter()
+ rawWriter := humaCtx.BodyWriter()
+ activityID := activitylib.StartHandlerActivityForUser(
+ humaCtx.Context(),
+ h.activityService,
+ input.EnvironmentID,
+ models.ActivityTypeProjectBuild,
+ "project",
+ input.ProjectID,
+ input.ProjectID,
+ user,
+ "Building project images",
+ "Project image build started",
+ models.JSON{"projectID": input.ProjectID, "services": options.Services},
+ )
+ activitylib.WriteStartedLine(rawWriter, activityID)
+
+ writer := activitylib.NewWriter(humaCtx.Context(), h.activityService, activityID, rawWriter, "Building project images")
_, _ = writer.Write([]byte(`{"type":"build","phase":"begin"}` + "\n"))
if f, ok := writer.(http.Flusher); ok {
f.Flush()
}
if err := h.projectService.BuildProjectServices(humaCtx.Context(), input.ProjectID, options, writer, user); err != nil {
+ activitylib.FlushWriter(writer)
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Project image build failed", err)
_, _ = fmt.Fprintf(writer, `{"error":%q}`+"\n", err.Error())
if f, ok := writer.(http.Flusher); ok {
f.Flush()
@@ -1112,6 +1270,7 @@ func (h *ProjectHandler) BuildProjectImages(ctx context.Context, input *BuildPro
if f, ok := writer.(http.Flusher); ok {
f.Flush()
}
+ activitylib.CompleteHandlerActivity(humaCtx.Context(), h.activityService, activityID, "Project image build completed", nil)
},
}, nil
}
diff --git a/backend/api/handlers/system.go b/backend/api/handlers/system.go
index eda95b4ec..de9a9eb18 100644
--- a/backend/api/handlers/system.go
+++ b/backend/api/handlers/system.go
@@ -23,10 +23,11 @@ import (
// SystemHandler handles system management endpoints.
type SystemHandler struct {
- dockerService *services.DockerClientService
- systemService *services.SystemService
- upgradeService *services.SystemUpgradeService
- cfg *config.Config
+ dockerService *services.DockerClientService
+ systemService *services.SystemService
+ upgradeService *services.SystemUpgradeService
+ activityService *services.ActivityService
+ cfg *config.Config
}
// --- Input/Output Types ---
@@ -114,12 +115,13 @@ type TriggerUpgradeOutput struct {
// RegisterSystem registers system management endpoints using Huma.
// Note: WebSocket endpoints (stats) remain in the Gin handler.
-func RegisterSystem(api huma.API, dockerService *services.DockerClientService, systemService *services.SystemService, upgradeService *services.SystemUpgradeService, cfg *config.Config) {
+func RegisterSystem(api huma.API, dockerService *services.DockerClientService, systemService *services.SystemService, upgradeService *services.SystemUpgradeService, cfg *config.Config, activityService *services.ActivityService) {
h := &SystemHandler{
- dockerService: dockerService,
- systemService: systemService,
- upgradeService: upgradeService,
- cfg: cfg,
+ dockerService: dockerService,
+ systemService: systemService,
+ upgradeService: upgradeService,
+ activityService: activityService,
+ cfg: cfg,
}
huma.Register(api, huma.Operation{
@@ -374,18 +376,9 @@ func (h *SystemHandler) PruneAll(ctx context.Context, input *PruneAllInput) (*Pr
"networks", input.Body.Networks,
"build_cache", input.Body.BuildCache)
- result, err := h.systemService.PruneAll(ctx, input.Body)
- if err != nil {
- slog.ErrorContext(ctx, "System prune operation failed", "error", err)
- return nil, huma.Error500InternalServerError((&common.SystemPruneError{Err: err}).Error())
- }
+ result := h.systemService.StartPruneAll(ctx, input.EnvironmentID, input.Body)
- slog.InfoContext(ctx, "System prune operation completed successfully",
- "containers_pruned", len(result.ContainersPruned),
- "images_deleted", len(result.ImagesDeleted),
- "volumes_deleted", len(result.VolumesDeleted),
- "networks_deleted", len(result.NetworksDeleted),
- "space_reclaimed", result.SpaceReclaimed)
+ slog.InfoContext(ctx, "System prune background activity started", "activityId", result.ActivityID)
return &PruneAllOutput{
Body: base.ApiResponse[system.PruneAllResult]{
@@ -401,7 +394,7 @@ func (h *SystemHandler) StartAllContainers(ctx context.Context, input *StartAllC
return nil, huma.Error500InternalServerError("service not available")
}
- result, err := h.systemService.StartAllContainers(ctx)
+ result, err := h.systemService.StartAllContainers(ctx, input.EnvironmentID)
if err != nil {
return nil, huma.Error500InternalServerError((&common.ContainerStartAllError{Err: err}).Error())
}
@@ -420,7 +413,7 @@ func (h *SystemHandler) StartAllStoppedContainers(ctx context.Context, input *St
return nil, huma.Error500InternalServerError("service not available")
}
- result, err := h.systemService.StartAllStoppedContainers(ctx)
+ result, err := h.systemService.StartAllStoppedContainers(ctx, input.EnvironmentID)
if err != nil {
return nil, huma.Error500InternalServerError((&common.ContainerStartStoppedError{Err: err}).Error())
}
@@ -439,7 +432,7 @@ func (h *SystemHandler) StopAllContainers(ctx context.Context, input *StopAllCon
return nil, huma.Error500InternalServerError("service not available")
}
- result, err := h.systemService.StopAllContainers(ctx)
+ result, err := h.systemService.StopAllContainers(ctx, input.EnvironmentID)
if err != nil {
return nil, huma.Error500InternalServerError((&common.ContainerStopAllError{Err: err}).Error())
}
diff --git a/backend/api/handlers/volumes.go b/backend/api/handlers/volumes.go
index 6989d1748..156d3a127 100644
--- a/backend/api/handlers/volumes.go
+++ b/backend/api/handlers/volumes.go
@@ -14,7 +14,9 @@ import (
"github.com/getarcaneapp/arcane/backend/internal/models"
"github.com/getarcaneapp/arcane/backend/internal/services"
"github.com/getarcaneapp/arcane/backend/pkg/authz"
+ activitylib "github.com/getarcaneapp/arcane/backend/pkg/libarcane/activity"
"github.com/getarcaneapp/arcane/backend/pkg/pagination"
+ "github.com/getarcaneapp/arcane/backend/pkg/utils"
"github.com/getarcaneapp/arcane/types/base"
volumetypes "github.com/getarcaneapp/arcane/types/volume"
"github.com/moby/moby/client"
@@ -22,8 +24,9 @@ import (
// VolumeHandler provides Huma-based volume management endpoints.
type VolumeHandler struct {
- volumeService *services.VolumeService
- dockerService *services.DockerClientService
+ volumeService *services.VolumeService
+ dockerService *services.DockerClientService
+ activityService *services.ActivityService
}
// --- Huma Input/Output Wrappers ---
@@ -96,6 +99,7 @@ type PruneVolumesInput struct {
type VolumePruneReportData struct {
VolumesDeleted []string `json:"volumesDeleted,omitempty"`
SpaceReclaimed uint64 `json:"spaceReclaimed"`
+ ActivityID *string `json:"activityId,omitempty"`
}
type PruneVolumesOutput struct {
@@ -295,10 +299,11 @@ type UploadAndRestoreOutput struct {
}
// RegisterVolumes registers volume management routes using Huma.
-func RegisterVolumes(api huma.API, dockerService *services.DockerClientService, volumeService *services.VolumeService) {
+func RegisterVolumes(api huma.API, dockerService *services.DockerClientService, volumeService *services.VolumeService, activityService *services.ActivityService) {
h := &VolumeHandler{
- volumeService: volumeService,
- dockerService: dockerService,
+ volumeService: volumeService,
+ dockerService: dockerService,
+ activityService: activityService,
}
huma.Register(api, huma.Operation{
@@ -743,10 +748,30 @@ func (h *VolumeHandler) CreateVolume(ctx context.Context, input *CreateVolumeInp
DriverOpts: input.Body.DriverOpts,
}
- response, err := h.volumeService.CreateVolume(ctx, options, *user)
+ var response *volumetypes.Volume
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ ResourceID: input.Body.Name,
+ ResourceName: input.Body.Name,
+ User: user,
+ Step: "Creating volume",
+ Message: "Creating volume",
+ SuccessMessage: "Volume created successfully",
+ Metadata: models.JSON{
+ "action": "create_volume",
+ "driver": input.Body.Driver,
+ },
+ }, func() error {
+ var createErr error
+ response, createErr = h.volumeService.CreateVolume(ctx, options, *user)
+ return createErr
+ })
if err != nil {
return nil, huma.Error500InternalServerError((&common.VolumeCreationError{Err: err}).Error())
}
+ response.ActivityID = utils.StringPtrFromTrimmed(activityID)
return &CreateVolumeOutput{
Body: base.ApiResponse[*volumetypes.Volume]{
@@ -767,7 +792,24 @@ func (h *VolumeHandler) RemoveVolume(ctx context.Context, input *RemoveVolumeInp
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
}
- if err := h.volumeService.DeleteVolume(ctx, input.VolumeName, input.Force, *user); err != nil {
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ ResourceID: input.VolumeName,
+ ResourceName: input.VolumeName,
+ User: user,
+ Step: "Removing volume",
+ Message: "Removing volume",
+ SuccessMessage: "Volume removed successfully",
+ Metadata: models.JSON{
+ "action": "remove_volume",
+ "force": input.Force,
+ },
+ }, func() error {
+ return h.volumeService.DeleteVolume(ctx, input.VolumeName, input.Force, *user)
+ })
+ if err != nil {
return nil, huma.Error500InternalServerError((&common.VolumeDeletionError{Err: err}).Error())
}
@@ -775,7 +817,8 @@ func (h *VolumeHandler) RemoveVolume(ctx context.Context, input *RemoveVolumeInp
Body: base.ApiResponse[base.MessageResponse]{
Success: true,
Data: base.MessageResponse{
- Message: "Volume removed successfully",
+ Message: "Volume removed successfully",
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
},
},
}, nil
@@ -787,7 +830,20 @@ func (h *VolumeHandler) PruneVolumes(ctx context.Context, input *PruneVolumesInp
return nil, huma.Error500InternalServerError("service not available")
}
- report, err := h.volumeService.PruneVolumes(ctx)
+ var report *volumetypes.PruneReport
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ Step: "Pruning unused volumes",
+ Message: "Pruning unused volumes",
+ SuccessMessage: "Volumes pruned successfully",
+ Metadata: models.JSON{"action": "prune_volumes"},
+ }, func() error {
+ var pruneErr error
+ report, pruneErr = h.volumeService.PruneVolumes(ctx)
+ return pruneErr
+ })
if err != nil {
return nil, huma.Error500InternalServerError((&common.VolumePruneError{Err: err}).Error())
}
@@ -798,6 +854,7 @@ func (h *VolumeHandler) PruneVolumes(ctx context.Context, input *PruneVolumesInp
Data: VolumePruneReportData{
VolumesDeleted: report.VolumesDeleted,
SpaceReclaimed: report.SpaceReclaimed,
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
},
},
}, nil
@@ -954,13 +1011,30 @@ func (h *VolumeHandler) UploadFile(ctx context.Context, input *UploadFileInput)
defer func() { _ = file.Close() }()
user, _ := humamw.GetCurrentUserFromContext(ctx)
- err = h.volumeService.UploadFile(ctx, input.VolumeName, input.Path, file, fileHeader.Filename, user)
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ ResourceID: input.VolumeName,
+ ResourceName: input.VolumeName,
+ User: user,
+ Step: "Uploading file",
+ Message: "Uploading file to volume",
+ SuccessMessage: "File uploaded successfully",
+ Metadata: models.JSON{
+ "action": "upload_volume_file",
+ "path": input.Path,
+ "filename": fileHeader.Filename,
+ },
+ }, func() error {
+ return h.volumeService.UploadFile(ctx, input.VolumeName, input.Path, file, fileHeader.Filename, user)
+ })
if err != nil {
return nil, huma.Error500InternalServerError(err.Error())
}
return &base.ApiResponse[base.MessageResponse]{
Success: true,
- Data: base.MessageResponse{Message: "File uploaded successfully"},
+ Data: base.MessageResponse{Message: "File uploaded successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
}, nil
}
@@ -969,13 +1043,29 @@ func (h *VolumeHandler) CreateDirectory(ctx context.Context, input *CreateDirect
return nil, huma.Error500InternalServerError("service not available")
}
user, _ := humamw.GetCurrentUserFromContext(ctx)
- err := h.volumeService.CreateDirectory(ctx, input.VolumeName, input.Path, user)
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ ResourceID: input.VolumeName,
+ ResourceName: input.VolumeName,
+ User: user,
+ Step: "Creating directory",
+ Message: "Creating directory in volume",
+ SuccessMessage: "Directory created successfully",
+ Metadata: models.JSON{
+ "action": "create_volume_directory",
+ "path": input.Path,
+ },
+ }, func() error {
+ return h.volumeService.CreateDirectory(ctx, input.VolumeName, input.Path, user)
+ })
if err != nil {
return nil, huma.Error500InternalServerError(err.Error())
}
return &base.ApiResponse[base.MessageResponse]{
Success: true,
- Data: base.MessageResponse{Message: "Directory created successfully"},
+ Data: base.MessageResponse{Message: "Directory created successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
}, nil
}
@@ -984,13 +1074,29 @@ func (h *VolumeHandler) DeleteFile(ctx context.Context, input *DeleteFileInput)
return nil, huma.Error500InternalServerError("service not available")
}
user, _ := humamw.GetCurrentUserFromContext(ctx)
- err := h.volumeService.DeleteFile(ctx, input.VolumeName, input.Path, user)
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ ResourceID: input.VolumeName,
+ ResourceName: input.VolumeName,
+ User: user,
+ Step: "Deleting file",
+ Message: "Deleting file or directory from volume",
+ SuccessMessage: "Deleted successfully",
+ Metadata: models.JSON{
+ "action": "delete_volume_file",
+ "path": input.Path,
+ },
+ }, func() error {
+ return h.volumeService.DeleteFile(ctx, input.VolumeName, input.Path, user)
+ })
if err != nil {
return nil, huma.Error500InternalServerError(err.Error())
}
return &base.ApiResponse[base.MessageResponse]{
Success: true,
- Data: base.MessageResponse{Message: "Deleted successfully"},
+ Data: base.MessageResponse{Message: "Deleted successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
}, nil
}
@@ -1056,10 +1162,27 @@ func (h *VolumeHandler) CreateBackup(ctx context.Context, input *CreateBackupInp
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
}
- backup, err := h.volumeService.CreateBackup(ctx, input.VolumeName, *user)
+ var backup *models.VolumeBackup
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ ResourceID: input.VolumeName,
+ ResourceName: input.VolumeName,
+ User: user,
+ Step: "Creating backup",
+ Message: "Creating volume backup",
+ SuccessMessage: "Volume backup created successfully",
+ Metadata: models.JSON{"action": "create_volume_backup"},
+ }, func() error {
+ var backupErr error
+ backup, backupErr = h.volumeService.CreateBackup(ctx, input.VolumeName, *user)
+ return backupErr
+ })
if err != nil {
return nil, huma.Error500InternalServerError(err.Error())
}
+ backup.ActivityID = utils.StringPtrFromTrimmed(activityID)
return &CreateBackupOutput{
Body: base.ApiResponse[*models.VolumeBackup]{
Success: true,
@@ -1077,14 +1200,30 @@ func (h *VolumeHandler) RestoreBackup(ctx context.Context, input *RestoreBackupI
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
}
- err := h.volumeService.RestoreBackup(ctx, input.VolumeName, input.BackupID, *user)
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ ResourceID: input.VolumeName,
+ ResourceName: input.VolumeName,
+ User: user,
+ Step: "Restoring backup",
+ Message: "Restoring volume backup",
+ SuccessMessage: "Restore initiated successfully",
+ Metadata: models.JSON{
+ "action": "restore_volume_backup",
+ "backupId": input.BackupID,
+ },
+ }, func() error {
+ return h.volumeService.RestoreBackup(ctx, input.VolumeName, input.BackupID, *user)
+ })
if err != nil {
return nil, huma.Error500InternalServerError(err.Error())
}
return &RestoreBackupOutput{
Body: base.ApiResponse[base.MessageResponse]{
Success: true,
- Data: base.MessageResponse{Message: "Restore initiated successfully"},
+ Data: base.MessageResponse{Message: "Restore initiated successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
},
}, nil
}
@@ -1103,14 +1242,32 @@ func (h *VolumeHandler) RestoreBackupFiles(ctx context.Context, input *RestoreBa
return nil, huma.Error400BadRequest("paths are required")
}
- if err := h.volumeService.RestoreBackupFiles(ctx, input.VolumeName, input.BackupID, input.Body.Paths, *user); err != nil {
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ ResourceID: input.VolumeName,
+ ResourceName: input.VolumeName,
+ User: user,
+ Step: "Restoring backup files",
+ Message: "Restoring files from volume backup",
+ SuccessMessage: "Restore initiated successfully",
+ Metadata: models.JSON{
+ "action": "restore_volume_backup_files",
+ "backupId": input.BackupID,
+ "paths": input.Body.Paths,
+ },
+ }, func() error {
+ return h.volumeService.RestoreBackupFiles(ctx, input.VolumeName, input.BackupID, input.Body.Paths, *user)
+ })
+ if err != nil {
return nil, huma.Error500InternalServerError(err.Error())
}
return &RestoreBackupFilesOutput{
Body: base.ApiResponse[base.MessageResponse]{
Success: true,
- Data: base.MessageResponse{Message: "Restore initiated successfully"},
+ Data: base.MessageResponse{Message: "Restore initiated successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
},
}, nil
}
@@ -1160,14 +1317,30 @@ func (h *VolumeHandler) DeleteBackup(ctx context.Context, input *DeleteBackupInp
return nil, huma.Error500InternalServerError("service not available")
}
user, _ := humamw.GetCurrentUserFromContext(ctx)
- err := h.volumeService.DeleteBackup(ctx, input.BackupID, user)
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume_backup",
+ ResourceID: input.BackupID,
+ ResourceName: input.BackupID,
+ User: user,
+ Step: "Deleting backup",
+ Message: "Deleting volume backup",
+ SuccessMessage: "Backup deleted successfully",
+ Metadata: models.JSON{
+ "action": "delete_volume_backup",
+ "backupId": input.BackupID,
+ },
+ }, func() error {
+ return h.volumeService.DeleteBackup(ctx, input.BackupID, user)
+ })
if err != nil {
return nil, huma.Error500InternalServerError(err.Error())
}
return &DeleteBackupOutput{
Body: base.ApiResponse[base.MessageResponse]{
Success: true,
- Data: base.MessageResponse{Message: "Backup deleted successfully"},
+ Data: base.MessageResponse{Message: "Backup deleted successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
},
}, nil
}
@@ -1217,14 +1390,30 @@ func (h *VolumeHandler) UploadAndRestore(ctx context.Context, input *UploadAndRe
}
defer func() { _ = file.Close() }()
- err = h.volumeService.UploadAndRestore(ctx, input.VolumeName, file, fileHeader.Filename, *user)
+ activityID, err := activitylib.RunHandlerActivity(ctx, h.activityService, activitylib.HandlerOptions{
+ EnvironmentID: input.EnvironmentID,
+ Type: models.ActivityTypeResourceAction,
+ ResourceType: "volume",
+ ResourceID: input.VolumeName,
+ ResourceName: input.VolumeName,
+ User: user,
+ Step: "Uploading backup",
+ Message: "Uploading and restoring volume backup",
+ SuccessMessage: "Backup uploaded and restored successfully",
+ Metadata: models.JSON{
+ "action": "upload_restore_volume_backup",
+ "filename": fileHeader.Filename,
+ },
+ }, func() error {
+ return h.volumeService.UploadAndRestore(ctx, input.VolumeName, file, fileHeader.Filename, *user)
+ })
if err != nil {
return nil, huma.Error500InternalServerError(err.Error())
}
return &UploadAndRestoreOutput{
Body: base.ApiResponse[base.MessageResponse]{
Success: true,
- Data: base.MessageResponse{Message: "Backup uploaded and restored successfully"},
+ Data: base.MessageResponse{Message: "Backup uploaded and restored successfully", ActivityID: utils.StringPtrFromTrimmed(activityID)},
},
}, nil
}
diff --git a/backend/go.mod b/backend/go.mod
index 284dd7409..5e5be8a16 100644
--- a/backend/go.mod
+++ b/backend/go.mod
@@ -17,6 +17,7 @@ require (
github.com/coreos/go-oidc/v3 v3.18.0
github.com/danielgtaylor/huma/v2 v2.38.0
github.com/depot/depot-go v0.5.2
+ github.com/distribution/reference v0.6.0
github.com/docker/cli v29.5.2+incompatible
github.com/docker/compose/v5 v5.1.4
github.com/docker/go-units v0.5.0
@@ -51,7 +52,6 @@ require (
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
github.com/wneessen/go-mail v0.7.3
- go.podman.io/image/v5 v5.40.0
golang.org/x/crypto v0.52.0
golang.org/x/mod v0.36.0
golang.org/x/net v0.55.0
@@ -100,7 +100,6 @@ require (
github.com/containerd/typeurl/v2 v2.2.3 // indirect
github.com/cyphar/filepath-securejoin v0.6.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
- github.com/distribution/reference v0.6.0 // indirect
github.com/docker/buildx v0.33.0 // indirect
github.com/docker/docker v28.5.2+incompatible // indirect
github.com/docker/docker-credential-helpers v0.9.7 // indirect
@@ -125,6 +124,7 @@ require (
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.7.0 // indirect
+ github.com/google/go-containerregistry v0.21.1 // indirect
github.com/google/go-github/v39 v39.2.0 // indirect
github.com/google/go-querystring v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
@@ -197,6 +197,7 @@ require (
github.com/tonistiigi/vt100 v0.0.0-20240514184818-90bafcd6abab // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
+ github.com/vbatts/tar-split v0.12.3 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
@@ -215,7 +216,6 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.43.0 // indirect
go.opentelemetry.io/otel/trace v1.43.0 // indirect
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
- go.podman.io/storage v1.63.0 // indirect
go.yaml.in/yaml/v4 v4.0.0-rc.4 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/term v0.43.0 // indirect
diff --git a/backend/go.sum b/backend/go.sum
index 463b38ecd..f2dd72134 100644
--- a/backend/go.sum
+++ b/backend/go.sum
@@ -581,10 +581,6 @@ go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g=
go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk=
-go.podman.io/image/v5 v5.40.0 h1:gNQvj343Eb4juCitUBkuDz1T82Zpp6nhgMEXzNfCges=
-go.podman.io/image/v5 v5.40.0/go.mod h1:qgXf1abXJ+2l01pL8+CljaMKryeo6ahaHO7H51ooKIc=
-go.podman.io/storage v1.63.0 h1:bj/pAWFhChbuBmejzno0iQLhU7FevGVXepRXm5pFGeA=
-go.podman.io/storage v1.63.0/go.mod h1:z4Z9K+7GhKjWL/Y1O17+4f8a1KGijVeC9hr3tymhSOs=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
diff --git a/backend/internal/bootstrap/jobs_bootstrap.go b/backend/internal/bootstrap/jobs_bootstrap.go
index 56752020c..68cafd63e 100644
--- a/backend/internal/bootstrap/jobs_bootstrap.go
+++ b/backend/internal/bootstrap/jobs_bootstrap.go
@@ -31,7 +31,7 @@ func registerJobs(appCtx context.Context, newScheduler *pkg_scheduler.JobSchedul
// Send initial heartbeat on startup without blocking bootstrap.
go analyticsJob.Run(appCtx)
- eventCleanupJob := pkg_scheduler.NewEventCleanupJob(appServices.Event, appServices.Settings)
+ eventCleanupJob := pkg_scheduler.NewEventCleanupJob(appServices.Event, appServices.Activity, appServices.Settings)
newScheduler.RegisterJob(eventCleanupJob)
pruningVolumeHelperJob := pkg_scheduler.NewPruningVolumeHelperJob(appServices.Volume, appServices.Settings)
diff --git a/backend/internal/bootstrap/router_bootstrap.go b/backend/internal/bootstrap/router_bootstrap.go
index 460310e4c..e0177ee2c 100644
--- a/backend/internal/bootstrap/router_bootstrap.go
+++ b/backend/internal/bootstrap/router_bootstrap.go
@@ -194,6 +194,7 @@ func setupRouter(ctx context.Context, cfg *config.Config, appServices *Services)
Font: appServices.Font,
Project: appServices.Project,
Event: appServices.Event,
+ Activity: appServices.Activity,
Version: appServices.Version,
Environment: appServices.Environment,
Settings: appServices.Settings,
diff --git a/backend/internal/bootstrap/services_bootstrap.go b/backend/internal/bootstrap/services_bootstrap.go
index 18a18cb78..fb7272674 100644
--- a/backend/internal/bootstrap/services_bootstrap.go
+++ b/backend/internal/bootstrap/services_bootstrap.go
@@ -40,6 +40,7 @@ type Services struct {
SystemUpgrade *services.SystemUpgradeService
Updater *services.UpdaterService
Event *services.EventService
+ Activity *services.ActivityService
Version *services.VersionService
Notification *services.NotificationService
ApiKey *services.ApiKeyService
@@ -56,6 +57,7 @@ func initializeServices(ctx context.Context, db *database.DB, cfg *config.Config
svcs = &Services{}
svcs.Event = services.NewEventService(db, cfg, httpClient)
+ svcs.Activity = services.NewActivityService(db)
svcs.Settings, err = services.NewSettingsService(ctx, db)
if err != nil {
return nil, nil, fmt.Errorf("failed to settings service: %w", err)
@@ -78,8 +80,8 @@ func initializeServices(ctx context.Context, db *database.DB, cfg *config.Config
svcs.Environment = services.NewEnvironmentService(db, httpClient, svcs.Docker, svcs.Event, svcs.Settings, svcs.ApiKey)
svcs.Version = services.NewVersionService(httpClient, cfg.UpdateCheckDisabled, config.Version, config.Revision, svcs.ContainerRegistry, svcs.Docker)
svcs.Notification = services.NewNotificationService(db, cfg, svcs.Environment)
- svcs.Vulnerability = services.NewVulnerabilityService(db, svcs.Docker, svcs.Event, svcs.Settings, svcs.Notification)
- svcs.ImageUpdate = services.NewImageUpdateService(db, svcs.Settings, svcs.ContainerRegistry, svcs.Docker, svcs.Event, svcs.Notification)
+ svcs.Vulnerability = services.NewVulnerabilityService(db, svcs.Docker, svcs.Event, svcs.Settings, svcs.Notification, svcs.Activity)
+ svcs.ImageUpdate = services.NewImageUpdateService(db, svcs.Settings, svcs.ContainerRegistry, svcs.Docker, svcs.Event, svcs.Notification, svcs.Activity)
svcs.Image = services.NewImageService(db, svcs.Docker, svcs.ContainerRegistry, svcs.ImageUpdate, svcs.Vulnerability, svcs.Event)
svcs.GitRepository = services.NewGitRepositoryService(db, cfg.GitWorkDir, svcs.Event, svcs.Settings)
svcs.Build = services.NewBuildService(db, svcs.Settings, svcs.Docker, svcs.ContainerRegistry, svcs.GitRepository, svcs.Event)
@@ -104,9 +106,9 @@ func initializeServices(ctx context.Context, db *database.DB, cfg *config.Config
svcs.Template = services.NewTemplateService(ctx, db, httpClient, svcs.Settings)
svcs.Auth = services.NewAuthService(svcs.User, svcs.Settings, svcs.Event, svcs.Session, svcs.Role, cfg.JWTSecret, cfg)
svcs.Oidc = services.NewOidcService(svcs.Auth, svcs.Settings, cfg, httpClient)
- svcs.System = services.NewSystemService(db, svcs.Docker, svcs.Container, svcs.Image, svcs.Volume, svcs.Network, svcs.Settings)
+ svcs.System = services.NewSystemService(db, svcs.Docker, svcs.Container, svcs.Image, svcs.Volume, svcs.Network, svcs.Settings, svcs.Activity)
svcs.SystemUpgrade = services.NewSystemUpgradeService(svcs.Docker, svcs.Version, svcs.Event, svcs.Settings)
- svcs.Updater = services.NewUpdaterService(db, svcs.Settings, svcs.Docker, svcs.Project, svcs.ImageUpdate, svcs.ContainerRegistry, svcs.Event, svcs.Image, svcs.Notification, svcs.SystemUpgrade)
+ svcs.Updater = services.NewUpdaterService(db, svcs.Settings, svcs.Docker, svcs.Project, svcs.ImageUpdate, svcs.ContainerRegistry, svcs.Event, svcs.Image, svcs.Notification, svcs.SystemUpgrade, svcs.Activity)
svcs.GitOpsSync = services.NewGitOpsSyncService(db, svcs.GitRepository, svcs.Project, svcs.Swarm, svcs.Event, svcs.Settings)
svcs.Webhook = services.NewWebhookService(db, svcs.Container, svcs.Updater, svcs.Project, svcs.GitOpsSync, svcs.Event)
diff --git a/backend/internal/common/errors.go b/backend/internal/common/errors.go
index f3d504a61..229148339 100644
--- a/backend/internal/common/errors.go
+++ b/backend/internal/common/errors.go
@@ -976,14 +976,6 @@ func (e *DockerInfoError) Error() string {
return fmt.Sprintf("Failed to get Docker info: %v", e.Err)
}
-type SystemPruneError struct {
- Err error
-}
-
-func (e *SystemPruneError) Error() string {
- return fmt.Sprintf("Failed to prune resources: %v", e.Err)
-}
-
type ContainerStartAllError struct {
Err error
}
diff --git a/backend/internal/configschema/schema_test.go b/backend/internal/configschema/schema_test.go
index b5b2188b3..fd78576c7 100644
--- a/backend/internal/configschema/schema_test.go
+++ b/backend/internal/configschema/schema_test.go
@@ -263,6 +263,8 @@ var expectedEnvConfigVars = []string{
var expectedSettingOverrideKeys = []string{
"accentColor",
+ "activityHistoryMaxEntries",
+ "activityHistoryRetentionDays",
"applicationTheme",
"authLocalEnabled",
"authPasswordPolicy",
diff --git a/backend/internal/models/activity.go b/backend/internal/models/activity.go
new file mode 100644
index 000000000..31c8d4e5c
--- /dev/null
+++ b/backend/internal/models/activity.go
@@ -0,0 +1,84 @@
+package models
+
+import "time"
+
+type (
+ ActivityType string
+ ActivityStatus string
+ ActivityMessageLevel string
+)
+
+const (
+ ActivityStatusQueued ActivityStatus = "queued"
+ ActivityStatusRunning ActivityStatus = "running"
+ ActivityStatusSuccess ActivityStatus = "success"
+ ActivityStatusFailed ActivityStatus = "failed"
+ ActivityStatusCancelled ActivityStatus = "cancelled"
+)
+
+const (
+ ActivityTypeImagePull ActivityType = "image_pull"
+ ActivityTypeImageBuild ActivityType = "image_build"
+ ActivityTypeImageUpdateCheck ActivityType = "image_update_check"
+ ActivityTypeProjectPull ActivityType = "project_pull"
+ ActivityTypeProjectBuild ActivityType = "project_build"
+ ActivityTypeProjectDeploy ActivityType = "project_deploy"
+ ActivityTypeProjectRedeploy ActivityType = "project_redeploy"
+ ActivityTypeProjectDown ActivityType = "project_down"
+ ActivityTypeProjectRestart ActivityType = "project_restart"
+ ActivityTypeProjectDestroy ActivityType = "project_destroy"
+ ActivityTypeContainerStart ActivityType = "container_start"
+ ActivityTypeContainerStop ActivityType = "container_stop"
+ ActivityTypeContainerRestart ActivityType = "container_restart"
+ ActivityTypeContainerRedeploy ActivityType = "container_redeploy"
+ ActivityTypeContainerDelete ActivityType = "container_delete"
+ ActivityTypeVulnerabilityScan ActivityType = "vulnerability_scan"
+ ActivityTypeAutoUpdate ActivityType = "auto_update"
+ ActivityTypeSystemPrune ActivityType = "system_prune"
+ ActivityTypeResourceAction ActivityType = "resource_action"
+)
+
+const (
+ ActivityMessageLevelInfo ActivityMessageLevel = "info"
+ ActivityMessageLevelWarning ActivityMessageLevel = "warning"
+ ActivityMessageLevelError ActivityMessageLevel = "error"
+ ActivityMessageLevelSuccess ActivityMessageLevel = "success"
+)
+
+type Activity struct {
+ EnvironmentID string `json:"environmentId" gorm:"column:environment_id;not null;index" sortable:"true"`
+ Type ActivityType `json:"type" gorm:"column:type;not null;index" sortable:"true"`
+ Status ActivityStatus `json:"status" gorm:"column:status;not null;index" sortable:"true"`
+ ResourceType *string `json:"resourceType,omitempty" gorm:"column:resource_type;index" sortable:"true"`
+ ResourceID *string `json:"resourceId,omitempty" gorm:"column:resource_id;index"`
+ ResourceName *string `json:"resourceName,omitempty" gorm:"column:resource_name" sortable:"true"`
+ Progress *int `json:"progress,omitempty" gorm:"column:progress"`
+ Step string `json:"step,omitempty" gorm:"column:step"`
+ LatestMessage string `json:"latestMessage,omitempty" gorm:"column:latest_message"`
+ StartedByUserID *string `json:"startedByUserId,omitempty" gorm:"column:started_by_user_id;index"`
+ StartedByUsername *string `json:"startedByUsername,omitempty" gorm:"column:started_by_username"`
+ StartedByDisplayName *string `json:"startedByDisplayName,omitempty" gorm:"column:started_by_display_name"`
+ StartedAt time.Time `json:"startedAt" gorm:"column:started_at;not null" sortable:"true"`
+ EndedAt *time.Time `json:"endedAt,omitempty" gorm:"column:ended_at" sortable:"true"`
+ DurationMs *int64 `json:"durationMs,omitempty" gorm:"column:duration_ms" sortable:"true"`
+ Error *string `json:"error,omitempty" gorm:"column:error"`
+ Metadata JSON `json:"metadata,omitempty" gorm:"type:text"`
+ BaseModel
+}
+
+func (Activity) TableName() string {
+ return "activities"
+}
+
+type ActivityMessage struct {
+ ActivityID string `json:"activityId" gorm:"column:activity_id;not null;index"`
+ Level ActivityMessageLevel `json:"level" gorm:"column:level;not null"`
+ Message string `json:"message" gorm:"column:message;not null"`
+ Payload JSON `json:"payload,omitempty" gorm:"type:text"`
+ Activity *Activity `json:"-" gorm:"foreignKey:ActivityID;constraint:OnDelete:CASCADE"`
+ BaseModel
+}
+
+func (ActivityMessage) TableName() string {
+ return "activity_messages"
+}
diff --git a/backend/internal/models/settings.go b/backend/internal/models/settings.go
index 04ba32060..4731c55cd 100644
--- a/backend/internal/models/settings.go
+++ b/backend/internal/models/settings.go
@@ -89,6 +89,8 @@ type Settings struct {
DockerClientRefreshInterval SettingVariable `key:"dockerClientRefreshInterval" meta:"label=Docker Client Refresh Interval;type=cron;keywords=docker,client,refresh,daemon,api,version,reconnect,renegotiate,schedule;category=internal;description=How often to refresh the cached Docker client API version (cron expression)"`
EventCleanupInterval SettingVariable `key:"eventCleanupInterval" meta:"label=Event Cleanup Interval;type=cron;keywords=events,cleanup,retention,interval,frequency,schedule,history,logs,jobs;description=How often to delete old events (cron expression)"`
ExpiredSessionsCleanupInterval SettingVariable `key:"expiredSessionsCleanupInterval" meta:"label=Expired Sessions Cleanup Interval;type=cron;keywords=sessions,cleanup,retention,expired,revoked,interval,frequency,schedule,auth,jobs;description=How often to delete expired and old revoked sessions (cron expression)"`
+ ActivityHistoryRetentionDays SettingVariable `key:"activityHistoryRetentionDays" meta:"label=Activity History Retention;type=number;keywords=activity,history,retention,days,cleanup,background,tasks;category=activity;description=Delete completed Activity Center entries older than this many days. Set 0 to disable age-based cleanup." catmeta:"id=activity;title=Activity;icon=activity;url=/settings/activity;description=Configure Activity Center history and cleanup"`
+ ActivityHistoryMaxEntries SettingVariable `key:"activityHistoryMaxEntries" meta:"label=Activity History Limit;type=number;keywords=activity,history,limit,entries,count,cleanup,background,tasks;category=activity;description=Maximum completed Activity Center entries to keep per environment. Set 0 to disable count-based cleanup."`
AutoInjectEnv SettingVariable `key:"autoInjectEnv" meta:"label=Auto Inject Env Variables;type=boolean;keywords=auto,inject,env,environment,variables,interpolation;category=internal;description=Automatically inject project .env variables into all containers (default: false)"`
DefaultDeployPullPolicy SettingVariable `key:"defaultDeployPullPolicy" meta:"label=Default Deploy Pull Policy;type=select;keywords=deploy,pull,policy,compose,up,missing,always;category=internal;description=Default image pull policy when deploying projects"`
ScheduledPruneEnabled SettingVariable `key:"scheduledPruneEnabled" meta:"label=Scheduled Prune Enabled;type=boolean;keywords=prune,cleanup,maintenance,schedule,automatic;category=internal;description=Enable scheduled pruning of unused Docker resources"`
diff --git a/backend/internal/models/volume_backup.go b/backend/internal/models/volume_backup.go
index a4df4768a..4643ef465 100644
--- a/backend/internal/models/volume_backup.go
+++ b/backend/internal/models/volume_backup.go
@@ -11,6 +11,7 @@ type VolumeBackup struct {
VolumeName string `json:"volumeName" gorm:"column:volume_name;index"`
Size int64 `json:"size" gorm:"column:size"`
CreatedAt time.Time `json:"createdAt" gorm:"column:created_at"`
+ ActivityID *string `json:"activityId,omitempty" gorm:"-"`
}
func (*VolumeBackup) TableName() string {
diff --git a/backend/internal/services/activity_service.go b/backend/internal/services/activity_service.go
new file mode 100644
index 000000000..7cadce737
--- /dev/null
+++ b/backend/internal/services/activity_service.go
@@ -0,0 +1,719 @@
+package services
+
+import (
+ "context"
+ "fmt"
+ "log/slog"
+ "strings"
+ "sync"
+ "time"
+
+ "github.com/getarcaneapp/arcane/backend/internal/database"
+ "github.com/getarcaneapp/arcane/backend/internal/models"
+ activitylib "github.com/getarcaneapp/arcane/backend/pkg/libarcane/activity"
+ "github.com/getarcaneapp/arcane/backend/pkg/pagination"
+ "github.com/getarcaneapp/arcane/backend/pkg/utils"
+ activitytypes "github.com/getarcaneapp/arcane/types/activity"
+ "gorm.io/gorm"
+)
+
+const (
+ defaultActivityRetentionDays = 30
+ defaultActivityHistoryLimit = 1000
+ defaultActivityMessages = 500
+)
+
+type ActivityService struct {
+ db *database.DB
+
+ subscribersMu sync.RWMutex
+ subscribers map[int]*activitySubscriber
+ nextSubID int
+}
+
+type activitySubscriber struct {
+ environmentID string
+ ch chan activitytypes.StreamEvent
+ missedEvents bool
+}
+
+type StartActivityRequest = activitylib.StartRequest
+type UpdateActivityRequest = activitylib.UpdateRequest
+type AppendActivityMessageRequest = activitylib.AppendMessageRequest
+
+func NewActivityService(db *database.DB) *ActivityService {
+ return &ActivityService{
+ db: db,
+ subscribers: map[int]*activitySubscriber{},
+ }
+}
+
+func (s *ActivityService) checkInitInternal() error {
+ if s == nil || s.db == nil {
+ return fmt.Errorf("activity service not initialized")
+ }
+ return nil
+}
+
+func (s *ActivityService) StartActivity(ctx context.Context, req StartActivityRequest) (*activitytypes.Activity, error) {
+ if err := s.checkInitInternal(); err != nil {
+ return nil, err
+ }
+
+ now := time.Now()
+ environmentID := strings.TrimSpace(req.EnvironmentID)
+ if environmentID == "" {
+ environmentID = "0"
+ }
+
+ var startedByUserID, startedByUsername, startedByDisplayName *string
+ if req.StartedBy != nil {
+ startedByUserID = utils.StringPtrFromTrimmed(req.StartedBy.ID)
+ startedByUsername = utils.StringPtrFromTrimmed(req.StartedBy.Username)
+ if req.StartedBy.DisplayName != nil {
+ startedByDisplayName = utils.StringPtrFromTrimmed(*req.StartedBy.DisplayName)
+ }
+ }
+
+ model := &models.Activity{
+ EnvironmentID: environmentID,
+ Type: req.Type,
+ Status: models.ActivityStatusRunning,
+ ResourceType: copyPtrInternal(req.ResourceType),
+ ResourceID: copyPtrInternal(req.ResourceID),
+ ResourceName: copyPtrInternal(req.ResourceName),
+ StartedByUserID: startedByUserID,
+ StartedByUsername: startedByUsername,
+ StartedByDisplayName: startedByDisplayName,
+ Progress: clampProgressPtrInternal(req.Progress),
+ Step: strings.TrimSpace(req.Step),
+ LatestMessage: strings.TrimSpace(req.LatestMessage),
+ StartedAt: now,
+ Metadata: cloneJSONInternal(req.Metadata),
+ BaseModel: models.BaseModel{
+ CreatedAt: now,
+ },
+ }
+ if model.Type == "" {
+ model.Type = models.ActivityTypeAutoUpdate
+ }
+
+ if err := s.db.WithContext(ctx).Create(model).Error; err != nil {
+ return nil, fmt.Errorf("failed to create activity: %w", err)
+ }
+
+ dto := activityToDTOInternal(model)
+ s.publishActivityInternal(dto)
+ return &dto, nil
+}
+
+func (s *ActivityService) UpdateActivity(ctx context.Context, activityID string, req UpdateActivityRequest) (*activitytypes.Activity, error) {
+ if err := s.checkInitInternal(); err != nil {
+ return nil, err
+ }
+ activityID = strings.TrimSpace(activityID)
+ if activityID == "" {
+ return nil, fmt.Errorf("activity id is required")
+ }
+
+ updates := map[string]any{
+ "updated_at": time.Now(),
+ }
+ if req.Status != "" {
+ updates["status"] = req.Status
+ }
+ if req.Progress != nil {
+ updates["progress"] = *clampProgressPtrInternal(req.Progress)
+ }
+ if req.Step != nil {
+ updates["step"] = strings.TrimSpace(*req.Step)
+ }
+ if req.LatestMessage != nil {
+ updates["latest_message"] = strings.TrimSpace(*req.LatestMessage)
+ }
+ if req.Error != nil {
+ updates["error"] = strings.TrimSpace(*req.Error)
+ }
+ if req.Metadata != nil {
+ updates["metadata"] = cloneJSONInternal(req.Metadata)
+ }
+
+ var model models.Activity
+ if err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
+ result := tx.Model(&models.Activity{}).Where("id = ?", activityID).Updates(updates)
+ if result.Error != nil {
+ return fmt.Errorf("failed to update activity: %w", result.Error)
+ }
+ if result.RowsAffected == 0 {
+ return fmt.Errorf("activity not found")
+ }
+ if err := tx.First(&model, "id = ?", activityID).Error; err != nil {
+ return fmt.Errorf("failed to load updated activity: %w", err)
+ }
+ return nil
+ }); err != nil {
+ return nil, err
+ }
+
+ dto := activityToDTOInternal(&model)
+ s.publishActivityInternal(dto)
+ return &dto, nil
+}
+
+func (s *ActivityService) AppendMessage(ctx context.Context, activityID string, req AppendActivityMessageRequest) (*activitytypes.Message, error) {
+ if err := s.checkInitInternal(); err != nil {
+ return nil, err
+ }
+ activityID = strings.TrimSpace(activityID)
+ if activityID == "" {
+ return nil, fmt.Errorf("activity id is required")
+ }
+
+ messageText := strings.TrimSpace(req.Message)
+ if messageText == "" {
+ return nil, nil
+ }
+ if len(messageText) > 8192 {
+ messageText = messageText[:8192]
+ }
+
+ level := req.Level
+ if level == "" {
+ level = models.ActivityMessageLevelInfo
+ }
+
+ now := time.Now()
+ message := &models.ActivityMessage{
+ ActivityID: activityID,
+ Level: level,
+ Message: messageText,
+ Payload: cloneJSONInternal(req.Payload),
+ BaseModel: models.BaseModel{
+ CreatedAt: now,
+ },
+ }
+
+ var updated models.Activity
+ if err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
+ if err := tx.Create(message).Error; err != nil {
+ return fmt.Errorf("failed to append activity message: %w", err)
+ }
+
+ updates := map[string]any{
+ "latest_message": messageText,
+ "updated_at": now,
+ }
+ if req.Progress != nil {
+ updates["progress"] = *clampProgressPtrInternal(req.Progress)
+ }
+ if strings.TrimSpace(req.Step) != "" {
+ updates["step"] = strings.TrimSpace(req.Step)
+ }
+
+ result := tx.Model(&models.Activity{}).Where("id = ?", activityID).Updates(updates)
+ if result.Error != nil {
+ return fmt.Errorf("failed to update activity latest message: %w", result.Error)
+ }
+ if result.RowsAffected == 0 {
+ return fmt.Errorf("activity not found")
+ }
+ if err := tx.First(&updated, "id = ?", activityID).Error; err != nil {
+ return fmt.Errorf("failed to load updated activity: %w", err)
+ }
+ return nil
+ }); err != nil {
+ return nil, err
+ }
+
+ dto := activityMessageToDTOInternal(message)
+ s.publishMessageInternal(updated.EnvironmentID, dto)
+ s.publishActivityInternal(activityToDTOInternal(&updated))
+ return &dto, nil
+}
+
+func (s *ActivityService) CompleteActivity(ctx context.Context, activityID string, status models.ActivityStatus, finalMessage string, errMessage *string, finalStep ...string) (*activitytypes.Activity, error) {
+ if err := s.checkInitInternal(); err != nil {
+ return nil, err
+ }
+ if status == "" {
+ status = models.ActivityStatusSuccess
+ }
+ if status != models.ActivityStatusSuccess && status != models.ActivityStatusFailed && status != models.ActivityStatusCancelled {
+ status = models.ActivityStatusSuccess
+ }
+
+ activityID = strings.TrimSpace(activityID)
+ if activityID == "" {
+ return nil, fmt.Errorf("activity id is required")
+ }
+
+ now := time.Now()
+ var model models.Activity
+ if err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
+ if err := tx.First(&model, "id = ?", activityID).Error; err != nil {
+ return fmt.Errorf("failed to load activity: %w", err)
+ }
+
+ updates := completeActivityUpdatesInternal(model.StartedAt, status, finalMessage, errMessage, finalStep, now)
+ if err := tx.Model(&models.Activity{}).Where("id = ?", activityID).Updates(updates).Error; err != nil {
+ return fmt.Errorf("failed to complete activity: %w", err)
+ }
+ if err := tx.First(&model, "id = ?", activityID).Error; err != nil {
+ return fmt.Errorf("failed to load completed activity: %w", err)
+ }
+ return nil
+ }); err != nil {
+ return nil, err
+ }
+
+ if strings.TrimSpace(finalMessage) != "" {
+ level := models.ActivityMessageLevelSuccess
+ switch status {
+ case models.ActivityStatusFailed:
+ level = models.ActivityMessageLevelError
+ case models.ActivityStatusCancelled:
+ level = models.ActivityMessageLevelWarning
+ case models.ActivityStatusQueued, models.ActivityStatusRunning, models.ActivityStatusSuccess:
+ }
+ if _, err := s.AppendMessage(context.WithoutCancel(ctx), activityID, AppendActivityMessageRequest{
+ Level: level,
+ Message: finalMessage,
+ }); err != nil {
+ slog.DebugContext(ctx, "failed to append final activity message", "activityId", activityID, "error", err)
+ }
+ if err := s.db.WithContext(context.WithoutCancel(ctx)).First(&model, "id = ?", activityID).Error; err != nil {
+ slog.DebugContext(ctx, "failed to reload activity after appending message", "activityId", activityID, "error", err)
+ }
+ }
+
+ dto := activityToDTOInternal(&model)
+ s.publishActivityInternal(dto)
+ return &dto, nil
+}
+
+func completeActivityUpdatesInternal(startedAt time.Time, status models.ActivityStatus, finalMessage string, errMessage *string, finalStep []string, now time.Time) map[string]any {
+ updates := map[string]any{
+ "status": status,
+ "ended_at": now,
+ "duration_ms": now.Sub(startedAt).Milliseconds(),
+ "updated_at": now,
+ }
+ if trimmed := strings.TrimSpace(finalMessage); trimmed != "" {
+ updates["latest_message"] = trimmed
+ }
+ if len(finalStep) > 0 {
+ if step := strings.TrimSpace(finalStep[0]); step != "" {
+ updates["step"] = step
+ }
+ }
+ if errMessage != nil && strings.TrimSpace(*errMessage) != "" {
+ updates["error"] = strings.TrimSpace(*errMessage)
+ }
+ if status == models.ActivityStatusSuccess {
+ updates["progress"] = 100
+ }
+ return updates
+}
+
+func (s *ActivityService) ListActivitiesPaginated(ctx context.Context, environmentID string, params pagination.QueryParams) ([]activitytypes.Activity, pagination.Response, error) {
+ if err := s.checkInitInternal(); err != nil {
+ return nil, pagination.Response{}, err
+ }
+
+ environmentID = strings.TrimSpace(environmentID)
+ if environmentID == "" {
+ environmentID = "0"
+ }
+
+ var activities []models.Activity
+ q := s.db.WithContext(ctx).Model(&models.Activity{}).Where("environment_id = ?", environmentID)
+
+ if term := strings.TrimSpace(params.Search); term != "" {
+ escaped := strings.NewReplacer(`\`, `\\`, `%`, `\%`, `_`, `\_`).Replace(term)
+ searchPattern := "%" + escaped + "%"
+ q = q.Where(
+ "type LIKE ? ESCAPE '\\' OR COALESCE(resource_name, '') LIKE ? ESCAPE '\\' OR COALESCE(latest_message, '') LIKE ? ESCAPE '\\' OR COALESCE(step, '') LIKE ? ESCAPE '\\' OR COALESCE(error, '') LIKE ? ESCAPE '\\'",
+ searchPattern, searchPattern, searchPattern, searchPattern, searchPattern,
+ )
+ }
+
+ q = pagination.ApplyFilter(q, "status", params.Filters["status"])
+ q = pagination.ApplyFilter(q, "type", params.Filters["type"])
+ q = pagination.ApplyFilter(q, "resource_type", params.Filters["resourceType"])
+
+ if params.Sort == "" {
+ q = q.Order("CASE WHEN status IN ('queued', 'running') THEN 0 ELSE 1 END ASC").
+ Order("COALESCE(updated_at, created_at) DESC").
+ Order("started_at DESC")
+ }
+
+ paginationResp, err := pagination.PaginateAndSortDB(params, q, &activities)
+ if err != nil {
+ return nil, pagination.Response{}, fmt.Errorf("failed to paginate activities: %w", err)
+ }
+
+ out := make([]activitytypes.Activity, 0, len(activities))
+ for i := range activities {
+ out = append(out, activityToDTOInternal(&activities[i]))
+ }
+ return out, paginationResp, nil
+}
+
+func (s *ActivityService) GetActivityDetail(ctx context.Context, environmentID, activityID string, limit int) (*activitytypes.Detail, error) {
+ if err := s.checkInitInternal(); err != nil {
+ return nil, err
+ }
+ if limit <= 0 || limit > defaultActivityMessages {
+ limit = defaultActivityMessages
+ }
+
+ var model models.Activity
+ if err := s.db.WithContext(ctx).
+ Where("id = ? AND environment_id = ?", activityID, environmentID).
+ First(&model).Error; err != nil {
+ return nil, fmt.Errorf("failed to load activity: %w", err)
+ }
+
+ var messages []models.ActivityMessage
+ if err := s.db.WithContext(ctx).
+ Where("activity_id = ?", activityID).
+ Order("created_at DESC").
+ Limit(limit).
+ Find(&messages).Error; err != nil {
+ return nil, fmt.Errorf("failed to load activity messages: %w", err)
+ }
+
+ outMessages := make([]activitytypes.Message, 0, len(messages))
+ for i := len(messages) - 1; i >= 0; i-- {
+ outMessages = append(outMessages, activityMessageToDTOInternal(&messages[i]))
+ }
+
+ return &activitytypes.Detail{
+ Activity: activityToDTOInternal(&model),
+ Messages: outMessages,
+ }, nil
+}
+
+func (s *ActivityService) PruneHistory(ctx context.Context, retentionDays, maxEntries int) (int64, error) {
+ if s == nil || s.db == nil {
+ return 0, nil
+ }
+ if retentionDays < 0 {
+ retentionDays = defaultActivityRetentionDays
+ }
+ if maxEntries < 0 {
+ maxEntries = defaultActivityHistoryLimit
+ }
+
+ var deleted int64
+ if err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
+ if retentionDays > 0 {
+ cutoff := time.Now().Add(-time.Duration(retentionDays) * 24 * time.Hour)
+ ids, err := findTerminalActivityIDsInternal(tx.
+ Where("COALESCE(ended_at, updated_at, created_at) < ?", cutoff))
+ if err != nil {
+ return fmt.Errorf("failed to find activities older than retention window: %w", err)
+ }
+ count, err := deleteActivitiesByIDInternal(tx, ids)
+ if err != nil {
+ return err
+ }
+ deleted += count
+ }
+
+ if maxEntries > 0 {
+ ids, err := findActivityIDsBeyondHistoryLimitInternal(tx, maxEntries)
+ if err != nil {
+ return err
+ }
+ count, err := deleteActivitiesByIDInternal(tx, ids)
+ if err != nil {
+ return err
+ }
+ deleted += count
+ }
+
+ return nil
+ }); err != nil {
+ return 0, err
+ }
+
+ return deleted, nil
+}
+
+func (s *ActivityService) DeleteHistory(ctx context.Context, environmentID string) (int64, error) {
+ if s == nil || s.db == nil {
+ return 0, nil
+ }
+
+ environmentID = strings.TrimSpace(environmentID)
+ if environmentID == "" {
+ environmentID = "0"
+ }
+
+ var deleted int64
+ if err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
+ ids, err := findTerminalActivityIDsInternal(tx.Where("environment_id = ?", environmentID))
+ if err != nil {
+ return fmt.Errorf("failed to find activity history: %w", err)
+ }
+ count, err := deleteActivitiesByIDInternal(tx, ids)
+ if err != nil {
+ return err
+ }
+ deleted = count
+ return nil
+ }); err != nil {
+ return 0, err
+ }
+
+ return deleted, nil
+}
+
+func (s *ActivityService) Subscribe(environmentID string) (<-chan activitytypes.StreamEvent, func() bool, func()) {
+ ch := make(chan activitytypes.StreamEvent, 64)
+ if s == nil {
+ close(ch)
+ return ch, func() bool { return false }, func() {}
+ }
+
+ environmentID = strings.TrimSpace(environmentID)
+ if environmentID == "" {
+ environmentID = "0"
+ }
+
+ s.subscribersMu.Lock()
+ s.nextSubID++
+ id := s.nextSubID
+ s.subscribers[id] = &activitySubscriber{environmentID: environmentID, ch: ch}
+ s.subscribersMu.Unlock()
+
+ missedEvents := func() bool {
+ s.subscribersMu.Lock()
+ defer s.subscribersMu.Unlock()
+
+ sub, ok := s.subscribers[id]
+ if !ok || !sub.missedEvents {
+ return false
+ }
+ sub.missedEvents = false
+ return true
+ }
+
+ unsubscribe := func() {
+ s.subscribersMu.Lock()
+ if sub, ok := s.subscribers[id]; ok {
+ delete(s.subscribers, id)
+ close(sub.ch)
+ }
+ s.subscribersMu.Unlock()
+ }
+
+ return ch, missedEvents, unsubscribe
+}
+
+func (s *ActivityService) publishActivityInternal(activity activitytypes.Activity) {
+ s.publishInternal(activity.EnvironmentID, activitytypes.StreamEvent{
+ Type: "activity",
+ ActivityID: activity.ID,
+ Activity: &activity,
+ Timestamp: time.Now(),
+ })
+}
+
+func (s *ActivityService) publishMessageInternal(environmentID string, message activitytypes.Message) {
+ s.publishInternal(environmentID, activitytypes.StreamEvent{
+ Type: "message",
+ ActivityID: message.ActivityID,
+ Message: &message,
+ Timestamp: time.Now(),
+ })
+}
+
+func (s *ActivityService) publishInternal(environmentID string, event activitytypes.StreamEvent) {
+ if s == nil {
+ return
+ }
+ s.subscribersMu.Lock()
+ defer s.subscribersMu.Unlock()
+
+ for _, sub := range s.subscribers {
+ if sub.environmentID != environmentID {
+ continue
+ }
+ select {
+ case sub.ch <- event:
+ default:
+ sub.missedEvents = true
+ slog.Warn("activity subscriber event buffer full; snapshot will be sent on next heartbeat", "environmentId", environmentID, "eventType", event.Type)
+ }
+ }
+}
+
+func activityToDTOInternal(model *models.Activity) activitytypes.Activity {
+ if model == nil {
+ return activitytypes.Activity{}
+ }
+ return activitytypes.Activity{
+ ID: model.ID,
+ EnvironmentID: model.EnvironmentID,
+ SourceEnvironmentID: model.EnvironmentID,
+ Type: activitytypes.Type(model.Type),
+ Status: activitytypes.Status(model.Status),
+ ResourceType: copyPtrInternal(model.ResourceType),
+ ResourceID: copyPtrInternal(model.ResourceID),
+ ResourceName: copyPtrInternal(model.ResourceName),
+ Progress: clampProgressPtrInternal(model.Progress),
+ Step: model.Step,
+ LatestMessage: model.LatestMessage,
+ StartedBy: activityStartedByDTOInternal(model),
+ StartedAt: model.StartedAt,
+ EndedAt: copyPtrInternal(model.EndedAt),
+ DurationMs: copyPtrInternal(model.DurationMs),
+ Error: copyPtrInternal(model.Error),
+ Metadata: jsonToMapInternal(model.Metadata),
+ CreatedAt: model.CreatedAt,
+ UpdatedAt: copyPtrInternal(model.UpdatedAt),
+ }
+}
+
+func activityMessageToDTOInternal(model *models.ActivityMessage) activitytypes.Message {
+ if model == nil {
+ return activitytypes.Message{}
+ }
+ return activitytypes.Message{
+ ID: model.ID,
+ ActivityID: model.ActivityID,
+ Level: activitytypes.MessageLevel(model.Level),
+ Message: model.Message,
+ Payload: jsonToMapInternal(model.Payload),
+ CreatedAt: model.CreatedAt,
+ }
+}
+
+func copyPtrInternal[T any](value *T) *T {
+ if value == nil {
+ return nil
+ }
+ out := *value
+ return &out
+}
+
+func clampProgressPtrInternal(value *int) *int {
+ if value == nil {
+ return nil
+ }
+ clamped := *value
+ if clamped < 0 {
+ clamped = 0
+ }
+ if clamped > 100 {
+ clamped = 100
+ }
+ return &clamped
+}
+
+func cloneJSONInternal(input models.JSON) models.JSON {
+ if len(input) == 0 {
+ return nil
+ }
+ out := make(models.JSON, len(input))
+ for key, value := range input {
+ out[key] = value
+ }
+ return out
+}
+
+func jsonToMapInternal(input models.JSON) map[string]any {
+ if len(input) == 0 {
+ return nil
+ }
+ out := make(map[string]any, len(input))
+ for key, value := range input {
+ out[key] = value
+ }
+ return out
+}
+
+func terminalActivityStatusesInternal() []models.ActivityStatus {
+ return []models.ActivityStatus{
+ models.ActivityStatusSuccess,
+ models.ActivityStatusFailed,
+ models.ActivityStatusCancelled,
+ }
+}
+
+func findTerminalActivityIDsInternal(q *gorm.DB) ([]string, error) {
+ var activityIDs []string
+ if err := q.Model(&models.Activity{}).
+ Where("status IN ?", terminalActivityStatusesInternal()).
+ Pluck("id", &activityIDs).Error; err != nil {
+ return nil, err
+ }
+ return activityIDs, nil
+}
+
+func findActivityIDsBeyondHistoryLimitInternal(tx *gorm.DB, maxEntries int) ([]string, error) {
+ var activityIDs []string
+ if err := tx.Raw(`
+ SELECT ranked.id
+ FROM (
+ SELECT id,
+ ROW_NUMBER() OVER (
+ PARTITION BY environment_id
+ ORDER BY COALESCE(ended_at, updated_at, created_at) DESC, started_at DESC
+ ) AS activity_rank
+ FROM activities
+ WHERE status IN ?
+ ) ranked
+ WHERE ranked.activity_rank > ?
+ `, terminalActivityStatusesInternal(), maxEntries).Scan(&activityIDs).Error; err != nil {
+ return nil, fmt.Errorf("failed to find excess activities: %w", err)
+ }
+ return activityIDs, nil
+}
+
+const deleteActivitiesBatchSize = 500
+
+func deleteActivitiesByIDInternal(tx *gorm.DB, activityIDs []string) (int64, error) {
+ if len(activityIDs) == 0 {
+ return 0, nil
+ }
+
+ var totalDeleted int64
+ for i := 0; i < len(activityIDs); i += deleteActivitiesBatchSize {
+ end := i + deleteActivitiesBatchSize
+ if end > len(activityIDs) {
+ end = len(activityIDs)
+ }
+ batch := activityIDs[i:end]
+
+ if err := tx.Where("activity_id IN ?", batch).Delete(&models.ActivityMessage{}).Error; err != nil {
+ return totalDeleted, fmt.Errorf("failed to delete activity messages: %w", err)
+ }
+ result := tx.Where("id IN ?", batch).Delete(&models.Activity{})
+ if result.Error != nil {
+ return totalDeleted, fmt.Errorf("failed to delete activities: %w", result.Error)
+ }
+ totalDeleted += result.RowsAffected
+ }
+
+ return totalDeleted, nil
+}
+
+func activityStartedByDTOInternal(model *models.Activity) *activitytypes.StartedBy {
+ if model.StartedByUsername == nil || strings.TrimSpace(*model.StartedByUsername) == "" {
+ return &activitytypes.StartedBy{Username: "System"}
+ }
+
+ startedBy := &activitytypes.StartedBy{
+ Username: strings.TrimSpace(*model.StartedByUsername),
+ }
+ if model.StartedByUserID != nil {
+ startedBy.UserID = strings.TrimSpace(*model.StartedByUserID)
+ }
+ if model.StartedByDisplayName != nil {
+ startedBy.DisplayName = strings.TrimSpace(*model.StartedByDisplayName)
+ }
+ return startedBy
+}
diff --git a/backend/internal/services/activity_service_test.go b/backend/internal/services/activity_service_test.go
new file mode 100644
index 000000000..9554fdef4
--- /dev/null
+++ b/backend/internal/services/activity_service_test.go
@@ -0,0 +1,302 @@
+package services
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ glsqlite "github.com/glebarez/sqlite"
+ "github.com/stretchr/testify/require"
+ "gorm.io/gorm"
+
+ "github.com/getarcaneapp/arcane/backend/internal/database"
+ "github.com/getarcaneapp/arcane/backend/internal/models"
+ "github.com/getarcaneapp/arcane/backend/pkg/pagination"
+ activitytypes "github.com/getarcaneapp/arcane/types/activity"
+)
+
+func setupActivityServiceTestDBInternal(t *testing.T) *database.DB {
+ t.Helper()
+
+ db, err := gorm.Open(glsqlite.Open(":memory:"), &gorm.Config{})
+ require.NoError(t, err)
+ require.NoError(t, db.AutoMigrate(&models.Activity{}, &models.ActivityMessage{}))
+ return &database.DB{DB: db}
+}
+
+func TestActivityServiceLifecycleInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityServiceTestDBInternal(t)
+ service := NewActivityService(db)
+
+ resourceType := "image"
+ resourceID := "img-123"
+ resourceName := "nginx:latest"
+ progress := 5
+ displayName := "Arcane Admin"
+ startedBy := &models.User{
+ BaseModel: models.BaseModel{ID: "user-1"},
+ Username: "arcane",
+ DisplayName: &displayName,
+ }
+ created, err := service.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: "0",
+ Type: models.ActivityTypeImagePull,
+ ResourceType: &resourceType,
+ ResourceID: &resourceID,
+ ResourceName: &resourceName,
+ StartedBy: startedBy,
+ Progress: &progress,
+ Step: "queued",
+ LatestMessage: "Pull queued",
+ })
+ require.NoError(t, err)
+ require.NotEmpty(t, created.ID)
+ require.Equal(t, "0", created.EnvironmentID)
+ require.Equal(t, "running", string(created.Status))
+ require.Equal(t, 5, *created.Progress)
+ require.NotNil(t, created.StartedBy)
+ require.Equal(t, "user-1", created.StartedBy.UserID)
+ require.Equal(t, "arcane", created.StartedBy.Username)
+ require.Equal(t, "Arcane Admin", created.StartedBy.DisplayName)
+
+ progress = 42
+ message, err := service.AppendMessage(ctx, created.ID, AppendActivityMessageRequest{
+ Level: models.ActivityMessageLevelInfo,
+ Message: "Downloading layers",
+ Progress: &progress,
+ Step: "download",
+ })
+ require.NoError(t, err)
+ require.NotNil(t, message)
+ require.Equal(t, created.ID, message.ActivityID)
+
+ completed, err := service.CompleteActivity(ctx, created.ID, models.ActivityStatusSuccess, "Pull complete", nil)
+ require.NoError(t, err)
+ require.Equal(t, "success", string(completed.Status))
+ require.NotNil(t, completed.EndedAt)
+ require.NotNil(t, completed.DurationMs)
+ require.Equal(t, 100, *completed.Progress)
+
+ list, paginationResp, err := service.ListActivitiesPaginated(ctx, "0", pagination.QueryParams{
+ PaginationParams: pagination.PaginationParams{Limit: 10},
+ })
+ require.NoError(t, err)
+ require.Len(t, list, 1)
+ require.Equal(t, int64(1), paginationResp.TotalItems)
+ require.Equal(t, created.ID, list[0].ID)
+
+ detail, err := service.GetActivityDetail(ctx, "0", created.ID, 10)
+ require.NoError(t, err)
+ require.Equal(t, created.ID, detail.Activity.ID)
+ require.Len(t, detail.Messages, 2)
+ require.Equal(t, "Downloading layers", detail.Messages[0].Message)
+ require.Equal(t, "Pull complete", detail.Messages[1].Message)
+}
+
+func TestActivityServiceStreamFanoutInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityServiceTestDBInternal(t)
+ service := NewActivityService(db)
+
+ events, _, unsubscribe := service.Subscribe("0")
+ defer unsubscribe()
+
+ created, err := service.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: "0",
+ Type: models.ActivityTypeProjectDeploy,
+ LatestMessage: "Deploy queued",
+ })
+ require.NoError(t, err)
+
+ first := receiveActivityEventInternal(t, events)
+ require.Equal(t, "activity", first.Type)
+ require.Equal(t, created.ID, first.ActivityID)
+ require.NotNil(t, first.Activity)
+
+ _, err = service.AppendMessage(ctx, created.ID, AppendActivityMessageRequest{
+ Level: models.ActivityMessageLevelInfo,
+ Message: "Deploying services",
+ Step: "deploy",
+ })
+ require.NoError(t, err)
+
+ messageEvent := receiveActivityEventInternal(t, events)
+ require.Equal(t, "message", messageEvent.Type)
+ require.Equal(t, created.ID, messageEvent.ActivityID)
+ require.NotNil(t, messageEvent.Message)
+ require.Equal(t, "Deploying services", messageEvent.Message.Message)
+}
+
+func TestActivityServiceRetentionCleanupInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityServiceTestDBInternal(t)
+ service := NewActivityService(db)
+
+ created, err := service.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: "0",
+ Type: models.ActivityTypeSystemPrune,
+ LatestMessage: "Prune started",
+ })
+ require.NoError(t, err)
+ _, err = service.AppendMessage(ctx, created.ID, AppendActivityMessageRequest{
+ Message: "Removing unused resources",
+ })
+ require.NoError(t, err)
+ _, err = service.CompleteActivity(ctx, created.ID, models.ActivityStatusSuccess, "Prune complete", nil)
+ require.NoError(t, err)
+
+ oldEndedAt := time.Now().Add(-((time.Duration(defaultActivityRetentionDays) * 24 * time.Hour) + time.Hour))
+ require.NoError(t, db.Model(&models.Activity{}).Where("id = ?", created.ID).Update("ended_at", oldEndedAt).Error)
+
+ deleted, err := service.PruneHistory(ctx, defaultActivityRetentionDays, 0)
+ require.NoError(t, err)
+ require.EqualValues(t, 1, deleted)
+
+ var activityCount int64
+ require.NoError(t, db.Model(&models.Activity{}).Count(&activityCount).Error)
+ require.Zero(t, activityCount)
+
+ var messageCount int64
+ require.NoError(t, db.Model(&models.ActivityMessage{}).Count(&messageCount).Error)
+ require.Zero(t, messageCount)
+}
+
+func TestActivityServicePruneHistoryZeroRetentionDisablesAgeCleanupInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityServiceTestDBInternal(t)
+ service := NewActivityService(db)
+
+ created, err := service.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: "0",
+ Type: models.ActivityTypeSystemPrune,
+ LatestMessage: "Prune started",
+ })
+ require.NoError(t, err)
+ _, err = service.CompleteActivity(ctx, created.ID, models.ActivityStatusSuccess, "Prune complete", nil)
+ require.NoError(t, err)
+
+ oldEndedAt := time.Now().Add(-((time.Duration(defaultActivityRetentionDays) * 24 * time.Hour) + time.Hour))
+ require.NoError(t, db.Model(&models.Activity{}).Where("id = ?", created.ID).Update("ended_at", oldEndedAt).Error)
+
+ deleted, err := service.PruneHistory(ctx, 0, 0)
+ require.NoError(t, err)
+ require.Zero(t, deleted)
+
+ var activityCount int64
+ require.NoError(t, db.Model(&models.Activity{}).Where("id = ?", created.ID).Count(&activityCount).Error)
+ require.EqualValues(t, 1, activityCount)
+}
+
+func TestActivityServiceSubscribeMarksMissedEventsWhenBufferFullInternal(t *testing.T) {
+ service := NewActivityService(nil)
+
+ events, missedEvents, unsubscribe := service.Subscribe("0")
+ defer unsubscribe()
+
+ for i := 0; i < cap(events); i++ {
+ service.publishInternal("0", activitytypes.StreamEvent{Type: "activity"})
+ }
+ require.False(t, missedEvents())
+
+ service.publishInternal("0", activitytypes.StreamEvent{Type: "activity"})
+ require.True(t, missedEvents())
+ require.False(t, missedEvents())
+}
+
+func TestActivityServiceDeleteHistoryPreservesActiveActivitiesInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityServiceTestDBInternal(t)
+ service := NewActivityService(db)
+
+ completed, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
+ require.NoError(t, err)
+ _, err = service.AppendMessage(ctx, completed.ID, AppendActivityMessageRequest{Message: "done"})
+ require.NoError(t, err)
+ _, err = service.CompleteActivity(ctx, completed.ID, models.ActivityStatusSuccess, "complete", nil)
+ require.NoError(t, err)
+
+ running, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
+ require.NoError(t, err)
+
+ remoteCompleted, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "remote-1", Type: models.ActivityTypeResourceAction})
+ require.NoError(t, err)
+ _, err = service.CompleteActivity(ctx, remoteCompleted.ID, models.ActivityStatusFailed, "failed", nil)
+ require.NoError(t, err)
+
+ deleted, err := service.DeleteHistory(ctx, "0")
+ require.NoError(t, err)
+ require.EqualValues(t, 1, deleted)
+
+ var remaining []models.Activity
+ require.NoError(t, db.Order("id").Find(&remaining).Error)
+ require.Len(t, remaining, 2)
+ require.ElementsMatch(t, []string{running.ID, remoteCompleted.ID}, []string{remaining[0].ID, remaining[1].ID})
+}
+
+func TestActivityServicePruneHistoryByAgeAndCountInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityServiceTestDBInternal(t)
+ service := NewActivityService(db)
+
+ oldActivity, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
+ require.NoError(t, err)
+ _, err = service.CompleteActivity(ctx, oldActivity.ID, models.ActivityStatusSuccess, "old", nil)
+ require.NoError(t, err)
+ oldTime := time.Now().Add(-48 * time.Hour)
+ require.NoError(t, db.Model(&models.Activity{}).Where("id = ?", oldActivity.ID).Updates(map[string]any{
+ "ended_at": oldTime,
+ "updated_at": oldTime,
+ }).Error)
+
+ for i := 0; i < 3; i++ {
+ item, startErr := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "remote-1", Type: models.ActivityTypeResourceAction})
+ require.NoError(t, startErr)
+ _, completeErr := service.CompleteActivity(ctx, item.ID, models.ActivityStatusSuccess, "done", nil)
+ require.NoError(t, completeErr)
+ stamp := time.Now().Add(time.Duration(i) * time.Minute)
+ require.NoError(t, db.Model(&models.Activity{}).Where("id = ?", item.ID).Updates(map[string]any{
+ "ended_at": stamp,
+ "updated_at": stamp,
+ }).Error)
+ }
+
+ running, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "remote-1", Type: models.ActivityTypeResourceAction})
+ require.NoError(t, err)
+
+ deleted, err := service.PruneHistory(ctx, 1, 2)
+ require.NoError(t, err)
+ require.EqualValues(t, 2, deleted)
+
+ var terminalRemoteCount int64
+ require.NoError(t, db.Model(&models.Activity{}).
+ Where("environment_id = ? AND status IN ?", "remote-1", terminalActivityStatusesInternal()).
+ Count(&terminalRemoteCount).Error)
+ require.EqualValues(t, 2, terminalRemoteCount)
+
+ var runningCount int64
+ require.NoError(t, db.Model(&models.Activity{}).Where("id = ?", running.ID).Count(&runningCount).Error)
+ require.EqualValues(t, 1, runningCount)
+
+ var oldCount int64
+ require.NoError(t, db.Model(&models.Activity{}).Where("id = ?", oldActivity.ID).Count(&oldCount).Error)
+ require.Zero(t, oldCount)
+}
+
+func TestActivityServiceCompleteActivityRejectsUninitializedServiceInternal(t *testing.T) {
+ service := NewActivityService(nil)
+ _, err := service.CompleteActivity(context.Background(), "any-id", models.ActivityStatusSuccess, "done", nil)
+ require.Error(t, err)
+}
+
+func receiveActivityEventInternal(t *testing.T, events <-chan activitytypes.StreamEvent) activitytypes.StreamEvent {
+ t.Helper()
+
+ select {
+ case event := <-events:
+ return event
+ case <-time.After(time.Second):
+ t.Fatal("timed out waiting for activity event")
+ return activitytypes.StreamEvent{}
+ }
+}
diff --git a/backend/internal/services/container_service.go b/backend/internal/services/container_service.go
index 2677f2ba9..0b979c4c6 100644
--- a/backend/internal/services/container_service.go
+++ b/backend/internal/services/container_service.go
@@ -146,6 +146,17 @@ func shouldStartRedeployedContainerInternal(containerInfo container.InspectRespo
return shouldStart
}
+func writeContainerProgressInternal(ctx context.Context, message string, progress int, phase string) {
+ progressWriter, _ := ctx.Value(projects.ProgressWriterKey{}).(io.Writer)
+ if progressWriter == nil {
+ return
+ }
+ payload := fmt.Sprintf(`{"type":"container","phase":%q,"status":%q,"progressDetail":{"current":%d,"total":100}}`+"\n", phase, message, progress)
+ if _, err := progressWriter.Write([]byte(payload)); err != nil {
+ slog.DebugContext(ctx, "failed to write container progress", "phase", phase, "error", err)
+ }
+}
+
func (s *ContainerService) pullRedeployImageInternal(ctx context.Context, dockerClient *client.Client, imageName, containerID, containerName string, user models.User) error {
settings := s.settingsService.GetSettingsConfig()
pullCtx, pullCancel := timeouts.WithTimeout(ctx, settings.DockerImagePullTimeout.AsInt(), timeouts.DefaultDockerImagePull)
@@ -519,12 +530,14 @@ func (s *ContainerService) RedeployContainer(ctx context.Context, containerID st
}
if imageName != "" {
+ writeContainerProgressInternal(ctx, "Pulling latest container image", 20, "pull")
if err := s.pullRedeployImageInternal(ctx, dockerClient, imageName, containerID, containerName, user); err != nil {
return "", err
}
}
backupName := buildRedeployBackupNameInternal(containerName, containerID)
+ writeContainerProgressInternal(ctx, "Preparing existing container", 45, "prepare")
if err := s.prepareContainerForRedeployInternal(ctx, dockerClient, containerID, containerName, backupName, wasRunning, user); err != nil {
return "", err
}
@@ -536,6 +549,7 @@ func (s *ContainerService) RedeployContainer(ctx context.Context, containerID st
newConfig.Hostname = ""
}
+ writeContainerProgressInternal(ctx, "Creating replacement container", 65, "create")
createResp, err := libarcane.ContainerCreateWithCompatibilityForAPIVersion(ctx, dockerClient, client.ContainerCreateOptions{
Config: &newConfig,
HostConfig: containerInfo.HostConfig,
@@ -553,6 +567,7 @@ func (s *ContainerService) RedeployContainer(ctx context.Context, containerID st
}
if shouldStartRedeployedContainerInternal(containerInfo, wasRunning) {
+ writeContainerProgressInternal(ctx, "Starting replacement container", 80, "start")
_, err = dockerClient.ContainerStart(ctx, createResp.ID, client.ContainerStartOptions{})
if err != nil {
if _, removeErr := dockerClient.ContainerRemove(ctx, createResp.ID, client.ContainerRemoveOptions{Force: true}); removeErr != nil {
@@ -594,6 +609,7 @@ func (s *ContainerService) RedeployContainer(ctx context.Context, containerID st
slog.WarnContext(ctx, "failed to log deploy event", "err", logErr)
}
+ writeContainerProgressInternal(ctx, "Container redeployed", 100, "complete")
return createResp.ID, nil
}
diff --git a/backend/internal/services/image_service.go b/backend/internal/services/image_service.go
index 8a403ccfd..c27547968 100644
--- a/backend/internal/services/image_service.go
+++ b/backend/internal/services/image_service.go
@@ -11,6 +11,7 @@ import (
"sync"
"time"
+ ref "github.com/distribution/reference"
"github.com/getarcaneapp/arcane/backend/internal/database"
"github.com/getarcaneapp/arcane/backend/internal/models"
dockerutils "github.com/getarcaneapp/arcane/backend/pkg/dockerutil"
@@ -23,7 +24,6 @@ import (
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/image"
"github.com/moby/moby/client"
- ref "go.podman.io/image/v5/docker/reference"
"golang.org/x/sync/errgroup"
"gorm.io/gorm"
)
diff --git a/backend/internal/services/image_update_service.go b/backend/internal/services/image_update_service.go
index 74a199683..c75690a88 100644
--- a/backend/internal/services/image_update_service.go
+++ b/backend/internal/services/image_update_service.go
@@ -9,17 +9,18 @@ import (
"sync"
"time"
+ ref "github.com/distribution/reference"
"github.com/getarcaneapp/arcane/backend/internal/database"
"github.com/getarcaneapp/arcane/backend/internal/models"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane/crypto"
imageupdatecore "github.com/getarcaneapp/arcane/backend/pkg/libarcane/imageupdate"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane/ratelimit"
registry "github.com/getarcaneapp/arcane/backend/pkg/libarcane/registryauth"
+ "github.com/getarcaneapp/arcane/backend/pkg/utils"
"github.com/getarcaneapp/arcane/types/containerregistry"
"github.com/getarcaneapp/arcane/types/imageupdate"
"github.com/moby/moby/api/types/image"
"github.com/moby/moby/client"
- ref "go.podman.io/image/v5/docker/reference"
"golang.org/x/sync/errgroup"
"gorm.io/gorm"
)
@@ -32,6 +33,7 @@ type ImageUpdateService struct {
eventService *EventService
notificationService *NotificationService
registryLimiter *ratelimit.RegistryRateLimiter
+ activityService *ActivityService
}
type ImageParts struct {
@@ -48,7 +50,7 @@ type localImageSnapshot struct {
AllDigests []string
}
-func NewImageUpdateService(db *database.DB, settingsService *SettingsService, registryService *ContainerRegistryService, dockerService *DockerClientService, eventService *EventService, notificationService *NotificationService) *ImageUpdateService {
+func NewImageUpdateService(db *database.DB, settingsService *SettingsService, registryService *ContainerRegistryService, dockerService *DockerClientService, eventService *EventService, notificationService *NotificationService, activityService *ActivityService) *ImageUpdateService {
return &ImageUpdateService{
db: db,
settingsService: settingsService,
@@ -57,19 +59,87 @@ func NewImageUpdateService(db *database.DB, settingsService *SettingsService, re
eventService: eventService,
notificationService: notificationService,
registryLimiter: ratelimit.NewRegistryRateLimiter(),
+ activityService: activityService,
+ }
+}
+
+func (s *ImageUpdateService) startImageUpdateActivityInternal(ctx context.Context, resourceName string, count int) string {
+ if s.activityService == nil {
+ return ""
+ }
+ resourceType := "image"
+ if count > 1 {
+ resourceType = "images"
+ }
+ activity, err := s.activityService.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: "0",
+ Type: models.ActivityTypeImageUpdateCheck,
+ ResourceType: &resourceType,
+ ResourceName: utils.StringPtrFromTrimmed(resourceName),
+ Step: "Checking image updates",
+ LatestMessage: "Image update check started",
+ Metadata: models.JSON{
+ "imageCount": count,
+ },
+ })
+ if err != nil {
+ slog.DebugContext(ctx, "failed to start image update activity", "error", err)
+ return ""
+ }
+ return activity.ID
+}
+
+func (s *ImageUpdateService) appendImageUpdateActivityMessageInternal(ctx context.Context, activityID string, level models.ActivityMessageLevel, message string, progress int, step string) {
+ if s.activityService == nil || activityID == "" || strings.TrimSpace(message) == "" {
+ return
+ }
+ if level == "" {
+ level = models.ActivityMessageLevelInfo
+ }
+ if _, err := s.activityService.AppendMessage(ctx, activityID, AppendActivityMessageRequest{
+ Level: level,
+ Message: message,
+ Progress: &progress,
+ Step: step,
+ }); err != nil {
+ slog.DebugContext(ctx, "failed to append image update activity message", "activityId", activityID, "error", err)
+ }
+}
+
+func (s *ImageUpdateService) completeImageUpdateActivityInternal(ctx context.Context, activityID string, success bool, message string) {
+ if s.activityService == nil || activityID == "" {
+ return
+ }
+ status := models.ActivityStatusSuccess
+ var errMessage *string
+ if !success {
+ status = models.ActivityStatusFailed
+ errMessage = utils.StringPtrFromTrimmed(message)
+ }
+ if message == "" {
+ message = "Image update check completed"
+ }
+ step := "Image update check complete"
+ if _, err := s.activityService.CompleteActivity(context.WithoutCancel(ctx), activityID, status, message, errMessage, step); err != nil {
+ slog.DebugContext(ctx, "failed to complete image update activity", "activityId", activityID, "error", err)
}
}
func (s *ImageUpdateService) CheckImageUpdate(ctx context.Context, imageRef string) (*imageupdate.Response, error) {
startTime := time.Now()
+ activityID := s.startImageUpdateActivityInternal(ctx, imageRef, 1)
+ s.appendImageUpdateActivityMessageInternal(ctx, activityID, models.ActivityMessageLevelInfo, fmt.Sprintf("Checking %s", imageRef), 20, "Checking remote digest")
parts := s.parseImageReference(imageRef)
if parts == nil {
- return &imageupdate.Response{
+ result := &imageupdate.Response{
Error: "Invalid image reference format",
CheckTime: time.Now(),
ResponseTimeMs: int(time.Since(startTime).Milliseconds()),
- }, nil
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
+ }
+ s.completeImageUpdateActivityInternal(ctx, activityID, false, result.Error)
+ return result, nil
}
digestResult, snapshot, err := s.checkDigestUpdateWithSnapshotInternal(ctx, parts)
@@ -78,6 +148,7 @@ func (s *ImageUpdateService) CheckImageUpdate(ctx context.Context, imageRef stri
Error: err.Error(),
CheckTime: time.Now(),
ResponseTimeMs: int(time.Since(startTime).Milliseconds()),
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
}
metadata := models.JSON{
"action": "check_update",
@@ -91,10 +162,12 @@ func (s *ImageUpdateService) CheckImageUpdate(ctx context.Context, imageRef stri
if saveErr := s.saveUpdateResultWithSnapshotInternal(ctx, imageRef, result, snapshot); saveErr != nil {
slog.WarnContext(ctx, "Failed to save update result", "imageRef", imageRef, "error", saveErr.Error())
}
+ s.completeImageUpdateActivityInternal(ctx, activityID, false, result.Error)
return result, err
}
digestResult.ResponseTimeMs = int(time.Since(startTime).Milliseconds())
+ digestResult.ActivityID = utils.StringPtrFromTrimmed(activityID)
metadata := models.JSON{
"action": "check_update",
"imageRef": imageRef,
@@ -118,6 +191,11 @@ func (s *ImageUpdateService) CheckImageUpdate(ctx context.Context, imageRef stri
}
}
+ finalMessage := "Image update check completed"
+ if digestResult.HasUpdate {
+ finalMessage = "Image update available"
+ }
+ s.completeImageUpdateActivityInternal(ctx, activityID, true, finalMessage)
return digestResult, nil
}
@@ -505,6 +583,22 @@ func countBatchResultOutcomesInternal(imageRefs []string, results map[string]*im
return successCount, errorCount
}
+// imageCheckResultMessageInternal derives an activity message level and text from
+// a per-image update check result: errors become ERROR, available updates become
+// SUCCESS, and up-to-date images stay INFO.
+func imageCheckResultMessageInternal(imageRef string, res *imageupdate.Response) (models.ActivityMessageLevel, string) {
+ if res == nil {
+ return models.ActivityMessageLevelError, fmt.Sprintf("%s: check failed", imageRef)
+ }
+ if err := strings.TrimSpace(res.Error); err != "" {
+ return models.ActivityMessageLevelError, fmt.Sprintf("%s: %s", imageRef, err)
+ }
+ if res.HasUpdate {
+ return models.ActivityMessageLevelSuccess, fmt.Sprintf("%s — update available", imageRef)
+ }
+ return models.ActivityMessageLevelInfo, fmt.Sprintf("%s — up to date", imageRef)
+}
+
func extractRepoAndTagFromImage(dockerImage image.InspectResponse) (repo, tag string) {
if len(dockerImage.RepoTags) > 0 && dockerImage.RepoTags[0] != "<none>:<none>" {
if named, err := ref.ParseNormalizedNamed(dockerImage.RepoTags[0]); err == nil {
@@ -892,16 +986,24 @@ func (s *ImageUpdateService) CheckMultipleImages(ctx context.Context, imageRefs
return results, nil
}
+ activityID := s.startImageUpdateActivityInternal(ctx, fmt.Sprintf("%d images", len(imageRefs)), len(imageRefs))
+ s.appendImageUpdateActivityMessageInternal(ctx, activityID, models.ActivityMessageLevelInfo, fmt.Sprintf("Checking %d image references", len(imageRefs)), 5, "Preparing image update check")
slog.DebugContext(ctx, "Starting batch image update check", "imageCount", len(imageRefs), "externalCredCount", len(externalCreds))
regRepos, initialResults, images := s.parseAndGroupImagesInternal(imageRefs)
maps.Copy(results, initialResults)
+ for _, result := range initialResults {
+ if result != nil {
+ result.ActivityID = utils.StringPtrFromTrimmed(activityID)
+ }
+ }
resolvedCreds := s.resolveBatchCredentialsInternal(ctx, externalCreds)
slog.DebugContext(ctx, "Resolved batch registry credentials", "credentialCount", len(resolvedCreds), "registryCount", len(regRepos))
var mu sync.Mutex
+ completed := 0
g, groupCtx := errgroup.WithContext(ctx)
g.SetLimit(10) // Limit concurrency
@@ -919,13 +1021,21 @@ func (s *ImageUpdateService) CheckMultipleImages(ctx context.Context, imageRefs
defer s.registryLimiter.Release(registry)
res, snapshot := s.checkSingleImageInBatchInternal(groupCtx, resolvedCreds, img.parts)
+ if res != nil {
+ res.ActivityID = utils.StringPtrFromTrimmed(activityID)
+ }
mu.Lock()
+ completed++
+ progress := 10 + int(float64(completed)/float64(len(images))*80)
for _, ref := range img.refs {
results[ref] = res
}
mu.Unlock()
+ level, message := imageCheckResultMessageInternal(img.canonicalRef, res)
+ s.appendImageUpdateActivityMessageInternal(groupCtx, activityID, level, message, progress, "Checking image")
+
if err := s.saveUpdateResultWithSnapshotInternal(groupCtx, img.canonicalRef, res, snapshot); err != nil {
slog.WarnContext(groupCtx, "Failed to save update result", "imageRef", img.canonicalRef, "error", err.Error())
}
@@ -939,64 +1049,68 @@ func (s *ImageUpdateService) CheckMultipleImages(ctx context.Context, imageRefs
}
successCount, errorCount := countBatchResultOutcomesInternal(imageRefs, results)
+ finalSuccess := errorCount == 0
+ finalMessage := fmt.Sprintf("Image update check completed: %d checked, %d errors", successCount, errorCount)
+ s.completeImageUpdateActivityInternal(ctx, activityID, finalSuccess, finalMessage)
slog.InfoContext(ctx, "Batch image update check completed",
"totalImages", len(imageRefs),
"successCount", successCount,
"errorCount", errorCount,
"duration", time.Since(startBatch))
- if s.notificationService != nil {
- // Use a context with timeout for notifications
- notifCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
- defer cancel()
+ s.sendBatchImageUpdateNotificationsInternal(ctx)
- // Get only the updates that haven't been notified yet
- unnotifiedUpdates, err := s.GetUnnotifiedUpdates(notifCtx)
- switch {
- case err != nil:
- slog.WarnContext(ctx, "Failed to get unnotified updates", "error", err.Error())
- case len(unnotifiedUpdates) > 0:
- // Convert unnotified records to the format expected by notification service
- updatesToNotify := make(map[string]*imageupdate.Response)
- imageIDsToMark := make([]string, 0, len(unnotifiedUpdates))
-
- for imageID, record := range unnotifiedUpdates {
- // Construct image ref from repository and tag
- imageRef := fmt.Sprintf("%s:%s", record.Repository, record.Tag)
- updatesToNotify[imageRef] = &imageupdate.Response{
- HasUpdate: record.HasUpdate,
- UpdateType: record.UpdateType,
- CurrentVersion: record.CurrentVersion,
- LatestVersion: stringPtrToString(record.LatestVersion),
- CurrentDigest: stringPtrToString(record.CurrentDigest),
- LatestDigest: stringPtrToString(record.LatestDigest),
- CheckTime: record.CheckTime,
- ResponseTimeMs: record.ResponseTimeMs,
- Error: stringPtrToString(record.LastError),
- AuthMethod: stringPtrToString(record.AuthMethod),
- AuthUsername: stringPtrToString(record.AuthUsername),
- AuthRegistry: stringPtrToString(record.AuthRegistry),
- UsedCredential: record.UsedCredential,
- }
- imageIDsToMark = append(imageIDsToMark, imageID)
+ return results, nil
+}
+
+func (s *ImageUpdateService) sendBatchImageUpdateNotificationsInternal(ctx context.Context) {
+ if s.notificationService == nil {
+ return
+ }
+
+ notifCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
+ defer cancel()
+
+ unnotifiedUpdates, err := s.GetUnnotifiedUpdates(notifCtx)
+ switch {
+ case err != nil:
+ slog.WarnContext(ctx, "Failed to get unnotified updates", "error", err.Error())
+ case len(unnotifiedUpdates) > 0:
+ updatesToNotify := make(map[string]*imageupdate.Response)
+ imageIDsToMark := make([]string, 0, len(unnotifiedUpdates))
+
+ for imageID, record := range unnotifiedUpdates {
+ imageRef := fmt.Sprintf("%s:%s", record.Repository, record.Tag)
+ updatesToNotify[imageRef] = &imageupdate.Response{
+ HasUpdate: record.HasUpdate,
+ UpdateType: record.UpdateType,
+ CurrentVersion: record.CurrentVersion,
+ LatestVersion: stringPtrToString(record.LatestVersion),
+ CurrentDigest: stringPtrToString(record.CurrentDigest),
+ LatestDigest: stringPtrToString(record.LatestDigest),
+ CheckTime: record.CheckTime,
+ ResponseTimeMs: record.ResponseTimeMs,
+ Error: stringPtrToString(record.LastError),
+ AuthMethod: stringPtrToString(record.AuthMethod),
+ AuthUsername: stringPtrToString(record.AuthUsername),
+ AuthRegistry: stringPtrToString(record.AuthRegistry),
+ UsedCredential: record.UsedCredential,
}
+ imageIDsToMark = append(imageIDsToMark, imageID)
+ }
- slog.InfoContext(ctx, "Sending notifications for unnotified updates", "count", len(updatesToNotify))
+ slog.InfoContext(ctx, "Sending notifications for unnotified updates", "count", len(updatesToNotify))
- if notifErr := s.notificationService.SendBatchImageUpdateNotification(notifCtx, updatesToNotify); notifErr != nil {
- slog.WarnContext(ctx, "Failed to send batch update notification", "error", notifErr.Error())
- } else {
- // Mark the images as notified only if notification was successful
- if markErr := s.MarkUpdatesAsNotified(notifCtx, imageIDsToMark); markErr != nil {
- slog.WarnContext(ctx, "Failed to mark updates as notified", "error", markErr.Error())
- }
- }
- default:
- slog.DebugContext(ctx, "No new updates to notify")
+ if notifErr := s.notificationService.SendBatchImageUpdateNotification(notifCtx, updatesToNotify); notifErr != nil {
+ slog.WarnContext(ctx, "Failed to send batch update notification", "error", notifErr.Error())
+ return
+ }
+ if markErr := s.MarkUpdatesAsNotified(notifCtx, imageIDsToMark); markErr != nil {
+ slog.WarnContext(ctx, "Failed to mark updates as notified", "error", markErr.Error())
}
+ default:
+ slog.DebugContext(ctx, "No new updates to notify")
}
-
- return results, nil
}
func (s *ImageUpdateService) CheckAllImages(ctx context.Context, limit int, externalCreds []containerregistry.Credential) (map[string]*imageupdate.Response, error) {
diff --git a/backend/internal/services/image_update_service_test.go b/backend/internal/services/image_update_service_test.go
index 95f00ac80..3440215ea 100644
--- a/backend/internal/services/image_update_service_test.go
+++ b/backend/internal/services/image_update_service_test.go
@@ -12,6 +12,7 @@ import (
"testing"
"time"
+ ref "github.com/distribution/reference"
"github.com/getarcaneapp/arcane/backend/internal/database"
"github.com/getarcaneapp/arcane/backend/internal/models"
"github.com/getarcaneapp/arcane/types/imageupdate"
@@ -24,7 +25,6 @@ import (
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- ref "go.podman.io/image/v5/docker/reference"
"gorm.io/gorm"
)
@@ -523,7 +523,7 @@ func TestImageUpdateService_CheckImageUpdate_UsesRegistryFallback(t *testing.T)
dockerService := &DockerClientService{client: newTestDockerClient(t, server)}
eventService := NewEventService(db, nil, nil)
- svc := NewImageUpdateService(db, nil, registryService, dockerService, eventService, nil)
+ svc := NewImageUpdateService(db, nil, registryService, dockerService, eventService, nil, nil)
result, err := svc.CheckImageUpdate(context.Background(), imageRef)
require.NoError(t, err)
@@ -563,7 +563,7 @@ func TestImageUpdateService_CheckMultipleImages_UsesRegistryFallback(t *testing.
dockerService := &DockerClientService{client: newTestDockerClient(t, server)}
eventService := NewEventService(db, nil, nil)
- svc := NewImageUpdateService(db, nil, registryService, dockerService, eventService, nil)
+ svc := NewImageUpdateService(db, nil, registryService, dockerService, eventService, nil, nil)
results, err := svc.CheckMultipleImages(context.Background(), []string{imageRef}, nil)
require.NoError(t, err)
@@ -618,7 +618,7 @@ func TestImageUpdateService_CheckMultipleImages_UsesDockerHubCredentialsOnFirstA
dockerService := &DockerClientService{client: newTestDockerClient(t, server)}
eventService := NewEventService(db, nil, nil)
- svc := NewImageUpdateService(db, nil, registryService, dockerService, eventService, nil)
+ svc := NewImageUpdateService(db, nil, registryService, dockerService, eventService, nil, nil)
results, err := svc.CheckMultipleImages(context.Background(), []string{"docker.io/library/registry:3"}, nil)
require.NoError(t, err)
@@ -658,7 +658,7 @@ func TestImageUpdateService_CheckMultipleImages_PersistsRefScopedErrorsWhenLocal
dockerService := &DockerClientService{client: newTestDockerClient(t, server)}
eventService := NewEventService(db, nil, nil)
- svc := NewImageUpdateService(db, nil, registryService, dockerService, eventService, nil)
+ svc := NewImageUpdateService(db, nil, registryService, dockerService, eventService, nil, nil)
results, err := svc.CheckMultipleImages(context.Background(), []string{imageRef}, nil)
require.NoError(t, err)
@@ -686,7 +686,7 @@ func TestImageUpdateService_SaveUpdateResultWithSnapshotInternal_PersistsRegistr
require.NoError(t, err)
imageRef := serverURL.Host + "/library/nginx:alpine"
- svc := NewImageUpdateService(db, nil, nil, &DockerClientService{client: newTestDockerClient(t, server)}, nil, nil)
+ svc := NewImageUpdateService(db, nil, nil, &DockerClientService{client: newTestDockerClient(t, server)}, nil, nil, nil)
result := &imageupdate.Response{
HasUpdate: true,
UpdateType: "digest",
@@ -763,7 +763,7 @@ func TestImageUpdateService_MarkImageRefUpToDateAfterPull_ClearsMatchingRecordsA
CheckTime: now,
}).Error)
- svc := NewImageUpdateService(db, nil, nil, &DockerClientService{client: newTestDockerClient(t, server)}, nil, nil)
+ svc := NewImageUpdateService(db, nil, nil, &DockerClientService{client: newTestDockerClient(t, server)}, nil, nil, nil)
require.NoError(t, svc.MarkImageRefUpToDateAfterPull(context.Background(), imageRef))
diff --git a/backend/internal/services/project_service.go b/backend/internal/services/project_service.go
index 41bd6f9b4..ecfdcdcbb 100644
--- a/backend/internal/services/project_service.go
+++ b/backend/internal/services/project_service.go
@@ -721,6 +721,26 @@ func (s *ProjectService) pullAndReconcileImageInternal(
return nil
}
+type projectProgressSuppressedContextKey struct{}
+
+func withProjectProgressSuppressedInternal(ctx context.Context) context.Context {
+ return context.WithValue(ctx, projectProgressSuppressedContextKey{}, true)
+}
+
+func writeProjectProgressInternal(ctx context.Context, message string, progress int, phase string) {
+ if suppressed, _ := ctx.Value(projectProgressSuppressedContextKey{}).(bool); suppressed {
+ return
+ }
+ progressWriter, _ := ctx.Value(projects.ProgressWriterKey{}).(io.Writer)
+ if progressWriter == nil {
+ return
+ }
+ payload := fmt.Sprintf(`{"type":"project","phase":%q,"status":%q,"progressDetail":{"current":%d,"total":100}}`+"\n", phase, message, progress)
+ if _, err := progressWriter.Write([]byte(payload)); err != nil {
+ slog.DebugContext(ctx, "failed to write project progress", "phase", phase, "error", err)
+ }
+}
+
func (s *ProjectService) UpdateProjectServices(ctx context.Context, projectID string, servicesToUpdate []string, user models.User) error {
projectFromDb, err := s.GetProjectFromDatabaseByID(ctx, projectID)
if err != nil {
@@ -739,16 +759,19 @@ func (s *ProjectService) UpdateProjectServices(ctx context.Context, projectID st
}
// 3. Pull images for specific services
+ writeProjectProgressInternal(ctx, "Pulling updated service images", 20, "pull")
if err := s.composePullSelectedServicesInternal(ctx, compProj, servicesToUpdate); err != nil {
slog.WarnContext(ctx, "compose pull failed, continuing", "error", err)
}
// 4. Stop specific services
+ writeProjectProgressInternal(ctx, "Stopping selected services", 45, "stop")
if err := projects.ComposeStop(ctx, compProj, servicesToUpdate); err != nil {
slog.WarnContext(ctx, "compose stop failed, continuing", "error", err)
}
// 5. Up specific services
+ writeProjectProgressInternal(ctx, "Starting selected services", 70, "up")
if err := projects.ComposeUp(ctx, compProj, servicesToUpdate, false, false); err != nil {
if statusErr := s.updateProjectStatusandCountsInternal(ctx, projectID, models.ProjectStatusStopped); statusErr != nil {
slog.ErrorContext(ctx, "UpdateProjectServices: failed to set stopped status after compose up failure", "projectID", projectID, "error", statusErr)
@@ -757,9 +780,11 @@ func (s *ProjectService) UpdateProjectServices(ctx context.Context, projectID st
}
// 6. Finalize status
+ writeProjectProgressInternal(ctx, "Refreshing project status", 90, "status")
if err := s.updateProjectStatusandCountsInternal(ctx, projectID, models.ProjectStatusRunning); err != nil {
return err
}
+ writeProjectProgressInternal(ctx, "Service update completed", 100, "complete")
metadata := models.JSON{
"action": "update_services",
@@ -1939,6 +1964,7 @@ func (s *ProjectService) DownProject(ctx context.Context, projectID string, user
return fmt.Errorf("failed to update project status to stopping: %w", err)
}
+ writeProjectProgressInternal(ctx, "Stopping project services", 45, "down")
if err := projects.ComposeDown(ctx, proj, false); err != nil {
_ = s.updateProjectStatusInternal(ctx, projectID, models.ProjectStatusRunning)
return fmt.Errorf("failed to bring down project: %w", err)
@@ -1953,7 +1979,12 @@ func (s *ProjectService) DownProject(ctx context.Context, projectID string, user
slog.ErrorContext(ctx, "could not log project down action", "error", logErr)
}
- return s.updateProjectStatusandCountsInternal(ctx, projectID, models.ProjectStatusStopped)
+ writeProjectProgressInternal(ctx, "Refreshing project status", 90, "status")
+ if err := s.updateProjectStatusandCountsInternal(ctx, projectID, models.ProjectStatusStopped); err != nil {
+ return err
+ }
+ writeProjectProgressInternal(ctx, "Project stopped", 100, "complete")
+ return nil
}
func (s *ProjectService) CreateProject(ctx context.Context, name, composeContent string, envContent *string, user models.User) (*models.Project, error) {
@@ -2021,11 +2052,13 @@ func (s *ProjectService) DestroyProject(ctx context.Context, projectID string, r
"projectName", proj.Name,
"projectPath", proj.Path)
- if err := s.DownProject(ctx, projectID, systemUser); err != nil {
+ writeProjectProgressInternal(ctx, "Stopping project before destroy", 25, "down")
+ if err := s.DownProject(withProjectProgressSuppressedInternal(ctx), projectID, systemUser); err != nil {
slog.WarnContext(ctx, "failed to bring down project", "error", err)
}
if removeVolumes {
+ writeProjectProgressInternal(ctx, "Removing project volumes", 55, "volumes")
if compProj, _, lerr := s.loadComposeProjectForProjectInternal(ctx, proj, nil); lerr == nil {
if derr := projects.ComposeDown(ctx, compProj, true); derr != nil {
slog.WarnContext(ctx, "failed to remove volumes", "error", derr)
@@ -2036,6 +2069,7 @@ func (s *ProjectService) DestroyProject(ctx context.Context, projectID string, r
}
if removeFiles {
+ writeProjectProgressInternal(ctx, "Removing project files", 75, "files")
slog.DebugContext(ctx, "Removing project files", "path", proj.Path)
if err := os.RemoveAll(proj.Path); err != nil {
slog.ErrorContext(ctx, "Failed to remove project files", "path", proj.Path, "error", err)
@@ -2050,6 +2084,7 @@ func (s *ProjectService) DestroyProject(ctx context.Context, projectID string, r
return fmt.Errorf("failed to delete project from database: %w", err)
}
s.invalidateComposeCacheInternal(projectID)
+ writeProjectProgressInternal(ctx, "Project destroyed", 100, "complete")
metadata := models.JSON{"action": "destroy", "projectID": projectID, "projectName": proj.Name, "removeFiles": removeFiles, "removeVolumes": removeVolumes}
if logErr := s.eventService.LogProjectEvent(ctx, models.EventTypeProjectDelete, projectID, proj.Name, user.ID, user.Username, "0", metadata); logErr != nil {
@@ -2076,7 +2111,15 @@ func (s *ProjectService) RedeployProject(ctx context.Context, projectID string,
return &common.ArcaneSelfRedeployError{}
}
- if err := s.PullProjectImages(ctx, projectID, io.Discard, user, nil); err != nil {
+ progressWriter, _ := ctx.Value(projects.ProgressWriterKey{}).(io.Writer)
+ if progressWriter == nil {
+ progressWriter = io.Discard
+ }
+ if _, writeErr := progressWriter.Write([]byte(`{"type":"deploy","phase":"pull","status":"pulling project images"}` + "\n")); writeErr != nil {
+ slog.DebugContext(ctx, "failed to write redeploy pull progress", "error", writeErr)
+ }
+
+ if err := s.PullProjectImages(ctx, projectID, progressWriter, user, nil); err != nil {
slog.WarnContext(ctx, "failed to pull project images", "error", err)
}
@@ -2085,6 +2128,10 @@ func (s *ProjectService) RedeployProject(ctx context.Context, projectID string,
slog.ErrorContext(ctx, "could not log project redeploy action", "error", logErr)
}
+ if _, writeErr := progressWriter.Write([]byte(`{"type":"deploy","phase":"up","status":"starting project deployment"}` + "\n")); writeErr != nil {
+ slog.DebugContext(ctx, "failed to write redeploy deploy progress", "error", writeErr)
+ }
+
return s.DeployProject(ctx, projectID, user, options)
}
@@ -2792,6 +2839,7 @@ func (s *ProjectService) RestartProject(ctx context.Context, projectID string, u
return fmt.Errorf("failed to load compose project: %w", lerr)
}
+ writeProjectProgressInternal(ctx, "Restarting project services", 55, "restart")
if err := projects.ComposeRestart(ctx, compProj, nil); err != nil {
_ = s.updateProjectStatusInternal(ctx, projectID, models.ProjectStatusRunning)
return fmt.Errorf("failed to restart project: %w", err)
@@ -2806,7 +2854,12 @@ func (s *ProjectService) RestartProject(ctx context.Context, projectID string, u
slog.ErrorContext(ctx, "could not log project restart action", "error", logErr)
}
- return s.updateProjectStatusandCountsInternal(ctx, projectID, models.ProjectStatusRunning)
+ writeProjectProgressInternal(ctx, "Refreshing project status", 90, "status")
+ if err := s.updateProjectStatusandCountsInternal(ctx, projectID, models.ProjectStatusRunning); err != nil {
+ return err
+ }
+ writeProjectProgressInternal(ctx, "Project restarted", 100, "complete")
+ return nil
}
func (s *ProjectService) UpdateProject(ctx context.Context, projectID string, name *string, composeContent, envContent *string, user models.User) (*models.Project, error) {
diff --git a/backend/internal/services/project_service_test.go b/backend/internal/services/project_service_test.go
index dfa9d928a..07bf3858c 100644
--- a/backend/internal/services/project_service_test.go
+++ b/backend/internal/services/project_service_test.go
@@ -1,6 +1,7 @@
package services
import (
+ "bytes"
"context"
"encoding/json"
"errors"
@@ -39,6 +40,17 @@ import (
"github.com/getarcaneapp/arcane/backend/internal/models"
)
+func TestWriteProjectProgressInternal_SuppressedContextSkipsProgress(t *testing.T) {
+ ctx := context.Background()
+ var buf bytes.Buffer
+ ctx = context.WithValue(ctx, projects.ProgressWriterKey{}, &buf)
+ ctx = withProjectProgressSuppressedInternal(ctx)
+
+ writeProjectProgressInternal(ctx, "Project stopped", 100, "complete")
+
+ require.Empty(t, buf.String())
+}
+
type testBuildBuilder struct {
err error
}
@@ -565,7 +577,7 @@ func TestProjectService_PullProjectImages_UpdatesCurrentImageRecordAfterPull(t *
dockerService := &DockerClientService{client: newTestDockerClient(t, server)}
eventService := NewEventService(db, nil, nil)
- imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil)
+ imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil, nil)
imageService := NewImageService(db, dockerService, nil, imageUpdateService, nil, eventService)
svc := NewProjectService(db, settingsService, nil, imageService, dockerService, nil, config.Load())
@@ -660,7 +672,7 @@ func TestProjectService_EnsureImagesPresent_UpdatesCurrentImageRecordAfterPull(t
dockerService := &DockerClientService{client: newTestDockerClient(t, server)}
eventService := NewEventService(db, nil, nil)
- imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil)
+ imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil, nil)
imageService := NewImageService(db, dockerService, nil, imageUpdateService, nil, eventService)
svc := NewProjectService(db, settingsService, nil, imageService, dockerService, nil, config.Load())
@@ -712,7 +724,7 @@ func TestProjectService_PullImageForService_UpdatesCurrentImageRecordAfterPull(t
dockerService := &DockerClientService{client: newTestDockerClient(t, server)}
eventService := NewEventService(db, nil, nil)
- imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil)
+ imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil, nil)
imageService := NewImageService(db, dockerService, nil, imageUpdateService, nil, eventService)
svc := NewProjectService(db, settingsService, nil, imageService, dockerService, nil, config.Load())
@@ -761,7 +773,7 @@ func TestProjectService_ComposePullSelectedServicesInternal_ReconcilesOnlyOnSucc
dockerService := &DockerClientService{client: newTestDockerClient(t, server)}
eventService := NewEventService(db, nil, nil)
- imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil)
+ imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil, nil)
imageService := NewImageService(db, dockerService, nil, imageUpdateService, nil, eventService)
svc := NewProjectService(db, settingsService, nil, imageService, dockerService, nil, config.Load())
@@ -839,7 +851,7 @@ func TestProjectService_ComposePullSelectedServicesInternal_LeavesRecordsWhenPul
repository := "registry.example.com/team/app"
dockerService := &DockerClientService{}
- imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil)
+ imageUpdateService := NewImageUpdateService(db, nil, nil, dockerService, nil, nil, nil)
imageService := NewImageService(db, dockerService, nil, imageUpdateService, nil, NewEventService(db, nil, nil))
svc := NewProjectService(db, settingsService, nil, imageService, dockerService, nil, config.Load())
diff --git a/backend/internal/services/settings_service.go b/backend/internal/services/settings_service.go
index 20d49ead0..6d11ba7ab 100644
--- a/backend/internal/services/settings_service.go
+++ b/backend/internal/services/settings_service.go
@@ -120,6 +120,8 @@ func DefaultSettingsConfig() *models.Settings {
DockerClientRefreshInterval: models.SettingVariable{Value: "*/30 * * * * *"},
EventCleanupInterval: models.SettingVariable{Value: "0 0 */6 * * *"},
ExpiredSessionsCleanupInterval: models.SettingVariable{Value: "0 0 0 * * *"},
+ ActivityHistoryRetentionDays: models.SettingVariable{Value: "30"},
+ ActivityHistoryMaxEntries: models.SettingVariable{Value: "1000"},
AutoInjectEnv: models.SettingVariable{Value: "false"},
DefaultDeployPullPolicy: models.SettingVariable{Value: "missing"},
ScheduledPruneEnabled: models.SettingVariable{Value: "false"},
diff --git a/backend/internal/services/system_service.go b/backend/internal/services/system_service.go
index 9ab5e957e..b31b5ec89 100644
--- a/backend/internal/services/system_service.go
+++ b/backend/internal/services/system_service.go
@@ -12,6 +12,7 @@ import (
"github.com/getarcaneapp/arcane/backend/internal/models"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane/dockerrun"
libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/imageupdate"
+ "github.com/getarcaneapp/arcane/backend/pkg/utils"
containertypes "github.com/getarcaneapp/arcane/types/container"
"github.com/getarcaneapp/arcane/types/system"
"github.com/goccy/go-yaml"
@@ -28,6 +29,9 @@ type SystemService struct {
volumeService *VolumeService
networkService *NetworkService
settingsService *SettingsService
+ activityService *ActivityService
+ pruneMu sync.Mutex
+ runningPrunes map[string]string
}
func NewSystemService(
@@ -38,6 +42,7 @@ func NewSystemService(
volumeService *VolumeService,
networkService *NetworkService,
settingsService *SettingsService,
+ activityService *ActivityService,
) *SystemService {
return &SystemService{
db: db,
@@ -47,6 +52,8 @@ func NewSystemService(
volumeService: volumeService,
networkService: networkService,
settingsService: settingsService,
+ activityService: activityService,
+ runningPrunes: make(map[string]string),
}
}
@@ -54,7 +61,7 @@ var systemUser = models.User{
Username: "System",
}
-func (s *SystemService) PruneAll(ctx context.Context, req system.PruneAllRequest) (*system.PruneAllResult, error) {
+func (s *SystemService) PruneAll(ctx context.Context, environmentID string, req system.PruneAllRequest) (*system.PruneAllResult, bool, error) {
slog.InfoContext(ctx, "Starting selective prune operation",
"containers", req.Containers,
"images", req.Images,
@@ -63,11 +70,65 @@ func (s *SystemService) PruneAll(ctx context.Context, req system.PruneAllRequest
"build_cache", req.BuildCache,
)
- result := &system.PruneAllResult{Success: true}
+ activityID, started := s.beginSystemPruneInternal(ctx, environmentID, req)
+ result := &system.PruneAllResult{Success: true, ActivityID: utils.StringPtrFromTrimmed(activityID)}
+ if !started {
+ slog.InfoContext(ctx, "System prune already running", "environmentId", environmentID, "activityId", activityID)
+ return result, false, nil
+ }
+
+ defer s.finishSystemPruneInternal(environmentID)
+
+ s.runSystemPruneInternal(ctx, req, activityID, result)
+
+ return result, true, nil
+}
+
+func (s *SystemService) StartPruneAll(ctx context.Context, environmentID string, req system.PruneAllRequest) *system.PruneAllResult {
+ activityID, started := s.beginSystemPruneInternal(ctx, environmentID, req)
+ if !started {
+ slog.InfoContext(ctx, "System prune already running", "environmentId", environmentID, "activityId", activityID)
+ return &system.PruneAllResult{Success: true, ActivityID: utils.StringPtrFromTrimmed(activityID)}
+ }
+
+ backgroundCtx := context.WithoutCancel(ctx)
+
+ go func() {
+ defer s.finishSystemPruneInternal(environmentID)
+
+ result := &system.PruneAllResult{Success: true, ActivityID: utils.StringPtrFromTrimmed(activityID)}
+ s.runSystemPruneInternal(backgroundCtx, req, activityID, result)
+ }()
+
+ return &system.PruneAllResult{Success: true, ActivityID: utils.StringPtrFromTrimmed(activityID)}
+}
+
+func (s *SystemService) beginSystemPruneInternal(ctx context.Context, environmentID string, req system.PruneAllRequest) (string, bool) {
+ s.pruneMu.Lock()
+ defer s.pruneMu.Unlock()
+
+ if activityID, ok := s.runningPrunes[environmentID]; ok {
+ return activityID, false
+ }
+
+ activityID := s.startSystemPruneActivityInternal(ctx, environmentID, req)
+ s.runningPrunes[environmentID] = activityID
+ return activityID, true
+}
+
+func (s *SystemService) finishSystemPruneInternal(environmentID string) {
+ s.pruneMu.Lock()
+ defer s.pruneMu.Unlock()
+
+ delete(s.runningPrunes, environmentID)
+}
+
+func (s *SystemService) runSystemPruneInternal(ctx context.Context, req system.PruneAllRequest, activityID string, result *system.PruneAllResult) {
var mu sync.Mutex
// 1. Prune Containers first (sequential) as it may free up other resources
if req.Containers != nil && req.Containers.Mode != system.PruneContainerModeNone {
+ s.appendSystemPruneActivityMessageInternal(ctx, activityID, "Pruning containers", 15)
slog.InfoContext(ctx, "Pruning containers...", "mode", req.Containers.Mode, "until", req.Containers.Until)
if err := s.pruneContainersInternal(ctx, *req.Containers, result); err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Container pruning failed: %v", err))
@@ -80,6 +141,7 @@ func (s *SystemService) PruneAll(ctx context.Context, req system.PruneAllRequest
if req.Images != nil && req.Images.Mode != system.PruneImageModeNone {
g.Go(func() error {
+ s.appendSystemPruneActivityMessageInternal(groupCtx, activityID, "Pruning images", 40)
slog.InfoContext(groupCtx, "Pruning images...", "mode", req.Images.Mode, "until", req.Images.Until)
localResult := &system.PruneAllResult{}
if err := s.pruneImagesInternal(groupCtx, *req.Images, localResult); err != nil {
@@ -100,6 +162,7 @@ func (s *SystemService) PruneAll(ctx context.Context, req system.PruneAllRequest
if req.BuildCache != nil && req.BuildCache.Mode != system.PruneBuildCacheModeNone {
g.Go(func() error {
+ s.appendSystemPruneActivityMessageInternal(groupCtx, activityID, "Pruning build cache", 45)
slog.InfoContext(groupCtx, "Pruning build cache...", "mode", req.BuildCache.Mode, "until", req.BuildCache.Until)
localResult := &system.PruneAllResult{}
if err := s.pruneBuildCacheInternal(groupCtx, *req.BuildCache, localResult); err != nil {
@@ -117,6 +180,7 @@ func (s *SystemService) PruneAll(ctx context.Context, req system.PruneAllRequest
if req.Volumes != nil && req.Volumes.Mode != system.PruneVolumeModeNone {
g.Go(func() error {
+ s.appendSystemPruneActivityMessageInternal(groupCtx, activityID, "Pruning volumes", 55)
slog.InfoContext(groupCtx, "Pruning volumes...", "mode", req.Volumes.Mode)
localResult := &system.PruneAllResult{}
if err := s.pruneVolumesInternal(groupCtx, *req.Volumes, localResult); err != nil {
@@ -137,6 +201,7 @@ func (s *SystemService) PruneAll(ctx context.Context, req system.PruneAllRequest
if req.Networks != nil && req.Networks.Mode != system.PruneNetworkModeNone {
g.Go(func() error {
+ s.appendSystemPruneActivityMessageInternal(groupCtx, activityID, "Pruning networks", 65)
slog.InfoContext(groupCtx, "Pruning networks...", "mode", req.Networks.Mode, "until", req.Networks.Until)
localResult := &system.PruneAllResult{}
if err := s.pruneNetworksInternal(groupCtx, *req.Networks, localResult); err != nil {
@@ -158,8 +223,68 @@ func (s *SystemService) PruneAll(ctx context.Context, req system.PruneAllRequest
}
slog.InfoContext(ctx, "Selective prune operation completed", "success", result.Success, "containers_pruned", len(result.ContainersPruned), "images_deleted", len(result.ImagesDeleted), "volumes_deleted", len(result.VolumesDeleted), "networks_deleted", len(result.NetworksDeleted), "space_reclaimed", result.SpaceReclaimed, "error_count", len(result.Errors))
+ s.completeSystemPruneActivityInternal(ctx, activityID, result)
+}
- return result, nil
+func (s *SystemService) startSystemPruneActivityInternal(ctx context.Context, environmentID string, req system.PruneAllRequest) string {
+ if s.activityService == nil {
+ return ""
+ }
+ resourceType := "system"
+ resourceName := "Docker resources"
+ activity, err := s.activityService.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: environmentID,
+ Type: models.ActivityTypeSystemPrune,
+ ResourceType: &resourceType,
+ ResourceName: &resourceName,
+ Step: "Preparing prune",
+ LatestMessage: "System prune started",
+ Metadata: models.JSON{
+ "containers": req.Containers,
+ "images": req.Images,
+ "volumes": req.Volumes,
+ "networks": req.Networks,
+ "buildCache": req.BuildCache,
+ },
+ })
+ if err != nil {
+ slog.DebugContext(ctx, "failed to start system prune activity", "error", err)
+ return ""
+ }
+ return activity.ID
+}
+
+func (s *SystemService) appendSystemPruneActivityMessageInternal(ctx context.Context, activityID, message string, progress int) {
+ if s.activityService == nil || activityID == "" {
+ return
+ }
+ if _, err := s.activityService.AppendMessage(ctx, activityID, AppendActivityMessageRequest{
+ Level: models.ActivityMessageLevelInfo,
+ Message: message,
+ Progress: &progress,
+ Step: message,
+ }); err != nil {
+ slog.DebugContext(ctx, "failed to append system prune activity message", "activityId", activityID, "error", err)
+ }
+}
+
+func (s *SystemService) completeSystemPruneActivityInternal(ctx context.Context, activityID string, result *system.PruneAllResult) {
+ if s.activityService == nil || activityID == "" || result == nil {
+ return
+ }
+
+ status := models.ActivityStatusSuccess
+ message := "System prune completed"
+ var errMessage *string
+ if !result.Success || len(result.Errors) > 0 {
+ status = models.ActivityStatusFailed
+ message = "System prune completed with errors"
+ joined := strings.Join(result.Errors, "; ")
+ errMessage = &joined
+ }
+ if _, err := s.activityService.CompleteActivity(context.WithoutCancel(ctx), activityID, status, message, errMessage); err != nil {
+ slog.DebugContext(ctx, "failed to complete system prune activity", "activityId", activityID, "error", err)
+ }
}
func (s *SystemService) performBatchContainerAction(ctx context.Context, containers []container.Summary, actionName string, shouldProcess func(container.Summary) bool, action func(context.Context, string) error) *containertypes.ActionResult {
@@ -201,55 +326,116 @@ func (s *SystemService) performBatchContainerAction(ctx context.Context, contain
return result
}
-func (s *SystemService) StartAllContainers(ctx context.Context) (*containertypes.ActionResult, error) {
+func (s *SystemService) StartAllContainers(ctx context.Context, environmentID string) (*containertypes.ActionResult, error) {
+ activityID := s.startSystemContainerActivityInternal(ctx, environmentID, models.ActivityTypeContainerStart, "All containers", "Starting all containers")
containers, _, _, _, err := s.dockerService.GetAllContainers(ctx)
if err != nil {
- return &containertypes.ActionResult{
- Success: false,
- Errors: []string{fmt.Sprintf("Failed to list containers: %v", err)},
- }, err
+ result := &containertypes.ActionResult{
+ Success: false,
+ Errors: []string{fmt.Sprintf("Failed to list containers: %v", err)},
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
+ }
+ s.completeSystemContainerActivityInternal(ctx, activityID, "Starting all containers failed", result)
+ return result, err
}
- return s.performBatchContainerAction(ctx, containers, "start",
+ result := s.performBatchContainerAction(ctx, containers, "start",
func(c container.Summary) bool { return c.State != "running" },
func(ctx context.Context, id string) error {
return s.containerService.StartContainer(ctx, id, systemUser)
- }), nil
+ })
+ result.ActivityID = utils.StringPtrFromTrimmed(activityID)
+ s.completeSystemContainerActivityInternal(ctx, activityID, "Started all containers", result)
+ return result, nil
}
-func (s *SystemService) StartAllStoppedContainers(ctx context.Context) (*containertypes.ActionResult, error) {
+func (s *SystemService) StartAllStoppedContainers(ctx context.Context, environmentID string) (*containertypes.ActionResult, error) {
+ activityID := s.startSystemContainerActivityInternal(ctx, environmentID, models.ActivityTypeContainerStart, "Stopped containers", "Starting stopped containers")
containers, _, _, _, err := s.dockerService.GetAllContainers(ctx)
if err != nil {
- return &containertypes.ActionResult{
- Success: false,
- Errors: []string{fmt.Sprintf("Failed to list containers: %v", err)},
- }, err
+ result := &containertypes.ActionResult{
+ Success: false,
+ Errors: []string{fmt.Sprintf("Failed to list containers: %v", err)},
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
+ }
+ s.completeSystemContainerActivityInternal(ctx, activityID, "Starting stopped containers failed", result)
+ return result, err
}
- return s.performBatchContainerAction(ctx, containers, "start",
+ result := s.performBatchContainerAction(ctx, containers, "start",
func(c container.Summary) bool { return c.State == "exited" },
func(ctx context.Context, id string) error {
return s.containerService.StartContainer(ctx, id, systemUser)
- }), nil
+ })
+ result.ActivityID = utils.StringPtrFromTrimmed(activityID)
+ s.completeSystemContainerActivityInternal(ctx, activityID, "Started stopped containers", result)
+ return result, nil
}
-func (s *SystemService) StopAllContainers(ctx context.Context) (*containertypes.ActionResult, error) {
+func (s *SystemService) StopAllContainers(ctx context.Context, environmentID string) (*containertypes.ActionResult, error) {
+ activityID := s.startSystemContainerActivityInternal(ctx, environmentID, models.ActivityTypeContainerStop, "All containers", "Stopping all containers")
containers, _, _, _, err := s.dockerService.GetAllContainers(ctx)
if err != nil {
- return &containertypes.ActionResult{
- Success: false,
- Errors: []string{fmt.Sprintf("Failed to list containers: %v", err)},
- }, err
+ result := &containertypes.ActionResult{
+ Success: false,
+ Errors: []string{fmt.Sprintf("Failed to list containers: %v", err)},
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
+ }
+ s.completeSystemContainerActivityInternal(ctx, activityID, "Stopping all containers failed", result)
+ return result, err
}
- return s.performBatchContainerAction(ctx, containers, "stop",
+ result := s.performBatchContainerAction(ctx, containers, "stop",
func(c container.Summary) bool {
// Skip Arcane container
return !libupdater.IsArcaneContainer(c.Labels)
},
func(ctx context.Context, id string) error {
return s.containerService.StopContainer(ctx, id, systemUser)
- }), nil
+ })
+ result.ActivityID = utils.StringPtrFromTrimmed(activityID)
+ s.completeSystemContainerActivityInternal(ctx, activityID, "Stopped all containers", result)
+ return result, nil
+}
+
+func (s *SystemService) startSystemContainerActivityInternal(ctx context.Context, environmentID string, activityType models.ActivityType, resourceName, message string) string {
+ if s.activityService == nil {
+ return ""
+ }
+ resourceType := "system"
+ activity, err := s.activityService.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: environmentID,
+ Type: activityType,
+ ResourceType: &resourceType,
+ ResourceName: &resourceName,
+ Step: message,
+ LatestMessage: message,
+ Metadata: models.JSON{"scope": resourceName},
+ })
+ if err != nil {
+ slog.DebugContext(ctx, "failed to start system container activity", "type", activityType, "error", err)
+ return ""
+ }
+ return activity.ID
+}
+
+func (s *SystemService) completeSystemContainerActivityInternal(ctx context.Context, activityID, successMessage string, result *containertypes.ActionResult) {
+ if s.activityService == nil || activityID == "" || result == nil {
+ return
+ }
+
+ status := models.ActivityStatusSuccess
+ message := successMessage
+ var errMessage *string
+ if !result.Success || len(result.Errors) > 0 {
+ status = models.ActivityStatusFailed
+ message = strings.Join(result.Errors, "; ")
+ errMessage = &message
+ }
+
+ if _, err := s.activityService.CompleteActivity(context.WithoutCancel(ctx), activityID, status, message, errMessage); err != nil {
+ slog.DebugContext(ctx, "failed to complete system container activity", "activityId", activityID, "error", err)
+ }
}
func (s *SystemService) pruneContainersInternal(ctx context.Context, options system.PruneContainersOptions, result *system.PruneAllResult) error {
diff --git a/backend/internal/services/updater_service.go b/backend/internal/services/updater_service.go
index 45e210c94..d32b9e2d1 100644
--- a/backend/internal/services/updater_service.go
+++ b/backend/internal/services/updater_service.go
@@ -22,8 +22,10 @@ import (
"github.com/getarcaneapp/arcane/backend/internal/database"
"github.com/getarcaneapp/arcane/backend/internal/models"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane"
+ activitylib "github.com/getarcaneapp/arcane/backend/pkg/libarcane/activity"
libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/imageupdate"
projectspkg "github.com/getarcaneapp/arcane/backend/pkg/projects"
+ "github.com/getarcaneapp/arcane/backend/pkg/utils"
"github.com/getarcaneapp/arcane/types/updater"
)
@@ -40,6 +42,7 @@ type UpdaterService struct {
imageService *ImageService
notificationService *NotificationService
upgradeService selfUpgradeService
+ activityService *ActivityService
statusMu sync.RWMutex
updatingContainers map[string]bool
@@ -63,6 +66,7 @@ func NewUpdaterService(
imageSvc *ImageService,
notifications *NotificationService,
upgrade selfUpgradeService,
+ activityService *ActivityService,
) *UpdaterService {
return &UpdaterService{
db: db,
@@ -75,6 +79,7 @@ func NewUpdaterService(
imageService: imageSvc,
notificationService: notifications,
upgradeService: upgrade,
+ activityService: activityService,
updatingContainers: map[string]bool{},
updatingProjects: map[string]bool{},
}
@@ -85,9 +90,17 @@ func NewUpdaterService(
// actions without mutating containers or projects.
//
//nolint:gocognit
-func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*updater.Result, error) {
+func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (out *updater.Result, err error) {
start := time.Now()
- out := &updater.Result{Items: []updater.ResourceResult{}}
+ out = &updater.Result{Items: []updater.ResourceResult{}}
+ activityID := s.startAutoUpdateActivityInternal(ctx, dryRun)
+ out.ActivityID = utils.StringPtrFromTrimmed(activityID)
+ defer func() {
+ if out != nil {
+ out.ActivityID = utils.StringPtrFromTrimmed(activityID)
+ }
+ s.completeAutoUpdateActivityInternal(ctx, activityID, out, err)
+ }()
var records []models.ImageUpdateRecord
if err := s.db.WithContext(ctx).Where("has_update = ?", true).Find(&records).Error; err != nil {
@@ -95,6 +108,7 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*update
}
// debug: how many pending records and dryRun flag
slog.DebugContext(ctx, "ApplyPending: found pending image update records", "records", len(records), "dryRun", dryRun)
+ s.appendAutoUpdateActivityMessageInternal(ctx, activityID, fmt.Sprintf("Found %d pending image update records", len(records)), "Planning updates", 10)
if len(records) == 0 {
out.Duration = time.Since(start).String()
@@ -148,6 +162,7 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*update
}
if len(plans) == 0 {
+ s.appendAutoUpdateActivityMessageInternal(ctx, activityID, "No active resources need updates", "Planning updates", 100)
out.Duration = time.Since(start).String()
return out, nil
}
@@ -174,6 +189,7 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*update
for i := range plans {
p := plans[i]
+ s.appendAutoUpdateActivityMessageInternal(ctx, activityID, fmt.Sprintf("Checking update for %s", p.oldRef), "Checking image", 20)
item := updater.ResourceResult{
ResourceID: p.oldRef,
ResourceType: "image",
@@ -227,7 +243,10 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*update
}
if !skipPull {
- if err := s.imageService.PullImage(ctx, p.newRef, io.Discard, systemUser, nil); err != nil {
+ progressWriter := activitylib.NewWriter(ctx, s.activityService, activityID, io.Discard, "Pulling updated images")
+ err := s.imageService.PullImage(ctx, p.newRef, progressWriter, systemUser, nil)
+ activitylib.FlushWriter(progressWriter)
+ if err != nil {
item.Status = "failed"
item.Error = err.Error()
out.Failed++
@@ -271,6 +290,7 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*update
}
if !dryRun && (len(oldIDToNewRef) > 0 || len(oldRefToNewRef) > 0) {
+ s.appendAutoUpdateActivityMessageInternal(ctx, activityID, "Restarting containers that use updated images", "Restarting containers", 75)
results, err := s.restartContainersUsingOldIDs(ctx, oldIDToNewRef, oldRefToNewRef)
if err != nil {
slog.Warn("container restarts had errors", "err", err)
@@ -321,6 +341,7 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*update
}
if !dryRun && len(oldIDSet) > 0 {
+ s.appendAutoUpdateActivityMessageInternal(ctx, activityID, "Pruning old image IDs", "Pruning images", 90)
ids := make([]string, 0, len(oldIDSet))
for id := range oldIDSet {
ids = append(ids, id)
@@ -387,13 +408,108 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*update
return out, nil
}
+func (s *UpdaterService) startAutoUpdateActivityInternal(ctx context.Context, dryRun bool) string {
+ if s.activityService == nil {
+ return ""
+ }
+ resourceType := "system"
+ resourceName := "Auto update"
+ activity, err := s.activityService.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: "0",
+ Type: models.ActivityTypeAutoUpdate,
+ ResourceType: &resourceType,
+ ResourceName: &resourceName,
+ Step: "Planning updates",
+ LatestMessage: "Auto-update run started",
+ Metadata: models.JSON{"dryRun": dryRun},
+ })
+ if err != nil {
+ slog.DebugContext(ctx, "failed to start auto-update activity", "error", err)
+ return ""
+ }
+ return activity.ID
+}
+
+func (s *UpdaterService) startSingleContainerUpdateActivityInternal(ctx context.Context, containerID string) string {
+ if s.activityService == nil {
+ return ""
+ }
+ resourceType := "container"
+ resourceName := containerID
+ activity, err := s.activityService.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: "0",
+ Type: models.ActivityTypeAutoUpdate,
+ ResourceType: &resourceType,
+ ResourceID: &containerID,
+ ResourceName: &resourceName,
+ Step: "Updating container",
+ LatestMessage: "Container update started",
+ Metadata: models.JSON{"containerID": containerID},
+ })
+ if err != nil {
+ slog.DebugContext(ctx, "failed to start container update activity", "containerID", containerID, "error", err)
+ return ""
+ }
+ return activity.ID
+}
+
+func (s *UpdaterService) appendAutoUpdateActivityMessageInternal(ctx context.Context, activityID, message, step string, progress int) {
+ if s.activityService == nil || activityID == "" {
+ return
+ }
+ if step == "" {
+ step = message
+ }
+ if _, err := s.activityService.AppendMessage(ctx, activityID, AppendActivityMessageRequest{
+ Level: models.ActivityMessageLevelInfo,
+ Message: message,
+ Progress: &progress,
+ Step: step,
+ }); err != nil {
+ slog.DebugContext(ctx, "failed to append auto-update activity message", "activityId", activityID, "error", err)
+ }
+}
+
+func (s *UpdaterService) completeAutoUpdateActivityInternal(ctx context.Context, activityID string, result *updater.Result, applyErr error) {
+ if s.activityService == nil || activityID == "" {
+ return
+ }
+
+ status := models.ActivityStatusSuccess
+ message := "Auto-update run completed"
+ var errMessage *string
+ if applyErr != nil {
+ status = models.ActivityStatusFailed
+ errText := applyErr.Error()
+ errMessage = &errText
+ message = errText
+ } else if result != nil && result.Failed > 0 {
+ status = models.ActivityStatusFailed
+ errText := fmt.Sprintf("%d update action(s) failed", result.Failed)
+ errMessage = &errText
+ message = errText
+ }
+
+ if _, err := s.activityService.CompleteActivity(context.WithoutCancel(ctx), activityID, status, message, errMessage); err != nil {
+ slog.DebugContext(ctx, "failed to complete auto-update activity", "activityId", activityID, "error", err)
+ }
+}
+
// UpdateSingleContainer updates a single container by ID to the latest available image.
// It pulls the new image, stops the container, removes it, and recreates it with the new image.
//
//nolint:gocognit // single-container update flow is intentionally linear with explicit early exits for failure reporting
-func (s *UpdaterService) UpdateSingleContainer(ctx context.Context, containerID string) (*updater.Result, error) {
+func (s *UpdaterService) UpdateSingleContainer(ctx context.Context, containerID string) (out *updater.Result, err error) {
start := time.Now()
- out := &updater.Result{Items: []updater.ResourceResult{}}
+ out = &updater.Result{Items: []updater.ResourceResult{}}
+ activityID := s.startSingleContainerUpdateActivityInternal(ctx, containerID)
+ out.ActivityID = utils.StringPtrFromTrimmed(activityID)
+ defer func() {
+ if out != nil {
+ out.ActivityID = utils.StringPtrFromTrimmed(activityID)
+ }
+ s.completeAutoUpdateActivityInternal(ctx, activityID, out, err)
+ }()
slog.InfoContext(ctx, "UpdateSingleContainer: starting", "containerID", containerID)
dcli, err := s.dockerService.GetClient(ctx)
if err != nil {
diff --git a/backend/internal/services/updater_service_test.go b/backend/internal/services/updater_service_test.go
index a2669a5c9..950afa241 100644
--- a/backend/internal/services/updater_service_test.go
+++ b/backend/internal/services/updater_service_test.go
@@ -579,6 +579,24 @@ func setupUpdaterServiceTestDB(t *testing.T) *database.DB {
return &database.DB{DB: db}
}
+func TestUpdaterService_AppendAutoUpdateActivityMessageUsesExplicitStepInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityServiceTestDBInternal(t)
+ activityService := NewActivityService(db)
+ svc := &UpdaterService{activityService: activityService}
+ activityID := svc.startAutoUpdateActivityInternal(ctx, false)
+ require.NotEmpty(t, activityID)
+
+ svc.appendAutoUpdateActivityMessageInternal(ctx, activityID, "Found 5 pending image update records", "Planning updates", 10)
+
+ var activity models.Activity
+ require.NoError(t, db.WithContext(ctx).First(&activity, "id = ?", activityID).Error)
+ require.NotNil(t, activity.Progress)
+ assert.Equal(t, 10, *activity.Progress)
+ assert.Equal(t, "Found 5 pending image update records", activity.LatestMessage)
+ assert.Equal(t, "Planning updates", activity.Step)
+}
+
func TestUpdaterService_ClearImageUpdateRecordByID_AvoidsRepoCanonicalMismatch(t *testing.T) {
ctx := context.Background()
db := setupUpdaterServiceTestDB(t)
diff --git a/backend/internal/services/version_service.go b/backend/internal/services/version_service.go
index b508597f9..e688ad3b5 100644
--- a/backend/internal/services/version_service.go
+++ b/backend/internal/services/version_service.go
@@ -10,6 +10,7 @@ import (
"strings"
"time"
+ ref "github.com/distribution/reference"
"github.com/getarcaneapp/arcane/backend/buildables"
"github.com/getarcaneapp/arcane/backend/internal/config"
docker "github.com/getarcaneapp/arcane/backend/pkg/dockerutil"
@@ -19,7 +20,6 @@ import (
"github.com/getarcaneapp/arcane/types/version"
containertypes "github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
- ref "go.podman.io/image/v5/docker/reference"
"golang.org/x/mod/semver"
)
diff --git a/backend/internal/services/vulnerability_service.go b/backend/internal/services/vulnerability_service.go
index ef7ae244d..7bc73e8ea 100644
--- a/backend/internal/services/vulnerability_service.go
+++ b/backend/internal/services/vulnerability_service.go
@@ -29,6 +29,7 @@ import (
libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/imageupdate"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane/timeouts"
"github.com/getarcaneapp/arcane/backend/pkg/pagination"
+ "github.com/getarcaneapp/arcane/backend/pkg/utils"
"github.com/getarcaneapp/arcane/types/vulnerability"
"github.com/moby/moby/api/pkg/stdcopy"
containertypes "github.com/moby/moby/api/types/container"
@@ -79,6 +80,7 @@ type VulnerabilityService struct {
eventService *EventService
settingsService *SettingsService
notificationService *NotificationService
+ activityService *ActivityService
// scanLocks provides per-image locking to allow concurrent scans of different images
// while preventing duplicate scans of the same image
scanLocks sync.Map // map[string]*sync.Mutex
@@ -230,13 +232,14 @@ func (s *VulnerabilityService) getTrivyScanSlotChannelInternal(limit int) chan i
}
// NewVulnerabilityService creates a new VulnerabilityService instance
-func NewVulnerabilityService(db *database.DB, dockerService *DockerClientService, eventService *EventService, settingsService *SettingsService, notificationService *NotificationService) *VulnerabilityService {
+func NewVulnerabilityService(db *database.DB, dockerService *DockerClientService, eventService *EventService, settingsService *SettingsService, notificationService *NotificationService, activityService *ActivityService) *VulnerabilityService {
return &VulnerabilityService{
db: db,
dockerService: dockerService,
eventService: eventService,
settingsService: settingsService,
notificationService: notificationService,
+ activityService: activityService,
trivyScanSlots: nil,
}
}
@@ -271,14 +274,16 @@ func (s *VulnerabilityService) ScanImage(ctx context.Context, envID string, imag
"imageId", imageID,
"imageName", imageName,
)
+ activityID := s.startVulnerabilityScanActivityInternal(scanCtx, envID, imageID, imageName, &user)
s.setScanPhaseInternal(imageID, vulnerability.ScanPhaseCreatingContainer)
// Create pending scan record
pendingResult := &vulnerability.ScanResult{
- ImageID: imageID,
- ImageName: imageName,
- ScanTime: time.Now(),
- Status: vulnerability.ScanStatusScanning,
+ ImageID: imageID,
+ ImageName: imageName,
+ ScanTime: time.Now(),
+ Status: vulnerability.ScanStatusScanning,
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
}
s.applyScanPhaseToResultInternal(pendingResult)
if saveErr := s.saveScanResultWithRetryInternal(scanCtx, pendingResult, defaultScanSaveRetryAttempts, defaultScanSaveRetryDelay); saveErr != nil {
@@ -297,9 +302,9 @@ func (s *VulnerabilityService) ScanImage(ctx context.Context, envID string, imag
)
}
- go func(bgCtx context.Context, scanEnvID, imgID, imgName string, scanUser models.User) {
- s.scanImageInBackgroundInternal(bgCtx, scanEnvID, imgID, imgName, scanUser)
- }(scanCtx, envID, imageID, imageName, user)
+ go func(bgCtx context.Context, scanEnvID, imgID, imgName string, scanUser models.User, scanActivityID string) {
+ s.scanImageInBackgroundInternal(bgCtx, scanEnvID, imgID, imgName, scanUser, scanActivityID)
+ }(scanCtx, envID, imageID, imageName, user, activityID)
return pendingResult, nil
}
@@ -340,9 +345,10 @@ func (s *VulnerabilityService) markStaleScanIfNeeded(ctx context.Context, record
return true
}
-func (s *VulnerabilityService) scanImageInBackgroundInternal(ctx context.Context, envID string, imageID, imageName string, user models.User) {
+func (s *VulnerabilityService) scanImageInBackgroundInternal(ctx context.Context, envID string, imageID, imageName string, user models.User, activityID string) {
defer s.clearScanPhaseInternal(imageID)
s.setScanPhaseInternal(imageID, vulnerability.ScanPhaseCreatingContainer)
+ s.updateVulnerabilityScanActivityInternal(ctx, activityID, vulnerability.ScanPhaseCreatingContainer, 10, "Preparing vulnerability scanner")
slog.DebugContext(ctx,
"starting background vulnerability scan",
@@ -354,12 +360,14 @@ func (s *VulnerabilityService) scanImageInBackgroundInternal(ctx context.Context
trivyImage, err := s.ensureTrivyImageInternal(ctx)
if err != nil {
s.setScanPhaseInternal(imageID, vulnerability.ScanPhaseStoringResults)
+ s.updateVulnerabilityScanActivityInternal(ctx, activityID, vulnerability.ScanPhaseStoringResults, 90, "Unable to prepare vulnerability scanner")
result := &vulnerability.ScanResult{
- ImageID: imageID,
- ImageName: imageName,
- ScanTime: time.Now(),
- Status: vulnerability.ScanStatusFailed,
- Error: fmt.Sprintf("Trivy scanner is not available: %s", err.Error()),
+ ImageID: imageID,
+ ImageName: imageName,
+ ScanTime: time.Now(),
+ Status: vulnerability.ScanStatusFailed,
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
+ Error: fmt.Sprintf("Trivy scanner is not available: %s", err.Error()),
}
if saveErr := s.saveScanResultWithRetryInternal(ctx, result, defaultScanSaveRetryAttempts, defaultScanSaveRetryDelay); saveErr != nil {
slog.WarnContext(ctx, "failed to save scan result", "error", saveErr)
@@ -371,22 +379,27 @@ func (s *VulnerabilityService) scanImageInBackgroundInternal(ctx context.Context
"imageName", imageName,
"error", result.Error,
)
+ s.completeVulnerabilityScanActivityInternal(ctx, activityID, false, result.Error)
return
}
+ s.setScanPhaseInternal(imageID, vulnerability.ScanPhaseScanningImage)
+ s.updateVulnerabilityScanActivityInternal(ctx, activityID, vulnerability.ScanPhaseScanningImage, 45, "Scanning image for vulnerabilities")
startTime := time.Now()
result, err := s.runTrivyScan(ctx, trivyImage, imageName, imageID)
duration := time.Since(startTime).Milliseconds()
if err != nil {
s.setScanPhaseInternal(imageID, vulnerability.ScanPhaseStoringResults)
+ s.updateVulnerabilityScanActivityInternal(ctx, activityID, vulnerability.ScanPhaseStoringResults, 90, "Storing failed scan result")
failedResult := &vulnerability.ScanResult{
- ImageID: imageID,
- ImageName: imageName,
- ScanTime: time.Now(),
- Status: vulnerability.ScanStatusFailed,
- Error: err.Error(),
- Duration: duration,
+ ImageID: imageID,
+ ImageName: imageName,
+ ScanTime: time.Now(),
+ Status: vulnerability.ScanStatusFailed,
+ ActivityID: utils.StringPtrFromTrimmed(activityID),
+ Error: err.Error(),
+ Duration: duration,
}
if saveErr := s.saveScanResultWithRetryInternal(ctx, failedResult, defaultScanSaveRetryAttempts, defaultScanSaveRetryDelay); saveErr != nil {
slog.WarnContext(ctx, "failed to save failed scan result", "error", saveErr)
@@ -400,12 +413,15 @@ func (s *VulnerabilityService) scanImageInBackgroundInternal(ctx context.Context
"error", err,
)
s.logScanEvent(ctx, envID, imageID, imageName, user, false, err.Error())
+ s.completeVulnerabilityScanActivityInternal(ctx, activityID, false, err.Error())
return
}
result.Duration = duration
+ result.ActivityID = utils.StringPtrFromTrimmed(activityID)
s.ensureSummary(result)
s.setScanPhaseInternal(imageID, vulnerability.ScanPhaseStoringResults)
+ s.updateVulnerabilityScanActivityInternal(ctx, activityID, vulnerability.ScanPhaseStoringResults, 90, "Storing vulnerability results")
if saveErr := s.saveScanResultWithRetryInternal(ctx, result, defaultScanSaveRetryAttempts, defaultScanSaveRetryDelay); saveErr != nil {
slog.WarnContext(ctx, "failed to save scan result", "error", saveErr)
}
@@ -420,6 +436,69 @@ func (s *VulnerabilityService) scanImageInBackgroundInternal(ctx context.Context
)
s.logScanEvent(ctx, envID, imageID, imageName, user, true, "")
+ s.completeVulnerabilityScanActivityInternal(ctx, activityID, true, "")
+}
+
+func (s *VulnerabilityService) startVulnerabilityScanActivityInternal(ctx context.Context, envID, imageID, imageName string, user *models.User) string {
+ if s.activityService == nil {
+ return ""
+ }
+
+ resourceType := "image"
+ progress := 0
+ activity, err := s.activityService.StartActivity(ctx, StartActivityRequest{
+ EnvironmentID: envID,
+ Type: models.ActivityTypeVulnerabilityScan,
+ ResourceType: &resourceType,
+ ResourceID: &imageID,
+ ResourceName: &imageName,
+ StartedBy: user,
+ Progress: &progress,
+ Step: string(vulnerability.ScanPhaseCreatingContainer),
+ LatestMessage: "Vulnerability scan queued",
+ })
+ if err != nil {
+ slog.WarnContext(ctx, "failed to create vulnerability scan activity", "error", err, "imageId", imageID)
+ return ""
+ }
+ return activity.ID
+}
+
+func (s *VulnerabilityService) updateVulnerabilityScanActivityInternal(ctx context.Context, activityID string, phase vulnerability.ScanPhase, progress int, message string) {
+ if s.activityService == nil || activityID == "" {
+ return
+ }
+
+ if _, err := s.activityService.AppendMessage(ctx, activityID, AppendActivityMessageRequest{
+ Level: models.ActivityMessageLevelInfo,
+ Message: message,
+ Progress: &progress,
+ Step: string(phase),
+ }); err != nil {
+ slog.DebugContext(ctx, "failed to append vulnerability scan activity message", "activityId", activityID, "error", err)
+ }
+}
+
+func (s *VulnerabilityService) completeVulnerabilityScanActivityInternal(ctx context.Context, activityID string, success bool, errMessage string) {
+ if s.activityService == nil || activityID == "" {
+ return
+ }
+
+ status := models.ActivityStatusSuccess
+ message := "Vulnerability scan completed"
+ var errorPtr *string
+ if !success {
+ status = models.ActivityStatusFailed
+ message = "Vulnerability scan failed"
+ if strings.TrimSpace(errMessage) != "" {
+ errorPtr = &errMessage
+ message = errMessage
+ }
+ }
+
+ if _, err := s.activityService.CompleteActivity(context.WithoutCancel(ctx), activityID, status, message, errorPtr); err != nil {
+ slog.DebugContext(ctx, "failed to complete vulnerability scan activity", "activityId", activityID, "error", err)
+ }
}
// GetScanResult retrieves the most recent scan result for an image
diff --git a/backend/pkg/authz/catalog.go b/backend/pkg/authz/catalog.go
index 54205d6ea..2629d918a 100644
--- a/backend/pkg/authz/catalog.go
+++ b/backend/pkg/authz/catalog.go
@@ -191,6 +191,10 @@ var permissionCatalog = []PermissionCatalogResource{
{"build-workspaces", "Build Workspaces", PermissionScopeEnv, []PermissionCatalogAction{
{"manage", PermBuildWorkspacesManage, "Manage", ""},
}},
+ {"activities", "Activities", PermissionScopeEnv, []PermissionCatalogAction{
+ {"read", PermActivitiesRead, "Read", ""},
+ {"delete", PermActivitiesDelete, "Clear history", ""},
+ }},
}
// PermissionCatalog returns a defensive copy of the full permission catalog.
diff --git a/backend/pkg/authz/permissions.go b/backend/pkg/authz/permissions.go
index 5cd372a04..4eb9f7682 100644
--- a/backend/pkg/authz/permissions.go
+++ b/backend/pkg/authz/permissions.go
@@ -164,6 +164,9 @@ const (
PermVulnsManage = "vulnerabilities:manage"
PermBuildWorkspacesManage = "build-workspaces:manage"
+
+ PermActivitiesRead = "activities:read"
+ PermActivitiesDelete = "activities:delete"
)
// orgLevelPermissions is derived from the authz permission catalog. Env-scoped
@@ -273,6 +276,7 @@ func BuiltInEditorPermissions() []string {
PermImageUpdatesRead, PermImageUpdatesCheck,
PermVulnsRead, PermVulnsScan, PermVulnsManage,
PermBuildWorkspacesManage,
+ PermActivitiesRead, PermActivitiesDelete,
}
}
@@ -296,6 +300,7 @@ func BuiltInDeployerPermissions() []string {
PermSystemRead,
PermImageUpdatesRead, PermImageUpdatesCheck,
PermVulnsRead,
+ PermActivitiesRead,
}
}
@@ -324,6 +329,7 @@ func BuiltInViewerPermissions() []string {
PermSystemRead,
PermImageUpdatesRead,
PermVulnsRead,
+ PermActivitiesRead,
}
}
@@ -344,6 +350,7 @@ func BuiltInMonitorPermissions() []string {
PermSystemRead,
PermImageUpdatesRead,
PermVulnsRead,
+ PermActivitiesRead,
}
}
diff --git a/backend/pkg/fswatch/watcher.go b/backend/pkg/fswatch/watcher.go
index 5c8f46ced..1a17a5d6b 100644
--- a/backend/pkg/fswatch/watcher.go
+++ b/backend/pkg/fswatch/watcher.go
@@ -293,13 +293,7 @@ func (fw *Watcher) addExistingDirectoriesRecursiveInternal(path string, logicalP
return nil
}
- watchPath := fw.resolveWatchPathInternal(path)
- fw.watchAliases[watchPath] = filepath.Clean(logicalPath)
- if err := fw.watcher.Add(watchPath); err != nil {
- slog.Warn("Failed to add directory to watcher",
- "path", watchPath,
- "error", err)
- }
+ fw.addWatchPathInternal(path, logicalPath)
if fw.maxDepth > 0 && depth == fw.maxDepth {
return nil
@@ -325,19 +319,6 @@ func (fw *Watcher) addExistingDirectoriesRecursiveInternal(path string, logicalP
return nil
}
-func (fw *Watcher) resolveWatchPathInternal(path string) string {
- if !fw.followSymlinks {
- return path
- }
-
- resolvedPath, err := filepath.EvalSymlinks(path)
- if err != nil {
- return path
- }
-
- return resolvedPath
-}
-
func (fw *Watcher) logicalPathForWatchEventInternal(path string) string {
cleanPath := filepath.Clean(path)
bestWatchPath := ""
@@ -367,6 +348,26 @@ func (fw *Watcher) logicalPathForWatchEventInternal(path string) string {
return filepath.Join(bestLogicalPath, rel)
}
+func (fw *Watcher) addWatchPathInternal(path string, logicalPath string) {
+ watchPaths := []string{path}
+ if fw.followSymlinks {
+ if info, err := os.Lstat(path); err == nil && info.Mode()&os.ModeSymlink != 0 {
+ if resolvedPath, resolveErr := filepath.EvalSymlinks(path); resolveErr == nil && resolvedPath != path {
+ watchPaths = append(watchPaths, resolvedPath)
+ }
+ }
+ }
+
+ for _, watchPath := range watchPaths {
+ fw.watchAliases[filepath.Clean(watchPath)] = filepath.Clean(logicalPath)
+ if err := fw.watcher.Add(watchPath); err != nil {
+ slog.Warn("Failed to add directory to watcher",
+ "path", watchPath,
+ "error", err)
+ }
+ }
+}
+
func (fw *Watcher) dirDepth(path string) int {
cleanRoot := fw.watchedPath
cleanPath := filepath.Clean(path)
diff --git a/backend/pkg/libarcane/activity/handler.go b/backend/pkg/libarcane/activity/handler.go
new file mode 100644
index 000000000..cca3dcdac
--- /dev/null
+++ b/backend/pkg/libarcane/activity/handler.go
@@ -0,0 +1,122 @@
+package activity
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "log/slog"
+ "strings"
+
+ "github.com/getarcaneapp/arcane/backend/internal/models"
+ "github.com/getarcaneapp/arcane/backend/pkg/utils"
+)
+
+type HandlerOptions struct {
+ EnvironmentID string
+ Type models.ActivityType
+ ResourceType string
+ ResourceID string
+ ResourceName string
+ User *models.User
+ Step string
+ Message string
+ SuccessMessage string
+ Metadata models.JSON
+}
+
+func StartHandlerActivityForUser(
+ ctx context.Context,
+ activityService Service,
+ environmentID string,
+ activityType models.ActivityType,
+ resourceType string,
+ resourceID string,
+ resourceName string,
+ user *models.User,
+ step string,
+ message string,
+ metadata models.JSON,
+) string {
+ if activityService == nil {
+ return ""
+ }
+
+ activity, err := activityService.StartActivity(ctx, StartRequest{
+ EnvironmentID: environmentID,
+ Type: activityType,
+ ResourceType: utils.StringPtrFromTrimmed(resourceType),
+ ResourceID: utils.StringPtrFromTrimmed(resourceID),
+ ResourceName: utils.StringPtrFromTrimmed(resourceName),
+ StartedBy: user,
+ Step: step,
+ LatestMessage: message,
+ Metadata: metadata,
+ })
+ if err != nil {
+ slog.DebugContext(ctx, "failed to start background activity", "type", activityType, "error", err)
+ return ""
+ }
+ return activity.ID
+}
+
+func CompleteHandlerActivity(ctx context.Context, activityService Service, activityID string, successMessage string, err error) {
+ if activityService == nil || strings.TrimSpace(activityID) == "" {
+ return
+ }
+
+ status := models.ActivityStatusSuccess
+ var errMessage *string
+ finalMessage := successMessage
+ if err != nil {
+ status = models.ActivityStatusFailed
+ errText := err.Error()
+ errMessage = &errText
+ finalMessage = errText
+ }
+
+ activityCtx := context.WithoutCancel(ctx)
+ if _, completeErr := activityService.CompleteActivity(activityCtx, activityID, status, finalMessage, errMessage); completeErr != nil {
+ slog.DebugContext(activityCtx, "failed to complete background activity", "activityId", activityID, "error", completeErr)
+ }
+}
+
+func RunHandlerActivity(ctx context.Context, activityService Service, opts HandlerOptions, action func() error) (string, error) {
+ activityID := StartHandlerActivityForUser(
+ ctx,
+ activityService,
+ opts.EnvironmentID,
+ opts.Type,
+ opts.ResourceType,
+ opts.ResourceID,
+ opts.ResourceName,
+ opts.User,
+ opts.Step,
+ opts.Message,
+ opts.Metadata,
+ )
+
+ err := action()
+ CompleteHandlerActivity(ctx, activityService, activityID, opts.SuccessMessage, err)
+ return activityID, err
+}
+
+func WriteStartedLine(writer io.Writer, activityID string) {
+ if writer == nil || strings.TrimSpace(activityID) == "" {
+ return
+ }
+
+ payload := map[string]string{
+ "type": "activity",
+ "activityId": activityID,
+ }
+ if err := json.NewEncoder(writer).Encode(payload); err != nil {
+ _, _ = fmt.Fprintf(writer, `{"activityId":%q}`+"\n", activityID)
+ }
+}
+
+func FlushWriter(writer io.Writer) {
+ if flusher, ok := writer.(interface{ Flush() }); ok {
+ flusher.Flush()
+ }
+}
diff --git a/backend/pkg/libarcane/activity/requests.go b/backend/pkg/libarcane/activity/requests.go
new file mode 100644
index 000000000..a9f70e37f
--- /dev/null
+++ b/backend/pkg/libarcane/activity/requests.go
@@ -0,0 +1,47 @@
+package activity
+
+import (
+ "context"
+
+ "github.com/getarcaneapp/arcane/backend/internal/models"
+ activitytypes "github.com/getarcaneapp/arcane/types/activity"
+)
+
+type Service interface {
+ StartActivity(ctx context.Context, req StartRequest) (*activitytypes.Activity, error)
+ CompleteActivity(ctx context.Context, activityID string, status models.ActivityStatus, finalMessage string, errMessage *string, finalStep ...string) (*activitytypes.Activity, error)
+}
+
+type MessageAppender interface {
+ AppendMessage(ctx context.Context, activityID string, req AppendMessageRequest) (*activitytypes.Message, error)
+}
+
+type StartRequest struct {
+ EnvironmentID string
+ Type models.ActivityType
+ ResourceType *string
+ ResourceID *string
+ ResourceName *string
+ StartedBy *models.User
+ Step string
+ LatestMessage string
+ Progress *int
+ Metadata models.JSON
+}
+
+type UpdateRequest struct {
+ Status models.ActivityStatus
+ Progress *int
+ Step *string
+ LatestMessage *string
+ Error *string
+ Metadata models.JSON
+}
+
+type AppendMessageRequest struct {
+ Level models.ActivityMessageLevel
+ Message string
+ Payload models.JSON
+ Progress *int
+ Step string
+}
diff --git a/backend/pkg/libarcane/activity/writer.go b/backend/pkg/libarcane/activity/writer.go
new file mode 100644
index 000000000..9931d4fbc
--- /dev/null
+++ b/backend/pkg/libarcane/activity/writer.go
@@ -0,0 +1,438 @@
+package activity
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+ "strings"
+ "sync"
+
+ "github.com/getarcaneapp/arcane/backend/internal/models"
+)
+
+type Writer struct {
+ ctx context.Context
+ activityService MessageAppender
+ activityID string
+ writer io.Writer
+ defaultStep string
+ queueCh chan writerQueueItem
+
+ mu sync.Mutex
+ buffer []byte
+ layers map[string]layerProgress
+}
+
+const writerAppendQueueSize = 128
+
+type layerProgress struct {
+ current int64
+ total int64
+ status string
+}
+
+type writerAppendMessage struct {
+ level models.ActivityMessageLevel
+ message string
+ payload models.JSON
+ progress *int
+ step string
+}
+
+type writerQueueItem struct {
+ message *writerAppendMessage
+ flush chan struct{}
+}
+
+func NewWriter(ctx context.Context, activityService MessageAppender, activityID string, writer io.Writer, defaultStep string) io.Writer {
+ if activityService == nil || strings.TrimSpace(activityID) == "" {
+ if writer == nil {
+ return io.Discard
+ }
+ return writer
+ }
+ if existing, ok := writer.(*Writer); ok {
+ return existing
+ }
+ out := &Writer{
+ ctx: ctx,
+ activityService: activityService,
+ activityID: strings.TrimSpace(activityID),
+ writer: writer,
+ defaultStep: strings.TrimSpace(defaultStep),
+ queueCh: make(chan writerQueueItem, writerAppendQueueSize),
+ layers: map[string]layerProgress{},
+ }
+ go out.drainMessagesInternal(ctx)
+ return out
+}
+
+func (w *Writer) Write(p []byte) (int, error) {
+ if w.writer != nil {
+ if _, err := w.writer.Write(p); err != nil {
+ return 0, err
+ }
+ }
+
+ w.mu.Lock()
+ messages := []writerAppendMessage{}
+ w.buffer = append(w.buffer, p...)
+ for {
+ idx := bytes.IndexByte(w.buffer, '\n')
+ if idx < 0 {
+ break
+ }
+ line := strings.TrimSpace(string(w.buffer[:idx]))
+ w.buffer = w.buffer[idx+1:]
+ if message, ok := w.processLineInternal(line); ok {
+ messages = append(messages, message)
+ }
+ }
+ w.mu.Unlock()
+
+ for _, message := range messages {
+ w.enqueueMessageInternal(message)
+ }
+
+ return len(p), nil
+}
+
+func (w *Writer) Flush() {
+ if flusher, ok := w.writer.(http.Flusher); ok {
+ flusher.Flush()
+ }
+ flushDone := make(chan struct{})
+ select {
+ case w.queueCh <- writerQueueItem{flush: flushDone}:
+ case <-doneInternal(w.ctx):
+ return
+ default:
+ return
+ }
+ select {
+ case <-flushDone:
+ case <-doneInternal(w.ctx):
+ return
+ }
+}
+
+func (w *Writer) processLineInternal(line string) (writerAppendMessage, bool) {
+ if line == "" || w.activityService == nil || w.activityID == "" {
+ return writerAppendMessage{}, false
+ }
+
+ var payload map[string]any
+ if err := json.Unmarshal([]byte(line), &payload); err != nil {
+ return writerAppendMessage{
+ level: models.ActivityMessageLevelInfo,
+ message: line,
+ step: w.defaultStep,
+ }, true
+ }
+
+ message, level, step, progress := w.describePayloadInternal(payload)
+ if message == "" {
+ return writerAppendMessage{}, false
+ }
+ return writerAppendMessage{
+ level: level,
+ message: message,
+ payload: models.JSON(payload),
+ progress: progress,
+ step: step,
+ }, true
+}
+
+func (w *Writer) describePayloadInternal(payload map[string]any) (string, models.ActivityMessageLevel, string, *int) {
+ level := models.ActivityMessageLevelInfo
+ step := w.defaultStep
+
+ if errorValue, ok := payload["error"]; ok && errorValue != nil {
+ level = models.ActivityMessageLevelError
+ return valueToStringInternal(errorValue), level, step, nil
+ }
+
+ if typ := strings.TrimSpace(valueToStringInternal(payload["type"])); typ != "" {
+ if typ == "container" {
+ return containerEventMessageInternal(payload), level, step, nil
+ }
+ if phase := strings.TrimSpace(valueToStringInternal(payload["phase"])); phase != "" {
+ step = phaseStepInternal(typ, phase, step)
+ progress := phaseProgressInternal(phase, payload["progressDetail"])
+ return phaseMessageInternal(typ, phase, payload), level, step, progress
+ }
+ }
+
+ if stream := strings.TrimSpace(valueToStringInternal(payload["stream"])); stream != "" {
+ return stream, level, fallbackStepInternal(step, "Building image"), nil
+ }
+
+ status := strings.TrimSpace(valueToStringInternal(payload["status"]))
+ id := strings.TrimSpace(valueToStringInternal(payload["id"]))
+ progressText := strings.TrimSpace(valueToStringInternal(payload["progress"]))
+ progress := w.updateLayerProgressInternal(id, status, payload["progressDetail"])
+
+ if status != "" {
+ parts := []string{status}
+ if id != "" {
+ parts = append(parts, id)
+ }
+ if progressText != "" {
+ parts = append(parts, progressText)
+ }
+ return strings.Join(parts, " · "), level, statusStepInternal(status, step), progress
+ }
+
+ return "", level, step, nil
+}
+
+func (w *Writer) updateLayerProgressInternal(id, status string, rawDetail any) *int {
+ if id == "" {
+ return nil
+ }
+
+ layer := w.layers[id]
+ layer.status = status
+ if detail, ok := rawDetail.(map[string]any); ok {
+ layer.current = numberToInt64Internal(detail["current"])
+ layer.total = numberToInt64Internal(detail["total"])
+ }
+ w.layers[id] = layer
+
+ if len(w.layers) == 0 {
+ return nil
+ }
+
+ var weighted float64
+ for _, item := range w.layers {
+ statusLower := strings.ToLower(item.status)
+ switch {
+ case layerCompleteInternal(statusLower):
+ weighted += 1
+ case strings.Contains(statusLower, "extracting"):
+ weighted += 0.95
+ case strings.Contains(statusLower, "verifying"):
+ weighted += 0.92
+ case strings.Contains(statusLower, "download complete"):
+ weighted += 0.85
+ case item.total > 0:
+ weighted += min((float64(item.current)/float64(item.total))*0.85, 0.85)
+ case strings.Contains(statusLower, "downloading") || strings.Contains(statusLower, "pulling"):
+ weighted += 0.05
+ }
+ }
+
+ progress := int((weighted / float64(len(w.layers))) * 100)
+ if progress > 100 {
+ progress = 100
+ }
+ if progress < 0 {
+ progress = 0
+ }
+ return &progress
+}
+
+func (w *Writer) enqueueMessageInternal(message writerAppendMessage) {
+ select {
+ case w.queueCh <- writerQueueItem{message: &message}:
+ case <-doneInternal(w.ctx):
+ return
+ default:
+ return
+ }
+}
+
+func (w *Writer) drainMessagesInternal(ctx context.Context) {
+ for {
+ select {
+ case item := <-w.queueCh:
+ if item.flush != nil {
+ close(item.flush)
+ continue
+ }
+ if item.message != nil {
+ w.appendMessageInternal(ctx, *item.message)
+ }
+ case <-doneInternal(ctx):
+ return
+ }
+ }
+}
+
+func doneInternal(ctx context.Context) <-chan struct{} {
+ if ctx == nil {
+ return nil
+ }
+ return ctx.Done()
+}
+
+func (w *Writer) appendMessageInternal(ctx context.Context, message writerAppendMessage) {
+ if ctx == nil {
+ return
+ }
+ if _, err := w.activityService.AppendMessage(ctx, w.activityID, AppendMessageRequest{
+ Level: message.level,
+ Message: message.message,
+ Payload: message.payload,
+ Progress: message.progress,
+ Step: message.step,
+ }); err != nil {
+ return
+ }
+}
+
+func valueToStringInternal(value any) string {
+ switch typed := value.(type) {
+ case string:
+ return typed
+ case fmt.Stringer:
+ return typed.String()
+ case nil:
+ return ""
+ default:
+ return fmt.Sprint(typed)
+ }
+}
+
+func numberToInt64Internal(value any) int64 {
+ switch typed := value.(type) {
+ case float64:
+ return int64(typed)
+ case float32:
+ return int64(typed)
+ case int64:
+ return typed
+ case int:
+ return int64(typed)
+ case json.Number:
+ out, _ := typed.Int64()
+ return out
+ default:
+ return 0
+ }
+}
+
+func layerCompleteInternal(status string) bool {
+ return strings.Contains(status, "pull complete") ||
+ strings.Contains(status, "already exists") ||
+ strings.Contains(status, "downloaded newer image") ||
+ strings.Contains(status, "image is up to date")
+}
+
+func statusStepInternal(status, fallback string) string {
+ lower := strings.ToLower(status)
+ switch {
+ case strings.Contains(lower, "downloading") || strings.Contains(lower, "pulling"):
+ return "Downloading layers"
+ case strings.Contains(lower, "extracting"):
+ return "Extracting layers"
+ case strings.Contains(lower, "verifying") || strings.Contains(lower, "digest"):
+ return "Verifying image"
+ case strings.Contains(lower, "building"):
+ return "Building image"
+ }
+ return fallback
+}
+
+func phaseStepInternal(typ, phase, fallback string) string {
+ switch typ {
+ case "deploy":
+ switch phase {
+ case "begin":
+ return "Starting deployment"
+ case "complete":
+ return "Deployment complete"
+ default:
+ return "Deploying services"
+ }
+ case "build":
+ switch phase {
+ case "begin":
+ return "Starting build"
+ case "complete":
+ return "Build complete"
+ default:
+ return "Building image"
+ }
+ }
+ return fallback
+}
+
+func phaseMessageInternal(typ, phase string, payload map[string]any) string {
+ if status := strings.TrimSpace(valueToStringInternal(payload["status"])); status != "" {
+ return status
+ }
+ if service := strings.TrimSpace(valueToStringInternal(payload["service"])); service != "" {
+ return fmt.Sprintf("%s %s: %s", typ, phase, service)
+ }
+ return fmt.Sprintf("%s %s", typ, phase)
+}
+
+func phaseProgressInternal(phase string, rawDetail any) *int {
+ switch phase {
+ case "begin":
+ out := 5
+ return &out
+ case "complete":
+ out := 100
+ return &out
+ default:
+ return progressDetailPercentInternal(rawDetail)
+ }
+}
+
+func progressDetailPercentInternal(rawDetail any) *int {
+ detail, ok := rawDetail.(map[string]any)
+ if !ok {
+ return nil
+ }
+
+ current := numberToInt64Internal(detail["current"])
+ total := numberToInt64Internal(detail["total"])
+
+ var progress int64
+ switch {
+ case total > 0:
+ progress = (current * 100) / total
+ default:
+ progress = current
+ }
+
+ if progress < 0 {
+ progress = 0
+ }
+ if progress > 100 {
+ progress = 100
+ }
+
+ out := int(progress)
+ return &out
+}
+
+func containerEventMessageInternal(payload map[string]any) string {
+ service := strings.TrimSpace(valueToStringInternal(payload["service"]))
+ state := strings.TrimSpace(valueToStringInternal(payload["state"]))
+ status := strings.TrimSpace(valueToStringInternal(payload["status"]))
+
+ if service == "" {
+ service = "unknown"
+ }
+
+ if status != "" {
+ return fmt.Sprintf("Container %s: %s", service, status)
+ }
+ if state != "" {
+ return fmt.Sprintf("Container %s: %s", service, state)
+ }
+ return fmt.Sprintf("Container %s", service)
+}
+
+func fallbackStepInternal(value, fallback string) string {
+ if strings.TrimSpace(value) != "" {
+ return value
+ }
+ return fallback
+}
diff --git a/backend/pkg/libarcane/imageupdate/registry_http.go b/backend/pkg/libarcane/imageupdate/registry_http.go
index 79be592c9..bab7b7899 100644
--- a/backend/pkg/libarcane/imageupdate/registry_http.go
+++ b/backend/pkg/libarcane/imageupdate/registry_http.go
@@ -12,8 +12,8 @@ import (
"strings"
"time"
+ ref "github.com/distribution/reference"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane/registryauth"
- ref "go.podman.io/image/v5/docker/reference"
)
const defaultRegistryHost = "registry-1.docker.io"
diff --git a/backend/pkg/libarcane/registryauth/helpers.go b/backend/pkg/libarcane/registryauth/helpers.go
index 8bf6258f1..46ac6f9c9 100644
--- a/backend/pkg/libarcane/registryauth/helpers.go
+++ b/backend/pkg/libarcane/registryauth/helpers.go
@@ -5,9 +5,9 @@ import (
"sort"
"strings"
+ ref "github.com/distribution/reference"
dockerauthconfig "github.com/moby/moby/api/pkg/authconfig"
dockerregistry "github.com/moby/moby/api/types/registry"
- ref "go.podman.io/image/v5/docker/reference"
)
func GetRegistryAddress(imageRef string) (string, error) {
diff --git a/backend/pkg/projects/cmds.go b/backend/pkg/projects/cmds.go
index be825ee11..111719688 100644
--- a/backend/pkg/projects/cmds.go
+++ b/backend/pkg/projects/cmds.go
@@ -58,7 +58,11 @@ func ComposeRestart(ctx context.Context, proj *types.Project, services []string)
return err
}
defer func() { _ = c.Close() }()
- return c.svc.Restart(restartCtx, proj.Name, api.RestartOptions{Services: services})
+
+ progressWriter, _ := ctx.Value(ProgressWriterKey{}).(io.Writer)
+ return runWithContainerPolling(restartCtx, c.svc, proj.Name, progressWriter, func() error {
+ return c.svc.Restart(restartCtx, proj.Name, api.RestartOptions{Services: services})
+ })
}
func ComposePull(ctx context.Context, proj *types.Project, services []string) error {
@@ -92,7 +96,6 @@ func ComposeStop(ctx context.Context, proj *types.Project, services []string) er
if len(services) == 0 {
return nil
}
- // Detach from the HTTP request context. See #1209.
stopCtx, cancel := detachFromHTTPContextInternal(ctx)
defer cancel()
@@ -101,7 +104,11 @@ func ComposeStop(ctx context.Context, proj *types.Project, services []string) er
return err
}
defer func() { _ = c.Close() }()
- return c.svc.Stop(stopCtx, proj.Name, api.StopOptions{Services: services})
+
+ progressWriter, _ := ctx.Value(ProgressWriterKey{}).(io.Writer)
+ return runWithContainerPolling(stopCtx, c.svc, proj.Name, progressWriter, func() error {
+ return c.svc.Stop(stopCtx, proj.Name, api.StopOptions{Services: services})
+ })
}
func ComposeUp(ctx context.Context, proj *types.Project, services []string, removeOrphans bool, forceRecreate bool) error {
@@ -245,6 +252,69 @@ func deployPhaseFromSummary(cs api.ContainerSummary) string {
}
}
+func runWithContainerPolling(ctx context.Context, svc api.Compose, projectName string, progressWriter io.Writer, operation func() error) error {
+ if progressWriter == nil {
+ return operation()
+ }
+
+ pollCtx, cancel := context.WithCancel(ctx)
+ defer cancel()
+
+ pollDone := make(chan struct{})
+ go func() {
+ defer close(pollDone)
+ pollContainerStatus(pollCtx, svc, projectName, progressWriter)
+ }()
+
+ err := operation()
+ cancel()
+ <-pollDone
+ return err
+}
+
+func pollContainerStatus(ctx context.Context, svc api.Compose, projectName string, progressWriter io.Writer) {
+ ticker := time.NewTicker(300 * time.Millisecond)
+ defer ticker.Stop()
+
+ lastState := map[string]string{}
+
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ case <-ticker.C:
+ containers, err := svc.Ps(ctx, projectName, api.PsOptions{All: true})
+ if err != nil {
+ continue
+ }
+ for _, cs := range containers {
+ name := strings.TrimSpace(cs.Service)
+ if name == "" {
+ name = strings.TrimSpace(cs.Name)
+ }
+ if name == "" {
+ continue
+ }
+
+ state := string(cs.State)
+ sig := state + "|" + string(cs.Health) + "|" + strings.TrimSpace(cs.Status)
+ if lastState[name] == sig {
+ continue
+ }
+ lastState[name] = sig
+
+ writeJSONLine(progressWriter, map[string]any{
+ "type": "container",
+ "service": name,
+ "state": state,
+ "health": string(cs.Health),
+ "status": strings.TrimSpace(cs.Status),
+ })
+ }
+ }
+ }
+}
+
func ComposePs(ctx context.Context, proj *types.Project, services []string, all bool) ([]api.ContainerSummary, error) {
c, err := NewClient(ctx)
if err != nil {
@@ -265,7 +335,10 @@ func ComposeDown(ctx context.Context, proj *types.Project, removeVolumes bool) e
}
defer func() { _ = c.Close() }()
- return c.svc.Down(downCtx, proj.Name, api.DownOptions{RemoveOrphans: true, Volumes: removeVolumes})
+ progressWriter, _ := ctx.Value(ProgressWriterKey{}).(io.Writer)
+ return runWithContainerPolling(downCtx, c.svc, proj.Name, progressWriter, func() error {
+ return c.svc.Down(downCtx, proj.Name, api.DownOptions{RemoveOrphans: true, Volumes: removeVolumes})
+ })
}
func ComposeLogs(ctx context.Context, projectName string, out io.Writer, follow bool, tail string) error {
diff --git a/backend/pkg/scheduler/event_cleanup_job.go b/backend/pkg/scheduler/event_cleanup_job.go
index c49c7956f..08daff1ab 100644
--- a/backend/pkg/scheduler/event_cleanup_job.go
+++ b/backend/pkg/scheduler/event_cleanup_job.go
@@ -12,12 +12,14 @@ const EventCleanupJobName = "event-cleanup"
type EventCleanupJob struct {
eventService *services.EventService
+ activityService *services.ActivityService
settingsService *services.SettingsService
}
-func NewEventCleanupJob(eventService *services.EventService, settingsService *services.SettingsService) *EventCleanupJob {
+func NewEventCleanupJob(eventService *services.EventService, activityService *services.ActivityService, settingsService *services.SettingsService) *EventCleanupJob {
return &EventCleanupJob{
eventService: eventService,
+ activityService: activityService,
settingsService: settingsService,
}
}
@@ -47,6 +49,22 @@ func (j *EventCleanupJob) Run(ctx context.Context) {
slog.InfoContext(ctx, "Event cleanup job completed successfully",
"jobName", EventCleanupJobName,
"olderThan", olderThan.String())
+
+ if j.activityService != nil {
+ retentionDays := j.settingsService.GetIntSetting(ctx, "activityHistoryRetentionDays", 30)
+ maxEntries := j.settingsService.GetIntSetting(ctx, "activityHistoryMaxEntries", 1000)
+ deleted, err := j.activityService.PruneHistory(ctx, retentionDays, maxEntries)
+ if err != nil {
+ slog.ErrorContext(ctx, "Failed to prune activity history", "jobName", EventCleanupJobName, "error", err)
+ return
+ }
+
+ slog.InfoContext(ctx, "Activity history cleanup completed successfully",
+ "jobName", EventCleanupJobName,
+ "retentionDays", retentionDays,
+ "maxEntries", maxEntries,
+ "deleted", deleted)
+ }
}
func (j *EventCleanupJob) Reschedule(ctx context.Context) error {
diff --git a/backend/pkg/scheduler/scheduled_prune_job.go b/backend/pkg/scheduler/scheduled_prune_job.go
index 238609dd6..d2670b82d 100644
--- a/backend/pkg/scheduler/scheduled_prune_job.go
+++ b/backend/pkg/scheduler/scheduled_prune_job.go
@@ -70,11 +70,15 @@ func (j *ScheduledPruneJob) Run(ctx context.Context) {
"build_cache", req.BuildCache,
)
- result, err := j.systemService.PruneAll(ctx, req)
+ result, started, err := j.systemService.PruneAll(ctx, "0", req)
if err != nil {
slog.ErrorContext(ctx, "scheduled prune run failed", "error", err)
return
}
+ if !started {
+ slog.InfoContext(ctx, "scheduled prune run skipped; prune already in progress", "activityId", result.ActivityID)
+ return
+ }
slog.InfoContext(ctx, "scheduled prune run completed",
"success", result.Success,
diff --git a/backend/resources/migrations/postgres/055_add_activities.down.sql b/backend/resources/migrations/postgres/055_add_activities.down.sql
new file mode 100644
index 000000000..58d060bf5
--- /dev/null
+++ b/backend/resources/migrations/postgres/055_add_activities.down.sql
@@ -0,0 +1,2 @@
+DROP TABLE IF EXISTS activity_messages;
+DROP TABLE IF EXISTS activities;
diff --git a/backend/resources/migrations/postgres/055_add_activities.up.sql b/backend/resources/migrations/postgres/055_add_activities.up.sql
new file mode 100644
index 000000000..728f41a72
--- /dev/null
+++ b/backend/resources/migrations/postgres/055_add_activities.up.sql
@@ -0,0 +1,40 @@
+CREATE TABLE activities (
+ id TEXT PRIMARY KEY,
+ created_at TIMESTAMPTZ NOT NULL,
+ updated_at TIMESTAMPTZ,
+ environment_id TEXT NOT NULL,
+ type TEXT NOT NULL,
+ status TEXT NOT NULL,
+ resource_type TEXT,
+ resource_id TEXT,
+ resource_name TEXT,
+ progress INTEGER,
+ step TEXT,
+ latest_message TEXT,
+ started_by_user_id TEXT,
+ started_by_username TEXT,
+ started_by_display_name TEXT,
+ started_at TIMESTAMPTZ NOT NULL,
+ ended_at TIMESTAMPTZ,
+ duration_ms BIGINT,
+ error TEXT,
+ metadata TEXT
+);
+
+CREATE INDEX idx_activities_environment_status_updated ON activities(environment_id, status, updated_at);
+CREATE INDEX idx_activities_environment_started ON activities(environment_id, started_at);
+CREATE INDEX idx_activities_type ON activities(type);
+CREATE INDEX idx_activities_resource ON activities(resource_type, resource_id);
+CREATE INDEX idx_activities_started_by_user_id ON activities(started_by_user_id);
+
+CREATE TABLE activity_messages (
+ id TEXT PRIMARY KEY,
+ created_at TIMESTAMPTZ NOT NULL,
+ updated_at TIMESTAMPTZ,
+ activity_id TEXT NOT NULL REFERENCES activities(id) ON DELETE CASCADE,
+ level TEXT NOT NULL,
+ message TEXT NOT NULL,
+ payload TEXT
+);
+
+CREATE INDEX idx_activity_messages_activity_created ON activity_messages(activity_id, created_at);
diff --git a/backend/resources/migrations/sqlite/055_add_activities.down.sql b/backend/resources/migrations/sqlite/055_add_activities.down.sql
new file mode 100644
index 000000000..58d060bf5
--- /dev/null
+++ b/backend/resources/migrations/sqlite/055_add_activities.down.sql
@@ -0,0 +1,2 @@
+DROP TABLE IF EXISTS activity_messages;
+DROP TABLE IF EXISTS activities;
diff --git a/backend/resources/migrations/sqlite/055_add_activities.up.sql b/backend/resources/migrations/sqlite/055_add_activities.up.sql
new file mode 100644
index 000000000..03a95b719
--- /dev/null
+++ b/backend/resources/migrations/sqlite/055_add_activities.up.sql
@@ -0,0 +1,41 @@
+CREATE TABLE activities (
+ id TEXT PRIMARY KEY,
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME,
+ environment_id TEXT NOT NULL,
+ type TEXT NOT NULL,
+ status TEXT NOT NULL,
+ resource_type TEXT,
+ resource_id TEXT,
+ resource_name TEXT,
+ progress INTEGER,
+ step TEXT,
+ latest_message TEXT,
+ started_by_user_id TEXT,
+ started_by_username TEXT,
+ started_by_display_name TEXT,
+ started_at DATETIME NOT NULL,
+ ended_at DATETIME,
+ duration_ms INTEGER,
+ error TEXT,
+ metadata TEXT
+);
+
+CREATE INDEX idx_activities_environment_status_updated ON activities(environment_id, status, updated_at);
+CREATE INDEX idx_activities_environment_started ON activities(environment_id, started_at);
+CREATE INDEX idx_activities_type ON activities(type);
+CREATE INDEX idx_activities_resource ON activities(resource_type, resource_id);
+CREATE INDEX idx_activities_started_by_user_id ON activities(started_by_user_id);
+
+CREATE TABLE activity_messages (
+ id TEXT PRIMARY KEY,
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME,
+ activity_id TEXT NOT NULL,
+ level TEXT NOT NULL,
+ message TEXT NOT NULL,
+ payload TEXT,
+ FOREIGN KEY(activity_id) REFERENCES activities(id) ON DELETE CASCADE
+);
+
+CREATE INDEX idx_activity_messages_activity_created ON activity_messages(activity_id, created_at);
diff --git a/cli/pkg/containers/cmd.go b/cli/pkg/containers/cmd.go
index 40b1ffa84..312e30f8b 100644
--- a/cli/pkg/containers/cmd.go
+++ b/cli/pkg/containers/cmd.go
@@ -281,7 +281,7 @@ var containersStartCmd = &cobra.Command{
}
defer func() { _ = resp.Body.Close() }()
- var result base.ApiResponse[container.ActionResult]
+ var result base.ApiResponse[base.MessageResponse]
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return fmt.Errorf("failed to parse response: %w", err)
}
@@ -323,7 +323,7 @@ var containersStopCmd = &cobra.Command{
}
defer func() { _ = resp.Body.Close() }()
- var result base.ApiResponse[container.ActionResult]
+ var result base.ApiResponse[base.MessageResponse]
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return fmt.Errorf("failed to parse response: %w", err)
}
@@ -365,7 +365,7 @@ var containersRestartCmd = &cobra.Command{
}
defer func() { _ = resp.Body.Close() }()
- var result base.ApiResponse[container.ActionResult]
+ var result base.ApiResponse[base.MessageResponse]
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return fmt.Errorf("failed to parse response: %w", err)
}
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index 7368f8b6e..cef1c449a 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -921,6 +921,9 @@
"swarm_service_form_env_key_placeholder": "KEY",
"swarm_service_form_key_placeholder": "key",
"swarm_service_form_value_placeholder": "value",
+ "swarm_node_label_key": "Key",
+ "swarm_node_label_reserved_prefixes": "Prefixes 'engine.labels' and 'com.docker.swarm' are reserved for system use.",
+ "swarm_node_label_value": "Value",
"swarm_service_form_mount_type_volume": "Volume",
"swarm_service_form_mount_type_bind": "Bind",
"swarm_service_form_source_placeholder": "source",
@@ -1970,6 +1973,76 @@
"sidebar_version": "{version}",
"sidebar_update_available": "Update available",
"sidebar_update_available_tooltip": "Update available: {version}",
+ "_comment_activity_center": "=== ACTIVITY CENTER ===",
+ "activity_center_title": "Activity Center",
+ "activity_center_open": "Open activity center",
+ "activity_active_count": "{count} active",
+ "activity_count_many": "9+",
+ "activity_filter_completed": "Completed",
+ "activity_status_queued": "Queued",
+ "activity_status_cancelled": "Cancelled",
+ "activity_type_image_pull": "Image Pull",
+ "activity_type_image_build": "Image Build",
+ "activity_type_image_update_check": "Image Update Check",
+ "activity_type_project_pull": "Project Pull",
+ "activity_type_project_build": "Project Build",
+ "activity_type_project_deploy": "Project Deploy",
+ "activity_type_project_redeploy": "Project Redeploy",
+ "activity_type_project_down": "Project Down",
+ "activity_type_project_restart": "Project Restart",
+ "activity_type_project_destroy": "Project Destroy",
+ "activity_type_container_start": "Container Start",
+ "activity_type_container_stop": "Container Stop",
+ "activity_type_container_restart": "Container Restart",
+ "activity_type_container_redeploy": "Container Redeploy",
+ "activity_type_container_delete": "Container Delete",
+ "activity_type_vulnerability_scan": "Vulnerability Scan",
+ "activity_type_auto_update": "Auto Update",
+ "activity_type_system_prune": "System Prune",
+ "activity_type_resource_action": "Resource Action",
+ "activity_unknown_target": "Unknown target",
+ "activity_no_message": "No message yet",
+ "activity_progress_percent": "{progress}%",
+ "activity_empty_title": "No activity here",
+ "activity_empty_description": "Background work will appear here as it starts.",
+ "activity_step_unknown": "Waiting for the next step",
+ "activity_duration": "Duration",
+ "activity_duration_ms": "{ms}ms",
+ "activity_duration_seconds": "{seconds}s",
+ "activity_duration_minutes": "{minutes}m {seconds}s",
+ "activity_output_title": "Output",
+ "activity_copy_output": "Copy Output",
+ "activity_output_loading": "Loading output…",
+ "activity_output_load_failed": "Failed to load activity output",
+ "activity_output_empty": "No output has been recorded for this activity yet.",
+ "activity_stream_error": "Lost connection to activity stream",
+ "activity_select_prompt_title": "Select an activity",
+ "activity_select_prompt": "Choose a background task to inspect its progress and recent output.",
+ "activity_view_activity": "View Activity",
+ "activity_source_environment": "Source environment",
+ "activity_started_by": "Started by {user}",
+ "activity_started_by_label": "Started by",
+ "activity_clear_history": "Clear history",
+ "activity_clear_history_title": "Clear activity history?",
+ "activity_clear_history_message": "Completed, failed, and cancelled entries for the selected environment will be deleted. Running activity will stay visible.",
+ "activity_clear_history_confirm": "Clear History",
+ "activity_clear_history_success": "Activity history cleared",
+ "activity_clear_history_failed": "Failed to clear activity history",
+ "activity_settings_title": "Activity",
+ "activity_settings_description": "Configure Activity Center history retention for each environment.",
+ "activity_settings_saved": "Activity settings saved",
+ "activity_history_section_title": "History Retention",
+ "activity_history_retention_days": "Retention Days",
+ "activity_history_retention_days_description": "Delete completed Activity Center entries older than this many days.",
+ "activity_history_retention_days_placeholder": "30",
+ "activity_history_retention_days_help": "Set to 0 to disable age-based cleanup.",
+ "activity_history_max_entries": "Maximum Entries",
+ "activity_history_max_entries_description": "Keep this many completed Activity Center entries per environment.",
+ "activity_history_max_entries_placeholder": "1000",
+ "activity_history_max_entries_help": "Set to 0 to disable count-based cleanup.",
+ "activity_scan_phase_creating_container": "Creating container",
+ "activity_scan_phase_scanning_image": "Scanning image",
+ "activity_scan_phase_storing_results": "Storing results",
"_comment_version_info": "=== VERSION INFO DIALOG ===",
"version_info_title": "About Arcane",
"version_info_version": "Version",
diff --git a/frontend/src/lib/components/action-buttons.svelte b/frontend/src/lib/components/action-buttons.svelte
index dd79913f6..79d550de4 100644
--- a/frontend/src/lib/components/action-buttons.svelte
+++ b/frontend/src/lib/components/action-buttons.svelte
@@ -7,7 +7,6 @@
import { handleApiResultWithCallbacks } from '$lib/utils/api';
import { ArcaneButton } from '$lib/components/arcane-button/index.js';
import DeploySplitButton from '$lib/components/deploy-split-button/deploy-split-button.svelte';
- import ProgressPopover from '$lib/components/progress-popover.svelte';
import * as DropdownMenu from '$lib/components/ui/dropdown-menu/index.js';
import { m } from '$lib/paraglide/messages';
import settingsStore from '$lib/stores/config-store';
@@ -15,9 +14,7 @@
import { containerService, type ContainerDetailsResponse } from '$lib/services/container-service';
import { projectService, type DeployProjectOptions } from '$lib/services/project-service';
import type { Project } from '$lib/types/swarm';
- import { isDownloadingLine, calculateOverallProgress, areAllLayersComplete } from '$lib/utils/docker';
- import { sanitizeLogText } from '$lib/utils/formatting';
- import { EllipsisIcon, DownloadIcon, HammerIcon } from '$lib/icons';
+ import { EllipsisIcon } from '$lib/icons';
import { createMutation } from '@tanstack/svelte-query';
import { hasPermission } from '$lib/utils/auth';
import { environmentStore } from '$lib/stores/environment.store.svelte';
@@ -38,7 +35,6 @@
let {
id,
- name,
type = 'container',
itemState = 'stopped',
desktopVariant = 'labels',
@@ -107,8 +103,8 @@
stop: !!(isLoading.stop || loading?.stop || stopLoading),
restart: !!(isLoading.restart || loading?.restart || restartLoading),
remove: !!(isLoading.remove || loading?.remove || removeLoading),
- pulling: !!(isLoading.pull || loading?.pull),
- building: !!(isLoading.build || loading?.build),
+ pull: !!(isLoading.pull || loading?.pull),
+ build: !!(isLoading.build || loading?.build),
redeploy: !!(isLoading.redeploy || loading?.redeploy || redeployLoading),
validating: !!(isLoading.validating || loading?.validating),
refresh: !!(isLoading.refresh || loading?.refresh || refreshLoading)
@@ -123,11 +119,7 @@
: projectService.deployProject(id, deployOptionsStore.getRequestOptions())
),
onMutate: () => setLoading('start', true),
- onSettled: () => {
- if (!deployPulling) {
- setLoading('start', false);
- }
- }
+ onSettled: () => setLoading('start', false)
}));
const stopMutation = createMutation(() => ({
@@ -175,21 +167,6 @@
onSettled: () => setLoading('refresh', false)
}));
- let pullPopoverOpen = $state(false);
- let buildPopoverOpen = $state(false);
- let deployPullPopoverOpen = $state(false);
- let projectPulling = $state(false); // only for Project Pull button/popover
- let projectBuilding = $state(false); // only for Project Build button/popover
- let deployPulling = $state(false); // only for Deploy popover
- let pullProgress = $state(0);
- let pullStatusText = $state('');
- let pullError = $state('');
- let layerProgress = $state<Record<string, { current: number; total: number; status: string }>>({});
- let buildOutputLines = $state<string[]>([]);
- let deployProgressPhase = $state<'pull' | 'build' | 'deploy'>('deploy');
- let deployServiceProgress = $state<Record<string, { phase: string; health?: string; state?: string; status?: string }>>({});
- let deployLastNonWaitingStatus = $state('');
-
const isRunning = $derived(itemState === 'running' || (type === 'project' && itemState === 'partially running'));
const projectHasBuildDirective = $derived(type === 'project' && hasBuildDirective);
@@ -228,20 +205,6 @@
}
return configuredProvider;
});
- const deployPopoverTitle = $derived.by(() => {
- switch (deployProgressPhase) {
- case 'build':
- return m.progress_building_images();
- case 'pull':
- return m.progress_pulling_images();
- default:
- return m.progress_deploying_project();
- }
- });
- const deployPopoverIcon = $derived(deployProgressPhase === 'build' ? HammerIcon : DownloadIcon);
- const deployPopoverLayers = $derived.by(() =>
- deployProgressPhase === 'pull' || deployProgressPhase === 'build' ? layerProgress : {}
- );
// Tailwind xl breakpoint is 1280px. We use this to avoid mounting two desktop variants at once
// (which would duplicate portaled popovers when the same `open` state is bound twice).
@@ -268,119 +231,6 @@
};
});
- function resetPullState() {
- pullProgress = 0;
- pullStatusText = '';
- pullError = '';
- layerProgress = {};
- buildOutputLines = [];
- deployProgressPhase = 'deploy';
- deployServiceProgress = {};
- deployLastNonWaitingStatus = '';
- }
-
- function appendBuildOutputLine(rawStatus: unknown, rawService?: unknown) {
- const status = sanitizeLogText(String(rawStatus ?? ''));
- if (!status) return;
-
- const service = sanitizeLogText(String(rawService ?? ''));
- const line = service ? `[${service}] ${status}` : status;
-
- if (buildOutputLines.length > 0 && buildOutputLines[buildOutputLines.length - 1] === line) {
- return;
- }
-
- buildOutputLines = [...buildOutputLines.slice(-149), line];
- }
-
- function deriveDeployStatusText(): string {
- const entries = Object.entries(deployServiceProgress);
- if (entries.length === 0) return m.progress_deploy_starting();
-
- const waiting = entries.filter(([_, v]) => v.phase === 'service_waiting_healthy').sort(([a], [b]) => a.localeCompare(b));
- const firstWaiting = waiting[0];
- if (firstWaiting) {
- const [service, v] = firstWaiting;
- const health = String(v.health ?? '').trim();
- return health
- ? m.progress_deploy_waiting_for_service_with_health({ service, health })
- : m.progress_deploy_waiting_for_service({ service });
- }
-
- const stateIssues = entries
- .filter(([_, v]) => v.phase === 'service_state' && (v.state ?? '').toLowerCase() !== 'running')
- .sort(([a], [b]) => a.localeCompare(b));
- const firstStateIssue = stateIssues[0];
- if (firstStateIssue) {
- const [service, v] = firstStateIssue;
- return m.progress_deploy_service_state({ service, state: String(v.state ?? '') });
- }
-
- return deployLastNonWaitingStatus || m.progress_deploy_starting();
- }
-
- function updatePullProgress() {
- pullProgress = calculateOverallProgress(layerProgress);
- }
-
- function updateLayerProgressFromStreamData(data: any) {
- const layerId = String(data?.id ?? '').trim();
- if (!layerId) return;
-
- const currentLayer = layerProgress[layerId] || { current: 0, total: 0, status: '' };
- if (data?.status) {
- currentLayer.status = String(data.status);
- }
-
- if (data?.progressDetail) {
- const { current, total } = data.progressDetail;
- if (typeof current === 'number') currentLayer.current = current;
- if (typeof total === 'number') currentLayer.total = total;
- }
-
- layerProgress[layerId] = currentLayer;
- updatePullProgress();
- }
-
- function handleBuildStreamLine(
- data: any,
- errorFallback: string,
- errorFormatter: (message: string) => string,
- onError?: (message: string) => void
- ): boolean {
- if (!data) return false;
-
- if (data.phase === 'begin') {
- pullStatusText = m.progress_building_images_starting();
- appendBuildOutputLine(m.build_phase_started(), data.service);
- }
-
- if (data.status) {
- pullStatusText = String(data.status);
- appendBuildOutputLine(data.status, data.service);
- }
-
- if (data.id) {
- updateLayerProgressFromStreamData(data);
- }
-
- if (data.phase === 'complete') {
- pullStatusText = m.build_completed();
- pullProgress = 100;
- appendBuildOutputLine(m.build_phase_completed(), data.service);
- }
-
- if (data.error) {
- const errMsg = typeof data.error === 'string' ? data.error : data.error.message || errorFallback;
- pullError = errMsg;
- pullStatusText = errorFormatter(errMsg);
- onError?.(errMsg);
- return true;
- }
-
- return false;
- }
-
async function handleRefresh() {
if (!onRefresh) return;
await refreshMutation.mutateAsync();
@@ -409,11 +259,6 @@
type: type
}),
onSuccess: async () => {
- toast.success(
- type === 'project'
- ? m.common_destroyed_success({ type: m.project() })
- : m.common_removed_success({ type: m.container() })
- );
await invalidateAll();
goto(type === 'project' ? '/projects' : '/containers');
}
@@ -441,9 +286,6 @@
result,
message: m.common_action_failed_with_type({ action: m.common_redeploy(), type }),
onSuccess: async (data) => {
- toast.success(
- type === 'container' ? m.container_redeploy_success() : m.common_redeploy_success({ type: name || type })
- );
const containerData = data as ContainerDetailsResponse;
if (type === 'container' && containerData?.data?.id) {
goto(`/containers/${containerData.data.id}`);
@@ -467,233 +309,26 @@
message: m.common_action_failed_with_type({ action: m.common_start(), type }),
onSuccess: async () => {
itemState = 'running';
- toast.success(m.common_started_success({ type: name || type }));
onActionComplete('running');
}
});
}
async function handleDeploy(options?: DeployProjectOptions) {
- resetPullState();
setLoading('start', true);
- let openedPopover = false;
- let hadError = false;
- let deployPhaseStarted = false;
- let buildPhaseStarted = false;
-
- // Always open the popover for deploy so we can show health-wait status even
- // when there is nothing to pull.
- deployPullPopoverOpen = true;
- deployPulling = true;
- deployProgressPhase = 'deploy';
- pullStatusText = m.progress_deploy_starting();
- openedPopover = true;
try {
- const handleDeployLine = (deployData: any) => {
- if (!deployData) return;
-
- if (deployData.type === 'build') {
- deployProgressPhase = 'build';
- if (!buildPhaseStarted) {
- buildPhaseStarted = true;
- pullProgress = 0;
- layerProgress = {};
- pullError = '';
- deployServiceProgress = {};
- deployLastNonWaitingStatus = '';
- }
-
- if (
- handleBuildStreamLine(
- deployData,
- m.progress_deploy_failed(),
- (errMsg) => m.progress_deploy_failed_with_error({ error: errMsg }),
- () => {
- hadError = true;
- deployPulling = false;
- }
- )
- ) {
- return;
- }
- return;
- }
-
- // Pull progress lines can be streamed by backend /up before deploy when
- // image policy requires pulling (missing/always/refresh).
- if (deployData.type !== 'deploy') {
- if (isDownloadingLine(deployData)) {
- deployProgressPhase = 'pull';
- pullStatusText = m.images_pull_initiating();
- }
-
- if (deployData.error) {
- const errMsg =
- typeof deployData.error === 'string' ? deployData.error : deployData.error.message || m.images_pull_stream_error();
- pullError = errMsg;
- pullStatusText = m.images_pull_failed_with_error({ error: errMsg });
- hadError = true;
- deployPulling = false;
- return;
- }
-
- if (deployData.status) pullStatusText = deployData.status;
-
- if (deployData.id) {
- deployProgressPhase = 'pull';
- const currentLayer = layerProgress[deployData.id] || { current: 0, total: 0, status: '' };
- currentLayer.status = deployData.status || currentLayer.status;
- if (deployData.progressDetail) {
- const { current, total } = deployData.progressDetail;
- if (typeof current === 'number') currentLayer.current = current;
- if (typeof total === 'number') currentLayer.total = total;
- }
- layerProgress[deployData.id] = currentLayer;
- }
-
- if (deployProgressPhase === 'pull') {
- updatePullProgress();
- }
- return;
- }
-
- // First deploy status line: switch UI from pull -> deploy.
- if (!deployPhaseStarted) {
- deployPhaseStarted = true;
- deployProgressPhase = 'deploy';
- pullProgress = 0;
- layerProgress = {};
- pullError = '';
- deployServiceProgress = {};
- deployLastNonWaitingStatus = '';
- }
-
- // Keep the popover in "loading" state during deployment.
- deployPulling = true;
- if (deployData.type === 'deploy') {
- switch (deployData.phase) {
- case 'begin':
- pullStatusText = m.progress_deploy_starting();
- break;
- case 'service_waiting_healthy': {
- const service = String(deployData.service ?? '').trim();
- if (service) {
- deployServiceProgress[service] = {
- phase: 'service_waiting_healthy',
- health: String(deployData.health ?? '')
- };
- pullStatusText = deriveDeployStatusText();
- }
- break;
- }
- case 'service_healthy':
- {
- const service = String(deployData.service ?? '').trim();
- if (service) {
- deployServiceProgress[service] = {
- phase: 'service_healthy',
- health: String(deployData.health ?? ''),
- state: String(deployData.state ?? ''),
- status: String(deployData.status ?? '')
- };
- deployLastNonWaitingStatus = m.progress_deploy_service_healthy({ service });
- pullStatusText = deriveDeployStatusText();
- }
- }
- break;
- case 'service_state':
- {
- const service = String(deployData.service ?? '').trim();
- if (service) {
- deployServiceProgress[service] = {
- phase: 'service_state',
- state: String(deployData.state ?? ''),
- health: String(deployData.health ?? ''),
- status: String(deployData.status ?? '')
- };
- deployLastNonWaitingStatus = m.progress_deploy_service_state({
- service,
- state: String(deployData.state ?? '')
- });
- pullStatusText = deriveDeployStatusText();
- }
- }
- break;
- case 'service_status':
- {
- const service = String(deployData.service ?? '').trim();
- if (service) {
- deployServiceProgress[service] = {
- phase: 'service_status',
- status: String(deployData.status ?? ''),
- state: String(deployData.state ?? ''),
- health: String(deployData.health ?? '')
- };
- deployLastNonWaitingStatus = m.progress_deploy_service_status({
- service,
- status: String(deployData.status ?? '')
- });
- pullStatusText = deriveDeployStatusText();
- }
- }
- break;
- case 'complete':
- pullStatusText = m.progress_deploy_completed();
- break;
- default:
- break;
- }
- } else if (deployData.status) {
- // fallback for unexpected payloads
- pullStatusText = String(deployData.status);
- }
-
- if (deployData.error) {
- const errMsg =
- typeof deployData.error === 'string' ? deployData.error : deployData.error.message || m.progress_deploy_failed();
- pullError = errMsg;
- pullStatusText = m.progress_deploy_failed_with_error({ error: errMsg });
- hadError = true;
- deployPulling = false;
- return;
- }
-
- // If we got "complete", stop the loading state
- if (deployData.type === 'deploy' && deployData.phase === 'complete') {
- deployPulling = false;
- pullProgress = 100;
- }
- };
-
- await projectService.deployProject(id, handleDeployLine, options ?? deployOptionsStore.getRequestOptions());
-
- if (hadError) throw new Error(pullError || m.progress_deploy_failed());
-
- // Deployment finished successfully.
- pullProgress = 100;
- deployPulling = false;
- pullStatusText = m.progress_deploy_completed();
- await invalidateAll();
-
- setTimeout(() => {
- deployPullPopoverOpen = false;
- deployPulling = false;
- resetPullState();
- }, 1500);
-
- // Deploy already completed successfully
- itemState = 'running';
- toast.success(m.common_started_success({ type: name || type }));
- onActionComplete('running');
- } catch (e: any) {
- const message = e?.message || m.common_action_failed_with_type({ action: m.common_start(), type });
- if (openedPopover) {
- pullError = message;
- pullStatusText = m.images_pull_failed_with_error({ error: message });
- deployPulling = false;
- }
- toast.error(message);
+ projectService
+ .deployProject(id, () => {}, options ?? deployOptionsStore.getRequestOptions())
+ .then(async () => {
+ await invalidateAll();
+ itemState = 'running';
+ onActionComplete('running');
+ })
+ .catch((e: any) => {
+ const message = e?.message || m.common_action_failed_with_type({ action: m.common_start(), type });
+ toast.error(message);
+ });
} finally {
setLoading('start', false);
}
@@ -706,7 +341,6 @@
message: m.common_action_failed_with_type({ action: m.common_stop(), type }),
onSuccess: async () => {
itemState = 'stopped';
- toast.success(m.common_stopped_success({ type: name || type }));
onActionComplete('stopped');
}
});
@@ -719,126 +353,54 @@
message: m.common_action_failed_with_type({ action: m.common_restart(), type }),
onSuccess: async () => {
itemState = 'running';
- toast.success(m.common_restarted_success({ type: name || type }));
onActionComplete('running');
}
});
}
async function handleProjectPull() {
- resetPullState();
- projectPulling = true;
- pullPopoverOpen = true;
- pullStatusText = m.images_pull_initiating();
-
- let wasSuccessful = false;
+ setLoading('pull', true);
try {
- await projectService.pullProjectImages(id, (data) => {
- if (!data) return;
-
- if (data.error) {
- const errMsg = typeof data.error === 'string' ? data.error : data.error.message || m.images_pull_stream_error();
- pullError = errMsg;
- pullStatusText = m.images_pull_failed_with_error({ error: errMsg });
- return;
- }
-
- if (data.status) pullStatusText = data.status;
-
- if (data.id) {
- const currentLayer = layerProgress[data.id] || { current: 0, total: 0, status: '' };
- currentLayer.status = data.status || currentLayer.status;
-
- if (data.progressDetail) {
- const { current, total } = data.progressDetail;
- if (typeof current === 'number') currentLayer.current = current;
- if (typeof total === 'number') currentLayer.total = total;
- }
- layerProgress[data.id] = currentLayer;
- }
-
- updatePullProgress();
- });
-
- // Stream finished
- updatePullProgress();
- if (!pullError && pullProgress < 100 && areAllLayersComplete(layerProgress)) {
- pullProgress = 100;
- }
-
- if (pullError) throw new Error(pullError);
-
- wasSuccessful = true;
- pullProgress = 100;
- pullStatusText = m.images_pulled_success();
- toast.success(m.images_pulled_success());
- await invalidateAll();
- onActionComplete(itemState);
-
- setTimeout(() => {
- pullPopoverOpen = false;
- projectPulling = false;
- resetPullState();
- }, 2000);
- } catch (error: any) {
- const message = error?.message || m.images_pull_failed();
- pullError = message;
- pullStatusText = m.images_pull_failed_with_error({ error: message });
- toast.error(message);
+ projectService
+ .pullProjectImages(id, () => {})
+ .then(async () => {
+ await invalidateAll();
+ onActionComplete(itemState);
+ })
+ .catch((error: any) => {
+ const message = error?.message || m.images_pull_failed();
+ toast.error(message);
+ });
} finally {
- if (!wasSuccessful) {
- projectPulling = false;
- }
+ setLoading('pull', false);
}
}
async function handleProjectBuild() {
- resetPullState();
- projectBuilding = true;
- buildPopoverOpen = true;
- pullStatusText = m.progress_building_images_starting();
-
- let wasSuccessful = false;
+ setLoading('build', true);
try {
const buildProvider = projectBuildProvider;
- await projectService.buildProjectImages(
- id,
- {
- provider: buildProvider,
- push: buildProvider === 'depot',
- load: buildProvider !== 'depot'
- },
- (data) => {
- if (!data) return;
-
- handleBuildStreamLine(data, m.build_failed(), (errMsg) => m.build_failed_with_error({ error: errMsg }));
- }
- );
-
- if (pullError) throw new Error(pullError);
-
- wasSuccessful = true;
- pullProgress = 100;
- pullStatusText = m.build_completed();
- toast.success(m.build_completed());
- await invalidateAll();
-
- setTimeout(() => {
- buildPopoverOpen = false;
- projectBuilding = false;
- resetPullState();
- }, 2000);
- } catch (error: any) {
- const message = error?.message || m.build_failed();
- pullError = message;
- pullStatusText = m.build_failed_with_error({ error: message });
- toast.error(message);
+ projectService
+ .buildProjectImages(
+ id,
+ {
+ provider: buildProvider,
+ push: buildProvider === 'depot',
+ load: buildProvider !== 'depot'
+ },
+ () => {}
+ )
+ .then(async () => {
+ await invalidateAll();
+ })
+ .catch((error: any) => {
+ const message = error?.message || m.build_failed();
+ toast.error(message);
+ });
} finally {
- if (!wasSuccessful) {
- projectBuilding = false;
- }
+ setLoading('build', false);
}
}
</script>
@@ -884,28 +446,13 @@
loading={uiLoading.start}
/>
{:else}
- <ProgressPopover
- bind:open={deployPullPopoverOpen}
- bind:progress={pullProgress}
- mode="generic"
- title={deployPopoverTitle}
- completeTitle={m.progress_deploy_completed()}
- statusText={pullStatusText}
- error={pullError}
- loading={deployPulling}
- icon={deployPopoverIcon}
- layers={deployPopoverLayers}
- showOutputPanel={deployProgressPhase === 'build'}
- outputLines={deployProgressPhase === 'build' ? buildOutputLines : []}
- >
- <DeploySplitButton
- size={adaptiveIconOnly ? 'icon' : 'default'}
- showLabel={!adaptiveIconOnly}
- customLabel={deployButtonLabel}
- onDeploy={() => handleDeploy()}
- loading={uiLoading.start}
- />
- </ProgressPopover>
+ <DeploySplitButton
+ size={adaptiveIconOnly ? 'icon' : 'default'}
+ showLabel={!adaptiveIconOnly}
+ customLabel={deployButtonLabel}
+ onDeploy={() => handleDeploy()}
+ loading={uiLoading.start}
+ />
{/if}
{/if}
@@ -947,49 +494,23 @@
{#if type === 'project'}
{#if projectHasBuildDirective && canBuild}
- <ProgressPopover
- bind:open={buildPopoverOpen}
- bind:progress={pullProgress}
- mode="generic"
- title={m.build_output()}
- completeTitle={m.build_completed()}
- statusText={pullStatusText}
- error={pullError}
- loading={projectBuilding}
- icon={HammerIcon}
- layers={layerProgress}
- showOutputPanel={projectBuilding}
- outputLines={buildOutputLines}
- >
- <ArcaneButton
- action="build"
- size={adaptiveIconOnly ? 'icon' : 'default'}
- showLabel={!adaptiveIconOnly}
- onclick={() => handleProjectBuild()}
- loading={projectBuilding}
- />
- </ProgressPopover>
+ <ArcaneButton
+ action="build"
+ size={adaptiveIconOnly ? 'icon' : 'default'}
+ showLabel={!adaptiveIconOnly}
+ onclick={() => handleProjectBuild()}
+ loading={uiLoading.build}
+ />
{/if}
{#if canPull}
- <ProgressPopover
- bind:open={pullPopoverOpen}
- bind:progress={pullProgress}
- title={m.progress_pulling_images()}
- statusText={pullStatusText}
- error={pullError}
- loading={projectPulling}
- icon={DownloadIcon}
- layers={layerProgress}
- >
- <ArcaneButton
- action="pull"
- size={adaptiveIconOnly ? 'icon' : 'default'}
- showLabel={!adaptiveIconOnly}
- onclick={() => handleProjectPull()}
- loading={projectPulling}
- />
- </ProgressPopover>
+ <ArcaneButton
+ action="pull"
+ size={adaptiveIconOnly ? 'icon' : 'default'}
+ showLabel={!adaptiveIconOnly}
+ onclick={() => handleProjectPull()}
+ loading={uiLoading.pull}
+ />
{/if}
{/if}
@@ -1083,12 +604,12 @@
{#if type === 'project'}
{#if projectHasBuildDirective && canBuild}
- <DropdownMenu.Item onclick={handleProjectBuild} disabled={projectBuilding || uiLoading.building}>
+ <DropdownMenu.Item onclick={handleProjectBuild} disabled={uiLoading.build}>
{m.build()}
</DropdownMenu.Item>
{/if}
{#if canPull}
- <DropdownMenu.Item onclick={handleProjectPull} disabled={projectPulling || uiLoading.pulling}>
+ <DropdownMenu.Item onclick={handleProjectPull} disabled={uiLoading.pull}>
{m.images_pull()}
</DropdownMenu.Item>
{/if}
@@ -1109,58 +630,6 @@
</DropdownMenu.Group>
</DropdownMenu.Content>
</DropdownMenu.Root>
-
- {#if type === 'project'}
- <ProgressPopover
- bind:open={deployPullPopoverOpen}
- bind:progress={pullProgress}
- mode="generic"
- title={deployPopoverTitle}
- completeTitle={m.progress_deploy_completed()}
- statusText={pullStatusText}
- error={pullError}
- loading={deployPulling}
- icon={deployPopoverIcon}
- layers={deployPopoverLayers}
- showOutputPanel={deployProgressPhase === 'build'}
- outputLines={deployProgressPhase === 'build' ? buildOutputLines : []}
- triggerClass="hidden"
- >
- <span class="hidden"></span>
- </ProgressPopover>
-
- <ProgressPopover
- bind:open={buildPopoverOpen}
- bind:progress={pullProgress}
- mode="generic"
- title={m.build_output()}
- completeTitle={m.build_completed()}
- statusText={pullStatusText}
- error={pullError}
- loading={projectBuilding}
- icon={HammerIcon}
- layers={layerProgress}
- showOutputPanel={projectBuilding}
- outputLines={buildOutputLines}
- triggerClass="hidden"
- >
- <span class="hidden"></span>
- </ProgressPopover>
-
- <ProgressPopover
- bind:open={pullPopoverOpen}
- bind:progress={pullProgress}
- title={m.progress_pulling_images()}
- statusText={pullStatusText}
- error={pullError}
- loading={projectPulling}
- icon={DownloadIcon}
- layers={layerProgress}
- triggerClass="hidden"
- >
- <span class="hidden"></span>
- </ProgressPopover>
- {/if}
</div>
{/if}
</div>
@@ -1171,22 +640,7 @@
{#if type === 'container'}
<ArcaneButton action="start" onclick={() => handleStart()} loading={uiLoading.start} />
{:else}
- <ProgressPopover
- bind:open={deployPullPopoverOpen}
- bind:progress={pullProgress}
- mode="generic"
- title={deployPopoverTitle}
- completeTitle={m.progress_deploy_completed()}
- statusText={pullStatusText}
- error={pullError}
- loading={deployPulling}
- icon={deployPopoverIcon}
- layers={deployPopoverLayers}
- showOutputPanel={deployProgressPhase === 'build'}
- outputLines={deployProgressPhase === 'build' ? buildOutputLines : []}
- >
- <DeploySplitButton customLabel={deployButtonLabel} onDeploy={() => handleDeploy()} loading={uiLoading.start} />
- </ProgressPopover>
+ <DeploySplitButton customLabel={deployButtonLabel} onDeploy={() => handleDeploy()} loading={uiLoading.start} />
{/if}
{/if}
@@ -1214,37 +668,11 @@
{#if type === 'project'}
{#if projectHasBuildDirective && canBuild}
- <ProgressPopover
- bind:open={buildPopoverOpen}
- bind:progress={pullProgress}
- mode="generic"
- title={m.build_output()}
- completeTitle={m.build_completed()}
- statusText={pullStatusText}
- error={pullError}
- loading={projectBuilding}
- icon={HammerIcon}
- layers={layerProgress}
- showOutputPanel={projectBuilding}
- outputLines={buildOutputLines}
- >
- <ArcaneButton action="build" onclick={() => handleProjectBuild()} loading={projectBuilding} />
- </ProgressPopover>
+ <ArcaneButton action="build" onclick={() => handleProjectBuild()} loading={uiLoading.build} />
{/if}
{#if canPull}
- <ProgressPopover
- bind:open={pullPopoverOpen}
- bind:progress={pullProgress}
- title={m.progress_pulling_images()}
- statusText={pullStatusText}
- error={pullError}
- loading={projectPulling}
- icon={DownloadIcon}
- layers={layerProgress}
- >
- <ArcaneButton action="pull" onclick={() => handleProjectPull()} loading={projectPulling} />
- </ProgressPopover>
+ <ArcaneButton action="pull" onclick={() => handleProjectPull()} loading={uiLoading.pull} />
{/if}
{/if}
@@ -1330,12 +758,12 @@
{#if type === 'project'}
{#if projectHasBuildDirective && canBuild}
- <DropdownMenu.Item onclick={handleProjectBuild} disabled={projectBuilding || uiLoading.building}>
+ <DropdownMenu.Item onclick={handleProjectBuild} disabled={uiLoading.build}>
{m.build()}
</DropdownMenu.Item>
{/if}
{#if canPull}
- <DropdownMenu.Item onclick={handleProjectPull} disabled={projectPulling || uiLoading.pulling}>
+ <DropdownMenu.Item onclick={handleProjectPull} disabled={uiLoading.pull}>
{m.images_pull()}
</DropdownMenu.Item>
{/if}
diff --git a/frontend/src/lib/components/activity/activity-center-trigger.svelte b/frontend/src/lib/components/activity/activity-center-trigger.svelte
new file mode 100644
index 000000000..36ab8c8be
--- /dev/null
+++ b/frontend/src/lib/components/activity/activity-center-trigger.svelte
@@ -0,0 +1,108 @@
+<script lang="ts">
+ import { ActivityIcon } from '$lib/icons';
+ import { activityStore } from '$lib/stores/activity.store.svelte';
+ import { m } from '$lib/paraglide/messages';
+ import { cn } from '$lib/utils';
+
+ let {
+ collapsed = false,
+ mobile = false,
+ compact = false,
+ class: className = '',
+ onOpen
+ }: {
+ collapsed?: boolean;
+ mobile?: boolean;
+ compact?: boolean;
+ class?: string;
+ onOpen?: () => void;
+ } = $props();
+
+ const activeCount = $derived(activityStore.activeCount);
+ const isActive = $derived(activeCount > 0);
+
+ function handleOpenInternal() {
+ activityStore.openCenter();
+ onOpen?.();
+ }
+</script>
+
+{#if compact}
+ <button
+ type="button"
+ onclick={handleOpenInternal}
+ title={m.activity_center_open()}
+ aria-label={m.activity_center_open()}
+ class={cn(
+ 'group focus-visible:ring-ring relative flex items-center transition-colors focus-visible:ring-2 focus-visible:outline-hidden',
+ collapsed
+ ? 'mx-auto h-9 w-9 justify-center rounded-xl'
+ : 'text-sidebar-foreground/80 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground h-8 w-full rounded-md px-2',
+ className
+ )}
+ >
+ <span
+ class={cn(
+ 'grid place-items-center rounded-md transition-colors',
+ collapsed ? 'size-8' : 'size-6',
+ isActive
+ ? 'bg-primary/15 text-primary'
+ : 'bg-sidebar-accent text-sidebar-foreground/60 group-hover:text-sidebar-foreground'
+ )}
+ >
+ <ActivityIcon class={cn(collapsed ? 'size-4.5' : 'size-3.5')} aria-hidden="true" />
+ </span>
+ {#if !collapsed}
+ <span class="ml-2 min-w-0 flex-1 truncate text-left text-xs font-medium">{m.activity_center_title()}</span>
+ <span
+ class={cn(
+ 'ml-2 inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1.5 text-[10px] leading-none font-semibold tabular-nums',
+ isActive ? 'bg-primary text-primary-foreground' : 'bg-sidebar-accent text-sidebar-foreground/45'
+ )}
+ >
+ {isActive ? (activeCount > 9 ? m.activity_count_many() : activeCount) : '0'}
+ </span>
+ {:else if isActive}
+ <span
+ class="bg-primary text-primary-foreground ring-sidebar absolute -top-0.5 -right-0.5 flex min-w-4 items-center justify-center rounded-full px-1 text-[10px] leading-4 font-bold tabular-nums ring-2"
+ >
+ {activeCount > 9 ? m.activity_count_many() : activeCount}
+ </span>
+ {/if}
+ </button>
+{:else}
+ <button
+ type="button"
+ onclick={handleOpenInternal}
+ title={m.activity_center_open()}
+ aria-label={m.activity_center_open()}
+ class={cn(
+ 'text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:ring-ring relative flex items-center gap-3 rounded-lg transition-colors focus-visible:ring-2 focus-visible:outline-hidden',
+ mobile
+ ? 'w-full px-4 py-3 text-sm font-medium'
+ : collapsed
+ ? 'h-9 w-9 justify-center'
+ : 'h-9 w-full px-3 text-sm font-medium',
+ className
+ )}
+ >
+ <span class="relative inline-flex">
+ <ActivityIcon class={cn(mobile ? 'size-5' : 'size-4.5')} aria-hidden="true" />
+ {#if activeCount > 0}
+ <span
+ aria-live="polite"
+ aria-atomic="true"
+ class="bg-primary text-primary-foreground absolute -top-2 -right-2 flex min-w-4 items-center justify-center rounded-full px-1 text-[10px] leading-4 font-bold tabular-nums"
+ >
+ {activeCount > 9 ? m.activity_count_many() : activeCount}
+ </span>
+ {/if}
+ </span>
+ {#if !collapsed || mobile}
+ <span class="min-w-0 flex-1 truncate text-left">{m.activity_center_title()}</span>
+ {#if activeCount > 0}
+ <span class="text-primary text-xs font-semibold tabular-nums">{m.activity_active_count({ count: activeCount })}</span>
+ {/if}
+ {/if}
+ </button>
+{/if}
diff --git a/frontend/src/lib/components/activity/activity-center.svelte b/frontend/src/lib/components/activity/activity-center.svelte
new file mode 100644
index 000000000..d7e51cc46
--- /dev/null
+++ b/frontend/src/lib/components/activity/activity-center.svelte
@@ -0,0 +1,142 @@
+<script lang="ts">
+ import { onMount } from 'svelte';
+ import ResponsiveDialog from '$lib/components/ui/responsive-dialog/responsive-dialog.svelte';
+ import * as Collapsible from '$lib/components/ui/collapsible/index.js';
+ import ActivityListItem from './activity-list-item.svelte';
+ import ActivityDetailPanel from './activity-detail-panel.svelte';
+ import { activityStore } from '$lib/stores/activity.store.svelte';
+ import type { ActivityFilter } from '$lib/types/activity.type';
+ import { ActivityIcon, RefreshIcon, TrashIcon } from '$lib/icons';
+ import { m } from '$lib/paraglide/messages';
+ import { cn } from '$lib/utils';
+ import { activityFilterLabel } from './activity-labels';
+ import { openConfirmDialog } from '$lib/components/confirm-dialog';
+ import { toast } from 'svelte-sonner';
+ import IfPermitted from '$lib/components/if-permitted.svelte';
+
+ const filters: ActivityFilter[] = ['running', 'failed', 'completed'];
+
+ onMount(() => {
+ void activityStore.start();
+ });
+
+ function handleOpenChangeInternal(open: boolean) {
+ activityStore.setOpen(open);
+ }
+
+ function clearHistoryInternal() {
+ openConfirmDialog({
+ title: m.activity_clear_history_title(),
+ message: m.activity_clear_history_message(),
+ confirm: {
+ label: m.activity_clear_history_confirm(),
+ destructive: true,
+ action: async () => {
+ try {
+ await activityStore.clearHistory();
+ toast.success(m.activity_clear_history_success());
+ } catch (error) {
+ console.error('Failed to clear activity history:', error);
+ toast.error(m.activity_clear_history_failed());
+ }
+ }
+ }
+ });
+ }
+</script>
+
+<ResponsiveDialog
+ open={activityStore.open}
+ onOpenChange={handleOpenChangeInternal}
+ variant="sheet"
+ title={m.activity_center_title()}
+ contentClass="w-[min(94vw,760px)] sm:max-w-[760px]"
+ class="flex min-h-0 flex-1 flex-col pt-3 pb-0"
+>
+ <div class="border-border/60 flex flex-wrap items-center justify-between gap-3 border-b px-4 py-3">
+ <div class="flex min-w-0 items-center gap-2">
+ {#if activityStore.activeCount > 0}
+ <span class="bg-primary/10 text-primary rounded-md px-2 py-1 text-xs font-semibold tabular-nums">
+ {m.activity_active_count({ count: activityStore.activeCount })}
+ </span>
+ {/if}
+ </div>
+
+ <div class="flex items-center gap-2">
+ <div class="bg-muted/40 inline-flex rounded-md p-0.5">
+ {#each filters as filter (filter)}
+ <button
+ type="button"
+ onclick={() => activityStore.setFilter(filter)}
+ class={cn(
+ 'rounded-sm px-2.5 py-1 text-xs font-medium transition-colors',
+ activityStore.filter === filter
+ ? 'bg-background text-foreground shadow-xs'
+ : 'text-muted-foreground hover:text-foreground'
+ )}
+ >
+ {activityFilterLabel(filter)}
+ </button>
+ {/each}
+ </div>
+ <button
+ type="button"
+ onclick={() => activityStore.refresh()}
+ title={m.common_refresh()}
+ aria-label={m.common_refresh()}
+ class="text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:ring-ring flex size-8 items-center justify-center rounded-md transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
+ >
+ <RefreshIcon class={cn('size-4', activityStore.loading && 'animate-spin')} aria-hidden="true" />
+ </button>
+ <IfPermitted perm="activities:delete">
+ <button
+ type="button"
+ onclick={clearHistoryInternal}
+ title={m.activity_clear_history()}
+ aria-label={m.activity_clear_history()}
+ class="text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:ring-ring flex size-8 items-center justify-center rounded-md transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
+ >
+ <TrashIcon class="size-4" aria-hidden="true" />
+ </button>
+ </IfPermitted>
+ </div>
+ </div>
+
+ <div class="min-h-[68vh] flex-1 overflow-y-auto">
+ {#if activityStore.loading && activityStore.activities.length === 0}
+ <div class="flex min-h-96 items-center justify-center p-6 text-center">
+ <div class="space-y-2">
+ <ActivityIcon class="text-muted-foreground mx-auto size-8 animate-pulse" aria-hidden="true" />
+ <p class="text-muted-foreground text-sm">{m.common_loading()}</p>
+ </div>
+ </div>
+ {:else if activityStore.filteredActivities.length === 0}
+ <div class="flex min-h-96 items-center justify-center p-6 text-center">
+ <div class="max-w-56 space-y-2">
+ <ActivityIcon class="text-muted-foreground/50 mx-auto size-9" aria-hidden="true" />
+ <h3 class="text-sm font-semibold">{m.activity_empty_title()}</h3>
+ <p class="text-muted-foreground text-xs leading-relaxed">{m.activity_empty_description()}</p>
+ </div>
+ </div>
+ {:else}
+ <div>
+ {#each activityStore.filteredActivities as activity (activity.id)}
+ {@const expanded = activityStore.isExpanded(activity.id)}
+ <Collapsible.Root open={expanded} onOpenChange={(open) => activityStore.setActivityExpanded(activity.id, open)}>
+ <Collapsible.Trigger
+ class="focus-visible:ring-ring block w-full cursor-pointer appearance-none border-0 bg-transparent p-0 text-left focus-visible:ring-2 focus-visible:outline-hidden focus-visible:ring-inset"
+ aria-label={m.activity_center_title()}
+ >
+ <ActivityListItem {activity} {expanded} />
+ </Collapsible.Trigger>
+ <Collapsible.Content
+ class="data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=closed]:slide-out-to-top-1 data-[state=open]:slide-in-from-top-1 overflow-hidden"
+ >
+ <ActivityDetailPanel {activity} />
+ </Collapsible.Content>
+ </Collapsible.Root>
+ {/each}
+ </div>
+ {/if}
+ </div>
+</ResponsiveDialog>
diff --git a/frontend/src/lib/components/activity/activity-detail-panel.svelte b/frontend/src/lib/components/activity/activity-detail-panel.svelte
new file mode 100644
index 000000000..eec062fa8
--- /dev/null
+++ b/frontend/src/lib/components/activity/activity-detail-panel.svelte
@@ -0,0 +1,228 @@
+<script lang="ts">
+ import { Progress } from '$lib/components/ui/progress/index.js';
+ import StatusBadge from '$lib/components/badges/status-badge.svelte';
+ import { CopyButton } from '$lib/components/ui/copy-button';
+ import { activityStore } from '$lib/stores/activity.store.svelte';
+ import type { Activity, ActivityMessage } from '$lib/types/activity.type';
+ import { ActivityIcon, TerminalIcon } from '$lib/icons';
+ import { m } from '$lib/paraglide/messages';
+ import { cn } from '$lib/utils';
+ import { activityStatusLabel, activityStatusVariant, activityTypeIcon, activityTypeLabel } from './activity-labels';
+
+ let { activity }: { activity: Activity } = $props();
+
+ let outputContainer = $state<HTMLElement | null>(null);
+
+ // Prefer the freshest activity data from the store (messages stream may update it).
+ const liveActivity = $derived(activityStore.getActivity(activity.id) ?? activity);
+ const detail = $derived(activityStore.getDetail(activity.id));
+ const messages = $derived(detail?.messages ?? []);
+ const outputText = $derived(messages.map(formatOutputLineInternal).join('\n'));
+ const IconComponent = $derived(activityTypeIcon(liveActivity.type));
+ const hasProgress = $derived(typeof liveActivity.progress === 'number');
+ const progressValue = $derived(Math.min(100, Math.max(0, Math.round(liveActivity.progress ?? 0))));
+ const isLoading = $derived(activityStore.isDetailLoading(activity.id));
+ const isDetailError = $derived(activityStore.isDetailError(activity.id));
+ const activityTarget = $derived(
+ liveActivity.resourceName || liveActivity.resourceId || liveActivity.resourceType || m.activity_unknown_target()
+ );
+ const sourceEnvironmentName = $derived(
+ liveActivity.sourceEnvironmentName || liveActivity.sourceEnvironmentId || liveActivity.environmentId
+ );
+ const startedByName = $derived(liveActivity.startedBy?.displayName || liveActivity.startedBy?.username);
+
+ $effect(() => {
+ messages.length;
+ outputContainer;
+ queueMicrotask(() => {
+ if (!outputContainer) {
+ return;
+ }
+ outputContainer.scrollTop = outputContainer.scrollHeight;
+ });
+ });
+
+ function formatDateTimeInternal(value?: string): string {
+ if (!value) {
+ return m.common_na();
+ }
+ return new Intl.DateTimeFormat(undefined, {
+ month: 'short',
+ day: 'numeric',
+ hour: 'numeric',
+ minute: '2-digit',
+ second: '2-digit'
+ }).format(new Date(value));
+ }
+
+ function formatDurationInternal(value: Activity | null): string {
+ const durationMs = value?.durationMs ?? (value?.startedAt ? Date.now() - new Date(value.startedAt).getTime() : 0);
+ if (!durationMs || Number.isNaN(durationMs)) {
+ return m.common_na();
+ }
+ if (durationMs < 1000) {
+ return m.activity_duration_ms({ ms: Math.max(0, Math.round(durationMs)) });
+ }
+
+ const totalSeconds = Math.round(durationMs / 1000);
+ if (totalSeconds < 60) {
+ return m.activity_duration_seconds({ seconds: totalSeconds });
+ }
+
+ const minutes = Math.floor(totalSeconds / 60);
+ const seconds = totalSeconds % 60;
+ return m.activity_duration_minutes({ minutes, seconds });
+ }
+
+ function formatOutputLineInternal(message: ActivityMessage): string {
+ const timestamp = new Intl.DateTimeFormat(undefined, {
+ hour: 'numeric',
+ minute: '2-digit',
+ second: '2-digit'
+ }).format(new Date(message.createdAt));
+ return `[${timestamp}] ${message.level.toUpperCase()} ${message.message}`;
+ }
+
+ function messageLevelClassInternal(level: ActivityMessage['level']): string {
+ switch (level) {
+ case 'error':
+ return 'text-red-300';
+ case 'warning':
+ return 'text-amber-300';
+ case 'success':
+ return 'text-emerald-300';
+ default:
+ return 'text-zinc-100';
+ }
+ }
+</script>
+
+<div class="bg-muted/25 border-border/50 border-b px-4 py-3">
+ <div class="border-border/60 bg-background overflow-hidden rounded-lg border shadow-sm">
+ <div class="space-y-4 px-5 py-4">
+ <div class="flex min-w-0 items-start justify-between gap-4">
+ <div class="flex min-w-0 items-start gap-3">
+ <div class="bg-primary/10 text-primary flex size-9 shrink-0 items-center justify-center rounded-md">
+ <IconComponent class="size-4.5" aria-hidden="true" />
+ </div>
+ <div class="min-w-0">
+ <div class="flex flex-wrap items-center gap-2">
+ <h3 class="truncate text-sm font-semibold">{activityTypeLabel(liveActivity.type)}</h3>
+ <StatusBadge
+ text={activityStatusLabel(liveActivity.status)}
+ variant={activityStatusVariant(liveActivity.status)}
+ size="sm"
+ minWidth="none"
+ />
+ </div>
+ <p class="text-muted-foreground mt-1 truncate text-xs">{activityTarget}</p>
+ </div>
+ </div>
+ </div>
+
+ <div class="space-y-2">
+ <div class="flex items-center justify-between gap-3 text-xs">
+ <span class="text-muted-foreground">{liveActivity.step || m.activity_step_unknown()}</span>
+ <span class="text-muted-foreground tabular-nums">
+ {#if hasProgress}
+ {m.activity_progress_percent({ progress: progressValue })}
+ {:else}
+ {m.common_live()}
+ {/if}
+ </span>
+ </div>
+ <Progress
+ value={hasProgress ? progressValue : 100}
+ indeterminate={!hasProgress && (liveActivity.status === 'running' || liveActivity.status === 'queued')}
+ class="h-1.5"
+ />
+ </div>
+
+ <div class="text-muted-foreground flex flex-wrap items-center gap-x-4 gap-y-1.5 text-xs">
+ <div class="flex items-center gap-1.5">
+ <span>{m.common_started()}</span>
+ <span class="text-foreground font-medium tabular-nums">{formatDateTimeInternal(liveActivity.startedAt)}</span>
+ </div>
+ <span class="text-border">•</span>
+ <div class="flex items-center gap-1.5">
+ <span>{m.common_finished()}</span>
+ <span class="text-foreground font-medium tabular-nums">{formatDateTimeInternal(liveActivity.endedAt)}</span>
+ </div>
+ <span class="text-border">•</span>
+ <div class="flex items-center gap-1.5">
+ <span>{m.activity_duration()}</span>
+ <span class="text-foreground font-medium tabular-nums">{formatDurationInternal(liveActivity)}</span>
+ </div>
+ {#if sourceEnvironmentName}
+ <span class="text-border">•</span>
+ <div class="flex items-center gap-1.5">
+ <span>{m.activity_source_environment()}</span>
+ <span class="text-foreground font-medium">{sourceEnvironmentName}</span>
+ </div>
+ {/if}
+ {#if startedByName}
+ <span class="text-border">•</span>
+ <div class="flex items-center gap-1.5">
+ <span>{m.activity_started_by_label()}</span>
+ <span class="text-foreground font-medium">{startedByName}</span>
+ </div>
+ {/if}
+ </div>
+
+ {#if liveActivity.error}
+ <div class="border-destructive/30 bg-destructive/10 text-destructive rounded-md border p-3 text-sm">
+ {liveActivity.error}
+ </div>
+ {/if}
+ </div>
+
+ <div class="border-border/60 border-t">
+ <div class="flex items-center justify-between px-5 py-2.5">
+ <div class="flex items-center gap-2">
+ <TerminalIcon class="text-muted-foreground size-4" aria-hidden="true" />
+ <span class="text-sm font-semibold">{m.activity_output_title()}</span>
+ </div>
+ <CopyButton text={outputText} variant="ghost" size="default" class="h-8 px-2 text-xs" tabindex={0}>
+ <span class="text-xs">{m.activity_copy_output()}</span>
+ </CopyButton>
+ </div>
+
+ <div
+ bind:this={outputContainer}
+ class="max-h-80 min-h-40 overflow-auto bg-zinc-950 px-5 py-4 font-mono text-[12px] leading-relaxed text-zinc-100"
+ >
+ {#if isDetailError && messages.length === 0}
+ <div class="flex min-h-32 flex-col items-center justify-center gap-2 text-zinc-500">
+ <span>{m.activity_output_load_failed()}</span>
+ <button
+ type="button"
+ onclick={() => activityStore.retryLoadDetail(activity.id)}
+ class="text-primary hover:text-primary/80 text-xs underline"
+ >
+ {m.common_retry()}
+ </button>
+ </div>
+ {:else if isLoading && messages.length === 0}
+ <div class="flex min-h-32 items-center justify-center text-zinc-500">
+ <ActivityIcon class="mr-2 size-4 animate-pulse" aria-hidden="true" />
+ {m.activity_output_loading()}
+ </div>
+ {:else if messages.length === 0}
+ <div class="flex min-h-32 items-center justify-center text-center text-zinc-500">
+ {m.activity_output_empty()}
+ </div>
+ {:else}
+ {#each messages as message (message.id)}
+ <div class="grid grid-cols-[auto_auto_minmax(0,1fr)] gap-2 rounded px-1 py-0.5 hover:bg-white/[0.04]">
+ <span class="text-zinc-500">{formatDateTimeInternal(message.createdAt)}</span>
+ <span class={cn('font-bold', messageLevelClassInternal(message.level))}>
+ {message.level.toUpperCase()}
+ </span>
+ <span class="break-words whitespace-pre-wrap">{message.message}</span>
+ </div>
+ {/each}
+ {/if}
+ </div>
+ </div>
+ </div>
+</div>
diff --git a/frontend/src/lib/components/activity/activity-labels.ts b/frontend/src/lib/components/activity/activity-labels.ts
new file mode 100644
index 000000000..0bc279341
--- /dev/null
+++ b/frontend/src/lib/components/activity/activity-labels.ts
@@ -0,0 +1,140 @@
+import { m } from '$lib/paraglide/messages';
+import type { ActivityFilter, ActivityStatus, ActivityType } from '$lib/types/activity.type';
+import type { IconType } from '$lib/icons';
+import {
+ ActivityIcon,
+ DownloadIcon,
+ HammerIcon,
+ RedeployIcon,
+ RefreshIcon,
+ RestartIcon,
+ ScanIcon,
+ StartIcon,
+ StopIcon,
+ TrashIcon
+} from '$lib/icons';
+
+export type ActivityBadgeVariant = 'red' | 'green' | 'blue' | 'gray' | 'amber' | 'purple';
+
+export function activityStatusLabel(status: ActivityStatus): string {
+ switch (status) {
+ case 'queued':
+ return m.activity_status_queued();
+ case 'running':
+ return m.common_running();
+ case 'success':
+ return m.common_success();
+ case 'failed':
+ return m.common_failed();
+ case 'cancelled':
+ return m.activity_status_cancelled();
+ }
+}
+
+export function activityStatusVariant(status: ActivityStatus): ActivityBadgeVariant {
+ switch (status) {
+ case 'queued':
+ return 'amber';
+ case 'running':
+ return 'blue';
+ case 'success':
+ return 'green';
+ case 'failed':
+ return 'red';
+ case 'cancelled':
+ return 'gray';
+ }
+}
+
+export function activityTypeLabel(type: ActivityType): string {
+ switch (type) {
+ case 'image_pull':
+ return m.activity_type_image_pull();
+ case 'image_build':
+ return m.activity_type_image_build();
+ case 'image_update_check':
+ return m.activity_type_image_update_check();
+ case 'project_pull':
+ return m.activity_type_project_pull();
+ case 'project_build':
+ return m.activity_type_project_build();
+ case 'project_deploy':
+ return m.activity_type_project_deploy();
+ case 'project_redeploy':
+ return m.activity_type_project_redeploy();
+ case 'project_down':
+ return m.activity_type_project_down();
+ case 'project_restart':
+ return m.activity_type_project_restart();
+ case 'project_destroy':
+ return m.activity_type_project_destroy();
+ case 'container_start':
+ return m.activity_type_container_start();
+ case 'container_stop':
+ return m.activity_type_container_stop();
+ case 'container_restart':
+ return m.activity_type_container_restart();
+ case 'container_redeploy':
+ return m.activity_type_container_redeploy();
+ case 'container_delete':
+ return m.activity_type_container_delete();
+ case 'vulnerability_scan':
+ return m.activity_type_vulnerability_scan();
+ case 'auto_update':
+ return m.activity_type_auto_update();
+ case 'system_prune':
+ return m.activity_type_system_prune();
+ case 'resource_action':
+ return m.activity_type_resource_action();
+ }
+}
+
+export function activityTypeIcon(type: ActivityType): IconType {
+ switch (type) {
+ case 'image_pull':
+ case 'project_pull':
+ return DownloadIcon;
+ case 'image_build':
+ case 'project_build':
+ return HammerIcon;
+ case 'image_update_check':
+ return RefreshIcon;
+ case 'project_deploy':
+ return ActivityIcon;
+ case 'container_start':
+ return StartIcon;
+ case 'project_redeploy':
+ case 'container_redeploy':
+ return RedeployIcon;
+ case 'project_down':
+ case 'container_stop':
+ return StopIcon;
+ case 'project_restart':
+ case 'container_restart':
+ return RestartIcon;
+ case 'project_destroy':
+ case 'container_delete':
+ return TrashIcon;
+ case 'vulnerability_scan':
+ return ScanIcon;
+ case 'auto_update':
+ return RefreshIcon;
+ case 'system_prune':
+ return TrashIcon;
+ case 'resource_action':
+ return ActivityIcon;
+ default:
+ return ActivityIcon;
+ }
+}
+
+export function activityFilterLabel(filter: ActivityFilter): string {
+ switch (filter) {
+ case 'running':
+ return m.common_running();
+ case 'failed':
+ return m.common_failed();
+ case 'completed':
+ return m.activity_filter_completed();
+ }
+}
diff --git a/frontend/src/lib/components/activity/activity-list-item.svelte b/frontend/src/lib/components/activity/activity-list-item.svelte
new file mode 100644
index 000000000..cb01ec760
--- /dev/null
+++ b/frontend/src/lib/components/activity/activity-list-item.svelte
@@ -0,0 +1,121 @@
+<script lang="ts">
+ import { Progress } from '$lib/components/ui/progress/index.js';
+ import StatusBadge from '$lib/components/badges/status-badge.svelte';
+ import { ArrowDownIcon } from '$lib/icons';
+ import { m } from '$lib/paraglide/messages';
+ import { cn } from '$lib/utils';
+ import { formatDistanceToNow } from 'date-fns';
+ import type { Activity, ActivityStatus } from '$lib/types/activity.type';
+ import { activityStatusLabel, activityStatusVariant, activityTypeIcon, activityTypeLabel } from './activity-labels';
+
+ let {
+ activity,
+ expanded = false
+ }: {
+ activity: Activity;
+ expanded?: boolean;
+ } = $props();
+
+ const IconComponent = $derived(activityTypeIcon(activity.type));
+ const hasProgress = $derived(typeof activity.progress === 'number');
+ const progressValue = $derived(Math.round(activity.progress ?? 0));
+ const isActive = $derived(activity.status === 'running' || activity.status === 'queued');
+ const targetName = $derived(activity.resourceName || activity.resourceId || m.activity_unknown_target());
+ const subtitle = $derived(activity.latestMessage || activity.step || m.activity_no_message());
+ const sourceEnvironmentName = $derived(
+ activity.sourceEnvironmentName || activity.sourceEnvironmentId || activity.environmentId
+ );
+ const startedByName = $derived(activity.startedBy?.displayName || activity.startedBy?.username);
+
+ const referenceDate = $derived(activity.endedAt || activity.startedAt);
+ const relativeTime = $derived(referenceDate ? formatDistanceToNow(new Date(referenceDate), { addSuffix: true }) : '');
+
+ function statusAccentClass(status: ActivityStatus): string {
+ switch (status) {
+ case 'failed':
+ return 'bg-red-500';
+ case 'running':
+ return 'bg-blue-500';
+ case 'queued':
+ return 'bg-amber-500';
+ case 'success':
+ return 'bg-emerald-500';
+ case 'cancelled':
+ return 'bg-muted-foreground/40';
+ }
+ }
+</script>
+
+<div
+ class={cn(
+ 'group border-border/40 hover:bg-muted/30 relative grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 border-b px-4 py-3 text-left transition-colors last:border-b-0',
+ expanded && 'bg-muted/40'
+ )}
+>
+ <span
+ aria-hidden="true"
+ class={cn(
+ 'absolute top-2 bottom-2 left-0 rounded-r-full transition-all',
+ statusAccentClass(activity.status),
+ expanded ? 'w-1' : 'w-0.5'
+ )}
+ ></span>
+
+ <div
+ class={cn(
+ 'bg-muted/80 text-muted-foreground mt-0.5 flex size-8 items-center justify-center rounded-md',
+ isActive && 'bg-primary/10 text-primary',
+ expanded && 'bg-primary/10 text-primary'
+ )}
+ >
+ <IconComponent class="size-4" aria-hidden="true" />
+ </div>
+ <div class="min-w-0 space-y-1.5">
+ <div class="flex min-w-0 items-start justify-between gap-3">
+ <div class="min-w-0 flex-1">
+ <div class="flex min-w-0 items-center gap-2">
+ <span class="text-foreground truncate text-sm font-semibold">{activityTypeLabel(activity.type)}</span>
+ {#if relativeTime}
+ <span class="text-muted-foreground/70 shrink-0 text-[11px]">· {relativeTime}</span>
+ {/if}
+ </div>
+ <div class="text-muted-foreground truncate text-xs">{targetName}</div>
+ <div class="text-muted-foreground/80 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px]">
+ {#if sourceEnvironmentName}
+ <span class="truncate">{sourceEnvironmentName}</span>
+ {/if}
+ {#if startedByName}
+ <span class="text-muted-foreground/50">·</span>
+ <span class="truncate">{m.activity_started_by({ user: startedByName })}</span>
+ {/if}
+ </div>
+ </div>
+ <StatusBadge
+ text={activityStatusLabel(activity.status)}
+ variant={activityStatusVariant(activity.status)}
+ size="sm"
+ minWidth="none"
+ />
+ </div>
+
+ <div class="space-y-1.5">
+ <div class="text-muted-foreground line-clamp-2 text-xs leading-relaxed">{subtitle}</div>
+ {#if isActive && !expanded}
+ <div class="flex items-center gap-2">
+ <Progress value={hasProgress ? progressValue : 100} indeterminate={!hasProgress} class="h-1.5 rounded-full" />
+ <span class="text-muted-foreground w-9 shrink-0 text-right text-[11px] tabular-nums">
+ {#if hasProgress}
+ {m.activity_progress_percent({ progress: progressValue })}
+ {:else}
+ {m.common_live()}
+ {/if}
+ </span>
+ </div>
+ {/if}
+ </div>
+ </div>
+
+ <div class="text-muted-foreground mt-1 flex size-6 shrink-0 items-center justify-center">
+ <ArrowDownIcon class={cn('size-4 transition-transform duration-200', expanded && 'rotate-180')} aria-hidden="true" />
+ </div>
+</div>
diff --git a/frontend/src/lib/components/file-browser/CreateFolderDialog.svelte b/frontend/src/lib/components/file-browser/CreateFolderDialog.svelte
index f9776e926..d516c5707 100644
--- a/frontend/src/lib/components/file-browser/CreateFolderDialog.svelte
+++ b/frontend/src/lib/components/file-browser/CreateFolderDialog.svelte
@@ -5,6 +5,7 @@
import { Label } from '$lib/components/ui/label';
import { toast } from 'svelte-sonner';
import * as m from '$lib/paraglide/messages.js';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let {
open = $bindable(false),
@@ -13,7 +14,7 @@
}: {
open: boolean;
currentPath: string;
- onCreate: (folderName: string) => Promise<void>;
+ onCreate: (folderName: string) => Promise<unknown>;
} = $props();
let folderName = $state('');
@@ -25,8 +26,8 @@
loading = true;
try {
- await onCreate(folderName);
- toast.success(m.common_create_success({ resource: folderName }));
+ const result = await onCreate(folderName);
+ toast.success(m.common_create_success({ resource: folderName }), activityToastOptions(extractActivityId(result)));
open = false;
folderName = '';
} catch (e: any) {
diff --git a/frontend/src/lib/components/file-browser/FileList.svelte b/frontend/src/lib/components/file-browser/FileList.svelte
index 608ea4201..cc10c06da 100644
--- a/frontend/src/lib/components/file-browser/FileList.svelte
+++ b/frontend/src/lib/components/file-browser/FileList.svelte
@@ -22,6 +22,7 @@
import { ArcaneButton } from '$lib/components/arcane-button';
import { bytes } from '$lib/utils/formatting';
import { format } from 'date-fns';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let {
files,
@@ -40,7 +41,7 @@
persistKey?: string;
onNavigate: (path: string) => void;
onRefresh: () => void;
- onDelete?: (file: FileEntry) => Promise<void>;
+ onDelete?: (file: FileEntry) => Promise<unknown>;
onDownload: (file: FileEntry) => Promise<void>;
onPreview: (file: FileEntry) => void;
onRestoreFromBackup?: (file: FileEntry) => void;
@@ -111,8 +112,8 @@
destructive: true,
action: async () => {
try {
- await onDelete(file);
- toast.success(m.common_delete_success({ resource: file.name }));
+ const result = await onDelete(file);
+ toast.success(m.common_delete_success({ resource: file.name }), activityToastOptions(extractActivityId(result)));
onRefresh();
} catch (e: any) {
toast.error(e.message || m.common_delete_failed({ resource: file.name }));
diff --git a/frontend/src/lib/components/file-browser/FileUploadDialog.svelte b/frontend/src/lib/components/file-browser/FileUploadDialog.svelte
index ff2c22414..e52aacfb5 100644
--- a/frontend/src/lib/components/file-browser/FileUploadDialog.svelte
+++ b/frontend/src/lib/components/file-browser/FileUploadDialog.svelte
@@ -5,6 +5,7 @@
import { toast } from 'svelte-sonner';
import * as m from '$lib/paraglide/messages.js';
import { CloseIcon } from '$lib/icons';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let {
open = $bindable(false),
@@ -13,7 +14,7 @@
}: {
open: boolean;
currentPath: string;
- onUpload: (file: File) => Promise<void>;
+ onUpload: (file: File) => Promise<unknown>;
} = $props();
let files = $state<File[]>([]);
@@ -35,10 +36,11 @@
if (files.length === 0) return;
uploading = true;
try {
+ let lastResult: unknown;
for (const file of files) {
- await onUploadAction(file);
+ lastResult = await onUploadAction(file);
}
- toast.success(m.common_success());
+ toast.success(m.common_success(), activityToastOptions(extractActivityId(lastResult)));
open = false;
files = [];
} catch (e: any) {
diff --git a/frontend/src/lib/components/file-browser/GenericFileBrowser.svelte b/frontend/src/lib/components/file-browser/GenericFileBrowser.svelte
index c4f3c27ac..3bd3b8a93 100644
--- a/frontend/src/lib/components/file-browser/GenericFileBrowser.svelte
+++ b/frontend/src/lib/components/file-browser/GenericFileBrowser.svelte
@@ -3,13 +3,13 @@
export interface FileProvider {
list: (path: string) => Promise<FileEntry[]>;
- mkdir: (path: string) => Promise<void>;
- upload: (path: string, file: File) => Promise<void>;
- delete: (path: string) => Promise<void>;
+ mkdir: (path: string) => Promise<unknown>;
+ upload: (path: string, file: File) => Promise<unknown>;
+ delete: (path: string) => Promise<unknown>;
download: (path: string) => Promise<void>;
getContent: (path: string) => Promise<{ content: string }>;
listBackups?: () => Promise<BackupEntry[]>;
- restoreFromBackup?: (backupId: string, path: string) => Promise<void>;
+ restoreFromBackup?: (backupId: string, path: string) => Promise<unknown>;
backupHasPath?: (backupId: string, path: string) => Promise<boolean>;
}
</script>
@@ -35,6 +35,7 @@
import { environmentStore } from '$lib/stores/environment.store.svelte';
import { hasPermission } from '$lib/utils/auth';
import IfPermitted from '$lib/components/if-permitted.svelte';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { provider, rootLabel, persistKey }: { provider: FileProvider; rootLabel?: string; persistKey?: string } = $props();
@@ -120,8 +121,8 @@
if (!restoreTarget || !provider.restoreFromBackup || !selectedBackupId) return;
restoringFile = true;
try {
- await provider.restoreFromBackup(selectedBackupId, restoreTarget.path);
- toast.success(m.volumes_backup_file_restore_success());
+ const result = await provider.restoreFromBackup(selectedBackupId, restoreTarget.path);
+ toast.success(m.volumes_backup_file_restore_success(), activityToastOptions(extractActivityId(result)));
showRestoreFile = false;
// Refresh the file list to show the restored file
await loadFiles(currentPath);
diff --git a/frontend/src/lib/components/image-update-item.svelte b/frontend/src/lib/components/image-update-item.svelte
index b0dd21404..ea848b140 100644
--- a/frontend/src/lib/components/image-update-item.svelte
+++ b/frontend/src/lib/components/image-update-item.svelte
@@ -10,6 +10,7 @@
import { ArrowRightIcon, RefreshIcon, AlertIcon, VerifiedCheckIcon, ApiKeyIcon, CircleArrowUpIcon, BoxIcon } from '$lib/icons';
import { createQuery } from '@tanstack/svelte-query';
import UpdateStatusPopover from '$lib/components/update-status-popover.svelte';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
interface Props {
updateInfo?: ImageUpdateData;
@@ -140,11 +141,12 @@
const result = await imageUpdateQuery.refetch();
if (result.data) {
onUpdated?.(result.data);
+ const toastOptions = activityToastOptions(extractActivityId(result.data));
if (result.data.error) {
- toast.error(result.data.error || m.images_update_check_failed());
+ toast.error(result.data.error || m.images_update_check_failed(), toastOptions);
} else {
- toast.success(m.images_update_check_completed());
+ toast.success(m.images_update_check_completed(), toastOptions);
}
return;
}
diff --git a/frontend/src/lib/components/mobile-nav/mobile-nav-sheet.svelte b/frontend/src/lib/components/mobile-nav/mobile-nav-sheet.svelte
index 9b4f6f6b9..24539ce4f 100644
--- a/frontend/src/lib/components/mobile-nav/mobile-nav-sheet.svelte
+++ b/frontend/src/lib/components/mobile-nav/mobile-nav-sheet.svelte
@@ -7,6 +7,7 @@
import { m } from '$lib/paraglide/messages';
import { environmentStore } from '$lib/stores/environment.store.svelte';
import MobileUserCard from './mobile-user-card.svelte';
+ import ActivityCenterTrigger from '$lib/components/activity/activity-center-trigger.svelte';
import * as Drawer from '$lib/components/ui/drawer/index.js';
import { queryKeys } from '$lib/query/query-keys';
import systemUpgradeService from '$lib/services/api/system-upgrade-service';
@@ -120,6 +121,7 @@
{#if memoizedUser}
<MobileUserCard user={memoizedUser} class="mb-6" />
{/if}
+ <ActivityCenterTrigger mobile class="mb-4" onOpen={handleItemClick} />
</div>
<div class="scrollbar-hide flex-1 overflow-y-auto px-6">
@@ -357,7 +359,8 @@
{#if versionInformation}
<div class="text-muted-foreground/60 text-center text-xs">
<p class="font-medium">
- Arcane {versionInformation.displayVersion ?? versionInformation.currentVersion}
+ {m.layout_title()}
+ {versionInformation.displayVersion ?? versionInformation.currentVersion}
</p>
</div>
{#if shouldShowBanner}
diff --git a/frontend/src/lib/components/progress-popover.svelte b/frontend/src/lib/components/progress-popover.svelte
deleted file mode 100644
index de1a925b1..000000000
--- a/frontend/src/lib/components/progress-popover.svelte
+++ /dev/null
@@ -1,316 +0,0 @@
-<script lang="ts">
- import { cn } from '$lib/utils.js';
- import * as Popover from '$lib/components/ui/popover/index.js';
- import * as Dialog from '$lib/components/ui/dialog/index.js';
- import { Popover as PopoverPrimitive } from 'bits-ui';
- import { Progress } from '$lib/components/ui/progress/index.js';
- import * as Item from '$lib/components/ui/item/index.js';
- import * as Collapsible from '$lib/components/ui/collapsible/index.js';
- import { ArcaneButton } from '$lib/components/arcane-button/index.js';
- import type { Snippet } from 'svelte';
- import { m } from '$lib/paraglide/messages';
- import { sanitizeLogText } from '$lib/utils/formatting';
- import {
- type LayerProgress,
- type PullPhase,
- getPullPhase,
- getLayerStats,
- showImageLayersState,
- isIndeterminatePhase,
- getAggregatePullPhase,
- getAggregateStatus
- } from '$lib/utils/docker';
- import { DownloadIcon, BoxIcon, ArrowDownIcon, VerifiedCheckIcon, CloseIcon } from '$lib/icons';
- import { IsMobile } from '$lib/hooks/is-mobile.svelte.js';
-
- interface Props {
- open?: boolean;
- title?: string;
- completeTitle?: string;
- subtitle?: string;
- progress?: number;
- statusText?: string;
- error?: string;
- loading?: boolean;
- mode?: 'pull' | 'generic';
- align?: 'start' | 'center' | 'end';
- sideOffset?: number;
- class?: string;
- icon?: typeof DownloadIcon;
- iconClass?: string;
- preventCloseWhileLoading?: boolean;
- onCancel?: () => void;
- layers?: Record<string, LayerProgress>;
- outputLines?: string[];
- showOutputPanel?: boolean;
- outputPlaceholder?: string;
- triggerClass?: string;
- children: Snippet;
- }
-
- let {
- open = $bindable(false),
- title = m.progress_title(),
- completeTitle = '',
- subtitle = m.progress_subtitle(),
- progress = $bindable(0),
- statusText = '',
- error = '',
- loading = false,
- mode = 'pull',
- align = 'center',
- sideOffset = 4,
- class: className = '',
- icon,
- iconClass = 'size-5',
- preventCloseWhileLoading = true,
- onCancel,
- layers = {},
- outputLines = [],
- showOutputPanel = false,
- outputPlaceholder = m.build_output_placeholder(),
- triggerClass,
- children
- }: Props = $props();
-
- let outputContainer = $state<HTMLElement | null>(null);
-
- $effect(() => {
- if (!open || !outputContainer || outputLines.length === 0) return;
- queueMicrotask(() => {
- if (!outputContainer) return;
- outputContainer.scrollTop = outputContainer.scrollHeight;
- });
- });
-
- const isMobile = new IsMobile();
-
- const percent = $derived(Math.round(progress));
- const isComplete = $derived(progress >= 100);
- const hasStructuredProgress = $derived(Object.keys(layers).length > 0 || progress > 0);
-
- // Track if we've ever reached complete state to prevent flashing back
- let hasReachedComplete = $state(false);
-
- // Update complete tracking
- $effect(() => {
- if (isComplete && !error) {
- hasReachedComplete = true;
- }
- // Reset when popover closes
- if (!open) {
- hasReachedComplete = false;
- }
- });
-
- // Derive layer stats using utility
- const layerStats = $derived(getLayerStats(layers, hasReachedComplete));
-
- // Check if we're in an indeterminate phase (extracting with no byte progress)
- const isIndeterminate = $derived(isIndeterminatePhase(layers, progress));
- const isIndeterminateGeneric = $derived(mode !== 'pull' && loading && !isComplete && !error && !hasStructuredProgress);
- const cleanStatusText = $derived(sanitizeLogText(statusText));
- const genericStatus = $derived(cleanStatusText || subtitle);
-
- // Derive aggregate status for display
- const aggregateStatus = $derived(getAggregateStatus(layers, cleanStatusText, hasReachedComplete || isComplete));
-
- // Derive the current phase from status text using utility (pull-mode only)
- const currentPhase = $derived.by((): PullPhase => {
- if (Object.keys(layers).length > 0) {
- return getAggregatePullPhase(layers, hasReachedComplete || isComplete, !!error);
- }
- return getPullPhase(cleanStatusText, hasReachedComplete || isComplete, !!error);
- });
-
- // Get localized title based on phase
- const displayTitle = $derived.by(() => {
- if (mode !== 'pull') {
- if (error) return m.error_occurred();
- if (isComplete && !loading) return completeTitle || title;
- return title;
- }
-
- switch (currentPhase) {
- case 'error':
- return m.error_occurred();
- case 'complete':
- return m.progress_pull_completed();
- case 'downloading':
- return m.progress_downloading();
- case 'extracting':
- return m.progress_extracting();
- case 'verifying':
- return m.progress_verifying();
- case 'waiting':
- return m.progress_waiting();
- default:
- return title;
- }
- });
-
- // Get the appropriate icon based on phase
- const PhaseIcon = $derived.by(() => {
- if (currentPhase === 'extracting') return BoxIcon;
- return icon ?? DownloadIcon;
- });
-
- function handleOpenChange(next: boolean) {
- if (preventCloseWhileLoading && !next && loading) {
- open = true;
- return;
- }
- open = next;
- }
-
- function getLayerPhase(status: string): PullPhase {
- return getPullPhase(status, false, false);
- }
-</script>
-
-{#snippet content()}
- <Item.Root variant={error ? 'outline' : 'default'} class={cn(error && 'border-destructive/50')}>
- <Item.Media
- variant="icon"
- class={cn(
- error && 'bg-destructive/10 text-destructive',
- isComplete && !loading && !error && 'bg-green-500/10 text-green-500'
- )}
- >
- {#if error}
- <CloseIcon class={iconClass} />
- {:else if isComplete && !loading}
- <VerifiedCheckIcon class={iconClass} />
- {:else}
- <PhaseIcon class={cn(iconClass, loading && 'animate-pulse')} />
- {/if}
- </Item.Media>
- <Item.Content>
- <Item.Title class={cn(error && 'text-destructive')}>{displayTitle}</Item.Title>
- <Item.Description class={cn(error && 'line-clamp-none break-words whitespace-pre-wrap')}>
- {#if error}
- {error}
- {:else if mode !== 'pull' && layerStats.total > 0}
- {hasReachedComplete ? 100 : percent}% · {genericStatus}
- <span class="text-muted-foreground">
- · {m.progress_layers_status({ completed: layerStats.completed, total: layerStats.total })}</span
- >
- {:else if mode !== 'pull'}
- {#if hasStructuredProgress || loading || hasReachedComplete}
- {hasReachedComplete ? 100 : percent}% · {genericStatus}
- {:else}
- {genericStatus}
- {/if}
- {:else if layerStats.total > 0}
- {aggregateStatus || subtitle}
- <span class="text-muted-foreground">
- · {m.progress_layers_status({ completed: layerStats.completed, total: layerStats.total })}</span
- >
- {:else}
- {hasReachedComplete ? 100 : percent}% · {aggregateStatus || subtitle}
- {/if}
- </Item.Description>
- </Item.Content>
- {#if loading && onCancel}
- <Item.Actions>
- <ArcaneButton action="cancel" size="sm" onclick={onCancel} />
- </Item.Actions>
- {/if}
- {#if !error}
- <Item.Footer>
- <Progress
- value={hasReachedComplete || isIndeterminate ? 100 : progress}
- max={100}
- class="h-1.5 w-full"
- indeterminate={(isIndeterminate && !hasReachedComplete) || isIndeterminateGeneric}
- />
- </Item.Footer>
- {/if}
- </Item.Root>
-
- {#if Object.keys(layers).length > 0 && !error}
- <Collapsible.Root bind:open={showImageLayersState.current} class="mt-2">
- <Collapsible.Trigger
- class="text-muted-foreground hover:text-foreground hover:bg-accent flex w-full items-center justify-between rounded-md px-2 py-1.5 text-xs transition-colors"
- >
- {m.progress_show_layers()}
- <ArrowDownIcon class={cn('size-3 transition-transform', showImageLayersState.current && 'rotate-180')} />
- </Collapsible.Trigger>
- <Collapsible.Content>
- <div class="mt-2 max-h-48 space-y-1.5 overflow-y-auto">
- {#each Object.entries(layers) as [id, layer] (id)}
- {@const layerStatus = sanitizeLogText(layer.status || '')}
- {@const phase = hasReachedComplete ? 'complete' : getLayerPhase(layerStatus)}
- {@const layerPercent =
- phase === 'complete' ? 100 : layer.total > 0 ? Math.round((layer.current / layer.total) * 100) : 0}
- <div class="bg-muted/30 rounded-md px-2 py-1.5">
- <div class="flex items-center justify-between gap-2">
- <span class="text-muted-foreground truncate font-mono text-[10px]">{id.slice(0, 12)}</span>
- <span
- class={cn(
- 'text-[10px] font-medium',
- phase === 'complete' && 'text-green-500',
- phase === 'downloading' && 'text-blue-500',
- phase === 'extracting' && 'text-amber-500'
- )}
- >
- {#if phase === 'complete'}
- ✓
- {:else if layer.total > 0}
- {layerPercent}%
- {:else}
- {layerStatus}
- {/if}
- </span>
- </div>
- <Progress value={layerPercent} max={100} class="mt-1 h-1" />
- </div>
- {/each}
- </div>
- </Collapsible.Content>
- </Collapsible.Root>
- {/if}
-
- {#if (showOutputPanel || outputLines.length > 0) && !error}
- <div class="mt-2 overflow-hidden rounded-md border border-white/10 bg-black/80">
- <div class="flex items-center justify-between border-b border-white/10 px-2 py-1">
- <span class="text-[10px] font-medium tracking-wide text-emerald-300/80 uppercase">{m.build_output()}</span>
- <span class="text-[10px] text-emerald-300/60">{outputLines.length}</span>
- </div>
- <pre
- bind:this={outputContainer}
- class="max-h-40 overflow-y-auto px-2 py-2 font-mono text-[11px] leading-relaxed whitespace-pre-wrap text-emerald-200">{#if outputLines.length > 0}{#each outputLines as line, i (i)}<span
- class="block break-words">{line}</span
- >{/each}{:else}<span class="text-emerald-300/60">{outputPlaceholder}</span>{/if}</pre>
- </div>
- {/if}
-{/snippet}
-{#if isMobile.current}
- <Dialog.Root bind:open onOpenChange={handleOpenChange}>
- <Dialog.Trigger>
- {#snippet child({ props })}
- <span {...props} class={cn('inline-flex w-fit', triggerClass)}>
- {@render children()}
- </span>
- {/snippet}
- </Dialog.Trigger>
- <Dialog.Content class={cn('p-2', error && 'max-w-[600px]', className)} showCloseButton={!loading}>
- {@render content()}
- </Dialog.Content>
- </Dialog.Root>
-{:else}
- <Popover.Root bind:open onOpenChange={handleOpenChange}>
- <Popover.Trigger>
- {#snippet child({ props })}
- <span {...props} class={cn('inline-flex w-fit', triggerClass)}>
- {@render children()}
- </span>
- {/snippet}
- </Popover.Trigger>
-
- <Popover.Content class={cn('w-80 p-2', error && 'w-auto max-w-[600px]', className)} {align} {sideOffset}>
- {@render content()}
- <PopoverPrimitive.Arrow class="fill-background stroke-border" />
- </Popover.Content>
- </Popover.Root>
-{/if}
diff --git a/frontend/src/lib/components/sheets/image-pull-sheet.svelte b/frontend/src/lib/components/sheets/image-pull-sheet.svelte
index c7603e169..fe475cd30 100644
--- a/frontend/src/lib/components/sheets/image-pull-sheet.svelte
+++ b/frontend/src/lib/components/sheets/image-pull-sheet.svelte
@@ -2,28 +2,11 @@
import * as ResponsiveDialog from '$lib/components/ui/responsive-dialog/index.js';
import { ArcaneButton } from '$lib/components/arcane-button/index.js';
import FormInput from '$lib/components/form/form-input.svelte';
- import { Progress } from '$lib/components/ui/progress/index.js';
- import * as Collapsible from '$lib/components/ui/collapsible/index.js';
import { z } from 'zod/v4';
import { createForm, preventDefault } from '$lib/utils/settings';
import { toast } from 'svelte-sonner';
import { environmentStore } from '$lib/stores/environment.store.svelte';
import { m } from '$lib/paraglide/messages';
- import { cn } from '$lib/utils.js';
- import {
- type LayerProgress,
- type PullPhase,
- calculateOverallProgress,
- areAllLayersComplete,
- updateLayerFromStreamData,
- extractErrorMessage,
- getLayerStats,
- getPullPhase,
- showImageLayersState,
- isIndeterminatePhase,
- getAggregateStatus
- } from '$lib/utils/docker';
- import { ArrowDownIcon } from '$lib/icons';
type ImagePullFormProps = {
open: boolean;
@@ -45,53 +28,12 @@
let { inputs, ...form } = $derived(createForm<typeof formSchema>(formSchema, formData));
let isPulling = $state(false);
- let pullProgress = $state(0);
- let pullStatusText = $state('');
- let pullError = $state('');
- let layerProgress = $state<Record<string, LayerProgress>>({});
- let hasReachedComplete = $state(false);
- let currentImageName = $state('');
- const layerStats = $derived(getLayerStats(layerProgress, hasReachedComplete));
- const aggregateStatus = $derived(getAggregateStatus(layerProgress, pullStatusText, hasReachedComplete));
- const showPullUI = $derived(isPulling || hasReachedComplete || !!pullError);
- const isIndeterminate = $derived(isIndeterminatePhase(layerProgress, pullProgress));
- let prevOpen = $state(false);
-
- $effect(() => {
- if (prevOpen && !open && !isPulling) {
- // Sheet just closed, reset state and form
- resetState();
- $inputs.imageRef.value = '';
- $inputs.tag.value = 'latest';
- }
- prevOpen = open;
- });
-
- function getLayerPhase(status: string): PullPhase {
- return getPullPhase(status, false, false);
- }
-
- function resetState() {
- isPulling = false;
- pullProgress = 0;
- pullStatusText = '';
- pullError = '';
- layerProgress = {};
- hasReachedComplete = false;
- currentImageName = '';
- }
-
- function updateProgress() {
- pullProgress = calculateOverallProgress(layerProgress);
- }
async function handleSubmit() {
const data = form.validate();
if (!data) return;
- resetState();
isPulling = true;
- pullStatusText = m.images_pull_initiating();
let imageName = data.imageRef.trim();
let imageTag = data.tag?.trim() || 'latest';
@@ -99,7 +41,6 @@
if (imageName.includes(':')) {
const lastColonIndex = imageName.lastIndexOf(':');
const possibleTag = imageName.substring(lastColonIndex + 1).trim();
- // Only split if the part after the last colon looks like a tag (not a port number in a registry URL)
if (possibleTag && !possibleTag.includes('/')) {
imageName = imageName.substring(0, lastColonIndex);
imageTag = possibleTag;
@@ -107,16 +48,12 @@
}
const fullImageName = `${imageName}:${imageTag}`;
- currentImageName = fullImageName;
const envId = await environmentStore.getCurrentEnvironmentId();
- pullStatusText = m.images_pull_initiating();
try {
const response = await fetch(`/api/environments/${envId}/images/pull`, {
method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
+ headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ imageName: fullImageName })
});
@@ -124,101 +61,73 @@
const errorData = await response.json().catch(() => ({
data: { message: m.images_pull_server_error() }
}));
-
const errorMessage =
errorData.data?.message ||
errorData.error ||
errorData.message ||
`${m.images_pull_server_error()}: HTTP ${response.status}`;
-
throw new Error(errorMessage);
}
- const reader = response.body.getReader();
- const decoder = new TextDecoder();
- let buffer = '';
-
- while (true) {
- const { done, value } = await reader.read();
- if (done) {
- pullStatusText = m.images_pull_processing_final_layers();
- break;
- }
-
- buffer += decoder.decode(value, { stream: true });
- const lines = buffer.split('\n');
- buffer = lines.pop() || '';
-
- for (const line of lines) {
- if (line.trim() === '') continue;
- try {
- const data = JSON.parse(line);
-
- const errorMsg = extractErrorMessage(data, m.images_pull_stream_error());
- if (errorMsg) {
- console.error('Error in stream:', errorMsg);
- pullError = errorMsg;
- pullStatusText = m.images_pull_failed_with_error({ error: pullError });
- continue;
- }
-
- if (data.status) pullStatusText = data.status;
- layerProgress = updateLayerFromStreamData(layerProgress, data);
- updateProgress();
- } catch (e: any) {
- console.warn('Failed to parse stream line or process data:', line, e);
- }
- }
- }
-
- updateProgress();
- if (!pullError && pullProgress < 100 && areAllLayersComplete(layerProgress)) {
- pullProgress = 100;
- }
-
- if (pullError) {
- throw new Error(pullError);
- }
-
- hasReachedComplete = true;
- pullProgress = 100;
- pullStatusText = m.images_pull_success({ repoTag: fullImageName });
- toast.success(m.images_pull_success({ repoTag: fullImageName }));
- onPullFinished(true, fullImageName);
+ open = false;
+ isPulling = false;
- // Close sheet after a brief delay to show success state
- // State will be reset by handleOpenChange when sheet closes
- setTimeout(() => {
- open = false;
- }, 1500);
+ drainPullStream(response.body, fullImageName);
} catch (error: any) {
- console.error('Pull image error:', error);
const message = error.message || m.images_pull_unexpected_error();
- pullError = message;
- pullStatusText = m.images_pull_failed_with_error({ error: message });
toast.error(message);
onPullFinished(false, fullImageName, message);
- } finally {
isPulling = false;
}
}
+ function drainPullStream(body: ReadableStream<Uint8Array>, fullImageName: string) {
+ const reader = body.getReader();
+ const decoder = new TextDecoder();
+ let buffer = '';
+
+ (async () => {
+ try {
+ while (true) {
+ const { done, value } = await reader.read();
+ if (done) break;
+
+ buffer += decoder.decode(value, { stream: true });
+ const lines = buffer.split('\n');
+ buffer = lines.pop() || '';
+
+ for (const line of lines) {
+ if (!line.trim()) continue;
+ try {
+ const parsed = JSON.parse(line);
+ if (parsed?.error) {
+ const errMsg =
+ typeof parsed.error === 'string' ? parsed.error : parsed.error.message || m.images_pull_stream_error();
+ toast.error(errMsg);
+ onPullFinished(false, fullImageName, errMsg);
+ return;
+ }
+ } catch {
+ // ignore non-JSON lines
+ }
+ }
+ }
+ onPullFinished(true, fullImageName);
+ } catch (error: any) {
+ const message = error.message || m.images_pull_unexpected_error();
+ toast.error(message);
+ onPullFinished(false, fullImageName, message);
+ }
+ })();
+ }
+
function handleOpenChange(newOpenState: boolean) {
if (!newOpenState && isPulling) {
- toast.info(m.images_pull_in_progress_toast());
- open = true; // Keep it open
return;
}
open = newOpenState;
- if (!newOpenState) {
- // Reset when closing (if we get here, isPulling is false)
- resetState();
- $inputs.imageRef.value = '';
- $inputs.tag.value = 'latest';
- } else {
- // Also reset when opening to ensure clean state
- resetState();
+ if (!newOpenState || newOpenState) {
$inputs.imageRef.value = '';
$inputs.tag.value = 'latest';
}
@@ -226,138 +135,36 @@
</script>
<ResponsiveDialog.Root
- bind:open
+ {open}
onOpenChange={handleOpenChange}
variant="sheet"
title={m.images_pull_image()}
- description={showPullUI && currentImageName ? currentImageName : m.images_pull_description()}
+ description={m.images_pull_description()}
contentClass="sm:max-w-[600px]"
>
{#snippet children()}
- {#if showPullUI}
- <!-- Pull progress UI -->
- <div class="space-y-4 py-6">
- {#if pullError}
- <div class="bg-destructive/10 text-destructive rounded-lg p-4">
- <p class="text-sm font-medium">{m.image_update_error_label()}</p>
- <p class="mt-1 text-xs">{pullError}</p>
- </div>
- {:else}
- <!-- Progress status -->
- <div class="space-y-2">
- <div class="flex items-center justify-between">
- <p class="text-sm font-medium">
- {#if hasReachedComplete}
- {m.progress_pull_completed()}
- {:else if layerStats.total > 0}
- <span class="flex items-center gap-1.5">
- <span>{aggregateStatus}</span>
- <span class="text-muted-foreground font-normal">•</span>
- <span class="text-muted-foreground font-normal">
- {m.progress_layers_status({ completed: layerStats.completed, total: layerStats.total })}
- </span>
- </span>
- {:else}
- {aggregateStatus || m.common_action_pulling()}
- {/if}
- </p>
- {#if !isIndeterminate || hasReachedComplete}
- <p class="text-muted-foreground text-sm">{Math.round(hasReachedComplete ? 100 : pullProgress)}%</p>
- {/if}
- </div>
- <Progress
- value={hasReachedComplete || isIndeterminate ? 100 : pullProgress}
- max={100}
- class="h-2 w-full"
- indeterminate={isIndeterminate && !hasReachedComplete}
- />
- </div>
-
- {#if Object.keys(layerProgress).length > 0}
- <Collapsible.Root bind:open={showImageLayersState.current}>
- <Collapsible.Trigger
- class="text-muted-foreground hover:text-foreground hover:bg-accent flex w-full items-center justify-between rounded-md px-2 py-1.5 text-xs transition-colors"
- >
- {m.progress_show_layers()}
- <ArrowDownIcon class={cn('size-4 transition-transform', showImageLayersState.current && 'rotate-180')} />
- </Collapsible.Trigger>
- <Collapsible.Content>
- <div class="mt-2 space-y-1.5">
- {#each Object.entries(layerProgress) as [id, layer] (id)}
- {@const phase = hasReachedComplete ? 'complete' : getLayerPhase(layer.status)}
- {@const layerPercent =
- phase === 'complete' ? 100 : layer.total > 0 ? Math.round((layer.current / layer.total) * 100) : 0}
- <div class="bg-muted/30 rounded-md px-2 py-1.5">
- <div class="flex items-center justify-between gap-2">
- <span class="text-muted-foreground truncate font-mono text-[10px]">{id.slice(0, 12)}</span>
- <span
- class={cn(
- 'shrink-0 text-[10px] font-medium',
- phase === 'complete' && 'text-green-500',
- phase === 'downloading' && 'text-blue-500',
- phase === 'extracting' && 'text-amber-500'
- )}
- >
- {#if phase === 'complete'}
- ✓
- {:else if layer.total > 0}
- {layerPercent}%
- {:else}
- {layer.status}
- {/if}
- </span>
- </div>
- <Progress value={layerPercent} max={100} class="mt-1 h-1" />
- </div>
- {/each}
- </div>
- </Collapsible.Content>
- </Collapsible.Root>
- {/if}
-
- {#if isPulling}
- <p class="text-muted-foreground text-xs">{m.images_pull_wait_message()}</p>
- {/if}
- {/if}
- </div>
- {:else}
- <form onsubmit={preventDefault(handleSubmit)} class="grid gap-4 py-6">
- <FormInput
- label={m.images_image_name_label()}
- type="text"
- placeholder={m.images_image_name_placeholder()}
- description={m.images_image_name_description()}
- bind:input={$inputs.imageRef}
- />
- <FormInput
- label={m.images_tag()}
- type="text"
- placeholder={m.images_tag_latest()}
- description={m.images_tag_description()}
- bind:input={$inputs.tag}
- />
- </form>
- {/if}
+ <form onsubmit={preventDefault(handleSubmit)} class="grid gap-4 py-6">
+ <FormInput
+ label={m.images_image_name_label()}
+ type="text"
+ placeholder={m.images_image_name_placeholder()}
+ description={m.images_image_name_description()}
+ bind:input={$inputs.imageRef}
+ />
+ <FormInput
+ label={m.images_tag()}
+ type="text"
+ placeholder={m.images_tag_latest()}
+ description={m.images_tag_description()}
+ bind:input={$inputs.tag}
+ />
+ </form>
{/snippet}
{#snippet footer()}
- {#if pullError}
- <div class="flex w-full flex-row gap-2">
- <ArcaneButton
- action="base"
- tone="outline"
- type="button"
- class="flex-1"
- onclick={() => resetState()}
- customLabel={m.common_retry()}
- />
- <ArcaneButton action="base" type="button" class="flex-1" onclick={() => (open = false)} customLabel={m.common_close()} />
- </div>
- {:else if !showPullUI}
- <div class="flex w-full flex-row gap-2">
- <ArcaneButton action="cancel" tone="outline" type="button" class="flex-1" onclick={() => (open = false)} />
- <ArcaneButton action="pull" type="submit" class="flex-1" onclick={handleSubmit} />
- </div>
- {/if}
+ <div class="flex w-full flex-row gap-2">
+ <ArcaneButton action="cancel" tone="outline" type="button" class="flex-1" onclick={() => (open = false)} />
+ <ArcaneButton action="pull" type="submit" class="flex-1" onclick={handleSubmit} disabled={isPulling} />
+ </div>
{/snippet}
</ResponsiveDialog.Root>
diff --git a/frontend/src/lib/components/sidebar/sidebar.svelte b/frontend/src/lib/components/sidebar/sidebar.svelte
index b7d12a05f..4cb9c3602 100644
--- a/frontend/src/lib/components/sidebar/sidebar.svelte
+++ b/frontend/src/lib/components/sidebar/sidebar.svelte
@@ -20,6 +20,7 @@
import SidebarLogo from './sidebar-logo.svelte';
import SidebarUpdatebanner from './sidebar-updatebanner.svelte';
import SidebarPinButton from './sidebar-pin-button.svelte';
+ import ActivityCenterTrigger from '$lib/components/activity/activity-center-trigger.svelte';
import userStore from '$lib/stores/user-store';
import settingsStore from '$lib/stores/config-store';
import { m } from '$lib/paraglide/messages';
@@ -99,6 +100,17 @@
{:else}
<SidebarEnvSwitcher onOpenDialog={() => (envSwitcherOpen = true)} />
{/if}
+ {#if isCollapsed}
+ <div class="flex justify-center px-1 pt-1">
+ <ActivityCenterTrigger collapsed compact />
+ </div>
+ {:else}
+ <Sidebar.Menu class="pt-1">
+ <Sidebar.MenuItem>
+ <ActivityCenterTrigger compact />
+ </Sidebar.MenuItem>
+ </Sidebar.Menu>
+ {/if}
</Sidebar.Header>
<Sidebar.Content class={!isCollapsed ? '-mt-2' : ''}>
{#if managementItems.length > 0}
diff --git a/frontend/src/lib/components/vulnerability/vulnerability-scan-item.svelte b/frontend/src/lib/components/vulnerability/vulnerability-scan-item.svelte
index 75a8acf6b..b98932657 100644
--- a/frontend/src/lib/components/vulnerability/vulnerability-scan-item.svelte
+++ b/frontend/src/lib/components/vulnerability/vulnerability-scan-item.svelte
@@ -9,6 +9,7 @@
import { formatTime } from '$lib/utils/formatting';
import { queryKeys } from '$lib/query/query-keys';
import { vulnerabilityService } from '$lib/services/vulnerability-service';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
import {
startVulnerabilityScanPolling,
stabilizeFailedVulnerabilitySummary,
@@ -45,9 +46,9 @@
const isScanInProgress = $derived(isScanning || isVulnerabilityScanInProgress(scanSummary?.status));
const scanPhaseSteps = [
- { key: 'creating_container', label: 'Creating container' },
- { key: 'scanning_image', label: 'Scanning image' },
- { key: 'storing_results', label: 'Storing results' }
+ { key: 'creating_container', label: m.activity_scan_phase_creating_container() },
+ { key: 'scanning_image', label: m.activity_scan_phase_scanning_image() },
+ { key: 'storing_results', label: m.activity_scan_phase_storing_results() }
] as const;
const scanErrorMessage = $derived.by(() => {
const detail = scanSummary?.error?.trim();
@@ -134,6 +135,7 @@
imageId: result.imageId,
scanTime: result.scanTime,
status: result.status,
+ activityId: result.activityId,
scanPhase: result.scanPhase,
summary: result.summary,
error: result.error
@@ -141,10 +143,11 @@
scanSummary = summary;
onScanned?.(summary);
if (result.status === 'completed') {
- toast.success(m.vuln_scan_completed());
+ toast.success(m.vuln_scan_completed(), activityToastOptions(result.activityId));
} else if (result.status === 'failed') {
- toast.error(result.error || m.vuln_scan_failed());
+ toast.error(result.error || m.vuln_scan_failed(), activityToastOptions(result.activityId));
} else if (pollingEnabled) {
+ toast.info(m.vuln_scan_started(), activityToastOptions(result.activityId));
beginPolling(true);
}
}
@@ -207,10 +210,11 @@
stopScanPolling();
if (showToast) {
+ const toastOptions = activityToastOptions(extractActivityId(resolvedSummary));
if (resolvedSummary.status === 'completed') {
- toast.success(m.vuln_scan_completed());
+ toast.success(m.vuln_scan_completed(), toastOptions);
} else {
- toast.error(resolvedSummary.error || m.vuln_scan_failed());
+ toast.error(resolvedSummary.error || m.vuln_scan_failed(), toastOptions);
}
}
},
diff --git a/frontend/src/lib/config/navigation-config.ts b/frontend/src/lib/config/navigation-config.ts
index d0e664976..f2bf2478a 100644
--- a/frontend/src/lib/config/navigation-config.ts
+++ b/frontend/src/lib/config/navigation-config.ts
@@ -25,7 +25,8 @@ import {
TemplateIcon,
GlobeIcon,
UpdateIcon,
- VariableIcon
+ VariableIcon,
+ ActivityIcon
} from '$lib/icons';
import { m } from '$lib/paraglide/messages';
import type { ShortcutKey } from '$lib/utils/navigation';
@@ -258,6 +259,13 @@ export const navigationItems: NavigationSections = {
scope: 'env',
requiredPermission: 'notifications:manage'
},
+ {
+ title: m.activity_settings_title(),
+ url: '/settings/activity',
+ icon: ActivityIcon,
+ scope: 'env',
+ requiredPermission: 'settings:read'
+ },
{
title: m.builds(),
url: '/settings/builds',
diff --git a/frontend/src/lib/icons/index.ts b/frontend/src/lib/icons/index.ts
index 2f1963bd1..d651c81d9 100644
--- a/frontend/src/lib/icons/index.ts
+++ b/frontend/src/lib/icons/index.ts
@@ -12,6 +12,7 @@ export { default as ImagesIcon } from 'virtual:icons/solar/gallery-linear';
export { default as NetworksIcon } from 'virtual:icons/fluent/virtual-network-16-filled';
export { default as VolumesIcon } from 'virtual:icons/fluent/hard-drive-20-filled';
export { default as EventsIcon } from 'virtual:icons/material-symbols/event-list';
+export { default as ActivityIcon } from 'virtual:icons/lucide/activity';
export { default as SettingsIcon } from 'virtual:icons/solar/settings-outline';
export { default as AppearanceIcon } from 'virtual:icons/f7/paintbrush';
export { default as DockerBrandIcon } from 'virtual:icons/cib/docker';
diff --git a/frontend/src/lib/services/activity-service.ts b/frontend/src/lib/services/activity-service.ts
new file mode 100644
index 000000000..45ec59d00
--- /dev/null
+++ b/frontend/src/lib/services/activity-service.ts
@@ -0,0 +1,60 @@
+import BaseAPIService, { handleUnauthorizedResponseInternal } from './api-service';
+import { environmentStore } from '$lib/stores/environment.store.svelte';
+import type { Activity, ActivityClearHistoryResult, ActivityDetail } from '$lib/types/activity.type';
+import type { Paginated, SearchPaginationSortRequest } from '$lib/types/shared';
+import { transformPaginationParams } from '$lib/utils/tables';
+
+export class ActivityService extends BaseAPIService {
+ private async resolveEnvironmentId(environmentId?: string): Promise<string> {
+ return environmentId ?? (await environmentStore.getCurrentEnvironmentId());
+ }
+
+ async getActivities(options?: SearchPaginationSortRequest, environmentId?: string): Promise<Paginated<Activity>> {
+ const envId = await this.resolveEnvironmentId(environmentId);
+ const params = transformPaginationParams(options);
+ const res = await this.api.get(`/environments/${envId}/activities`, { params });
+ return res.data;
+ }
+
+ async getActivity(activityId: string, environmentId?: string, limit = 500): Promise<ActivityDetail> {
+ const envId = await this.resolveEnvironmentId(environmentId);
+ return this.handleResponse(this.api.get(`/environments/${envId}/activities/${activityId}`, { params: { limit } }));
+ }
+
+ async clearHistory(environmentId?: string): Promise<ActivityClearHistoryResult> {
+ const envId = await this.resolveEnvironmentId(environmentId);
+ return this.handleResponse(this.api.delete(`/environments/${envId}/activities/history`));
+ }
+
+ getActivityStreamUrl(environmentId: string, limit = 50): string {
+ const baseUrl = this.api.defaults.baseURL.replace(/\/+$/, '');
+ const params = new URLSearchParams({ limit: String(limit) });
+ return `${baseUrl}/environments/${encodeURIComponent(environmentId)}/activities/stream?${params.toString()}`;
+ }
+
+ async openActivityStream(environmentId: string, signal: AbortSignal, limit = 50, retry = false): Promise<Response> {
+ const response = await fetch(this.getActivityStreamUrl(environmentId, limit), {
+ credentials: 'include',
+ headers: { Accept: 'application/x-json-stream' },
+ signal
+ });
+ if (response.status === 401) {
+ const action = await handleUnauthorizedResponseInternal(
+ `/environments/${encodeURIComponent(environmentId)}/activities/stream`,
+ retry
+ );
+ if (action === 'retry') {
+ return this.openActivityStream(environmentId, signal, limit, true);
+ }
+ if (action === 'redirect') {
+ return new Promise<Response>(() => {});
+ }
+ }
+ if (!response.ok) {
+ throw new Error(`Activity stream failed with status ${response.status}`);
+ }
+ return response;
+ }
+}
+
+export const activityService = new ActivityService();
diff --git a/frontend/src/lib/services/api-service.ts b/frontend/src/lib/services/api-service.ts
index 598932076..4452b30b5 100644
--- a/frontend/src/lib/services/api-service.ts
+++ b/frontend/src/lib/services/api-service.ts
@@ -161,6 +161,66 @@ function getRequestPath(url: string, baseURL: string): string {
}
let tokenRefreshHandler: (() => Promise<string | null>) | null = null;
+const skipAuthPathsInternal = [
+ '/auth/login',
+ '/auth/logout',
+ '/auth/refresh',
+ '/auth/oidc',
+ '/auth/oidc/login',
+ '/auth/oidc/callback',
+ '/auth/auto-login',
+ '/auth/auto-login-config',
+ '/settings/public'
+];
+
+type UnauthorizedActionInternal = 'none' | 'redirect' | 'retry';
+
+function isAuthPagePathInternal(pathname: string): boolean {
+ return (
+ pathname.startsWith('/login') ||
+ pathname.startsWith('/logout') ||
+ pathname.startsWith('/oidc') ||
+ pathname.startsWith('/auth/oidc')
+ );
+}
+
+export async function handleUnauthorizedResponseInternal(
+ requestPath: string,
+ retry = false,
+ serverMsg?: string | null
+): Promise<UnauthorizedActionInternal> {
+ if (typeof window === 'undefined' || retry) {
+ return 'none';
+ }
+
+ const isVersionMismatch = serverMsg?.toLowerCase().includes('application has been updated');
+ const isAuthApi = skipAuthPathsInternal.some((path) => requestPath.startsWith(path));
+ const pathname = window.location.pathname || '/';
+ const isOnAuthPage = isAuthPagePathInternal(pathname);
+
+ if (!isAuthApi && !isOnAuthPage && tokenRefreshHandler) {
+ try {
+ await tokenRefreshHandler();
+ return 'retry';
+ } catch {
+ if (isVersionMismatch) {
+ toast.info('Application has been updated. Please log in again.');
+ }
+ const redirectTo = encodeURIComponent(pathname);
+ window.location.replace(`/login?redirect=${redirectTo}`);
+ return 'redirect';
+ }
+ }
+
+ if (!isAuthApi && !isOnAuthPage && isVersionMismatch) {
+ toast.info('Application has been updated. Please log in again.');
+ const redirectTo = encodeURIComponent(pathname);
+ window.location.replace(`/login?redirect=${redirectTo}`);
+ return 'redirect';
+ }
+
+ return 'none';
+}
class APIClient {
defaults: { baseURL: string };
@@ -232,49 +292,18 @@ class APIClient {
};
if (errorResponse.status === 401 && typeof window !== 'undefined' && !config._retry) {
- const serverMsg = extractServerMessage(parsed);
- const isVersionMismatch = serverMsg?.toLowerCase().includes('application has been updated');
- const reqUrl = getRequestPath(url, baseURL);
- const skipAuthPaths = [
- '/auth/login',
- '/auth/logout',
- '/auth/refresh',
- '/auth/oidc',
- '/auth/oidc/login',
- '/auth/oidc/callback',
- '/auth/auto-login',
- '/auth/auto-login-config',
- '/settings/public'
- ];
- const isAuthApi = skipAuthPaths.some((path) => reqUrl.startsWith(path));
- const pathname = window.location.pathname || '/';
- const isOnAuthPage =
- pathname.startsWith('/login') ||
- pathname.startsWith('/logout') ||
- pathname.startsWith('/oidc') ||
- pathname.startsWith('/auth/oidc');
-
- if (!isAuthApi && !isOnAuthPage && tokenRefreshHandler) {
- try {
- await tokenRefreshHandler();
- return this.performRequest<T>(method, url, data, {
- ...config,
- _retry: true
- });
- } catch {
- if (isVersionMismatch) {
- toast.info('Application has been updated. Please log in again.');
- }
- const redirectTo = encodeURIComponent(pathname);
- window.location.replace(`/login?redirect=${redirectTo}`);
- return new Promise(() => {});
- }
+ const action = await handleUnauthorizedResponseInternal(
+ getRequestPath(url, baseURL),
+ !!config._retry,
+ extractServerMessage(parsed)
+ );
+ if (action === 'retry') {
+ return this.performRequest<T>(method, url, data, {
+ ...config,
+ _retry: true
+ });
}
-
- if (!isAuthApi && !isOnAuthPage && isVersionMismatch) {
- toast.info('Application has been updated. Please log in again.');
- const redirectTo = encodeURIComponent(pathname);
- window.location.replace(`/login?redirect=${redirectTo}`);
+ if (action === 'redirect') {
return new Promise(() => {});
}
}
diff --git a/frontend/src/lib/services/image-service.ts b/frontend/src/lib/services/image-service.ts
index 7dd45303c..f62be729d 100644
--- a/frontend/src/lib/services/image-service.ts
+++ b/frontend/src/lib/services/image-service.ts
@@ -49,9 +49,9 @@ export class ImageService extends BaseAPIService {
return this.handleResponse(this.api.post(`/environments/${envId}/images/pull`, { imageName, tag, auth }));
}
- async deleteImage(imageId: string, options?: { force?: boolean; noprune?: boolean }): Promise<void> {
+ async deleteImage(imageId: string, options?: { force?: boolean; noprune?: boolean }): Promise<any> {
const envId = await environmentStore.getCurrentEnvironmentId();
- await this.handleResponse(this.api.delete(`/environments/${envId}/images/${imageId}`, { params: options }));
+ return this.handleResponse(this.api.delete(`/environments/${envId}/images/${imageId}`, { params: options }));
}
async pruneImages(options: PruneImagesOptions): Promise<any> {
diff --git a/frontend/src/lib/services/volume-backup-service.ts b/frontend/src/lib/services/volume-backup-service.ts
index 15b89acff..b29ca5803 100644
--- a/frontend/src/lib/services/volume-backup-service.ts
+++ b/frontend/src/lib/services/volume-backup-service.ts
@@ -20,12 +20,12 @@ export class VolumeBackupService extends BaseAPIService {
return res.data;
}
- async restoreBackup(volumeName: string, backupId: string): Promise<void> {
+ async restoreBackup(volumeName: string, backupId: string): Promise<any> {
const envId = await environmentStore.getCurrentEnvironmentId();
return this.handleResponse(this.api.post(`/environments/${envId}/volumes/${volumeName}/backups/${backupId}/restore`));
}
- async restoreBackupFiles(volumeName: string, backupId: string, paths: string[]): Promise<void> {
+ async restoreBackupFiles(volumeName: string, backupId: string, paths: string[]): Promise<any> {
const envId = await environmentStore.getCurrentEnvironmentId();
return this.handleResponse(
this.api.post(`/environments/${envId}/volumes/${volumeName}/backups/${backupId}/restore-files`, {
@@ -48,7 +48,7 @@ export class VolumeBackupService extends BaseAPIService {
return res.data.data ?? [];
}
- async deleteBackup(backupId: string): Promise<void> {
+ async deleteBackup(backupId: string): Promise<any> {
const envId = await environmentStore.getCurrentEnvironmentId();
return this.handleResponse(this.api.delete(`/environments/${envId}/volumes/backups/${backupId}`));
}
@@ -68,7 +68,7 @@ export class VolumeBackupService extends BaseAPIService {
link.remove();
}
- async uploadAndRestore(volumeName: string, file: File): Promise<void> {
+ async uploadAndRestore(volumeName: string, file: File): Promise<any> {
const envId = await environmentStore.getCurrentEnvironmentId();
const formData = new FormData();
formData.append('file', file);
diff --git a/frontend/src/lib/services/volume-browser-service.ts b/frontend/src/lib/services/volume-browser-service.ts
index 29a35b93b..fdc94a1eb 100644
--- a/frontend/src/lib/services/volume-browser-service.ts
+++ b/frontend/src/lib/services/volume-browser-service.ts
@@ -37,7 +37,7 @@ export class VolumeBrowserService extends BaseAPIService {
link.remove();
}
- async uploadFile(volumeName: string, path: string, file: File): Promise<void> {
+ async uploadFile(volumeName: string, path: string, file: File): Promise<any> {
const envId = await environmentStore.getCurrentEnvironmentId();
const formData = new FormData();
formData.append('file', file);
@@ -48,7 +48,7 @@ export class VolumeBrowserService extends BaseAPIService {
);
}
- async createDirectory(volumeName: string, path: string): Promise<void> {
+ async createDirectory(volumeName: string, path: string): Promise<any> {
const envId = await environmentStore.getCurrentEnvironmentId();
return this.handleResponse(
this.api.post(`/environments/${envId}/volumes/${volumeName}/browse/mkdir`, null, {
@@ -57,7 +57,7 @@ export class VolumeBrowserService extends BaseAPIService {
);
}
- async deleteFile(volumeName: string, path: string): Promise<void> {
+ async deleteFile(volumeName: string, path: string): Promise<any> {
const envId = await environmentStore.getCurrentEnvironmentId();
return this.handleResponse(
this.api.delete(`/environments/${envId}/volumes/${volumeName}/browse`, {
diff --git a/frontend/src/lib/stores/activity.store.svelte.ts b/frontend/src/lib/stores/activity.store.svelte.ts
new file mode 100644
index 000000000..a764f01c8
--- /dev/null
+++ b/frontend/src/lib/stores/activity.store.svelte.ts
@@ -0,0 +1,435 @@
+import { browser } from '$app/environment';
+import { activityService } from '$lib/services/activity-service';
+import { environmentStore, LOCAL_DOCKER_ENVIRONMENT_ID } from '$lib/stores/environment.store.svelte';
+import type {
+ Activity,
+ ActivityDetail,
+ ActivityFilter,
+ ActivityMessage,
+ ActivityStatus,
+ ActivityStreamEvent
+} from '$lib/types/activity.type';
+
+const ACTIVITY_LIST_LIMIT = 50;
+const ACTIVITY_DETAIL_LIMIT = 500;
+const MAX_RECONNECT_DELAY = 15_000;
+const MAX_RECONNECT_ATTEMPTS = 20;
+
+function sortActivitiesInternal(items: Activity[]): Activity[] {
+ return [...items].sort((a, b) => {
+ const aActive = isActiveStatusInternal(a.status);
+ const bActive = isActiveStatusInternal(b.status);
+ if (aActive !== bActive) return aActive ? -1 : 1;
+ return getActivitySortTimeInternal(b) - getActivitySortTimeInternal(a);
+ });
+}
+
+function getActivitySortTimeInternal(activity: Activity): number {
+ const value = activity.updatedAt || activity.endedAt || activity.startedAt || activity.createdAt;
+ return value ? new Date(value).getTime() : 0;
+}
+
+function isActiveStatusInternal(status: ActivityStatus): boolean {
+ return status === 'queued' || status === 'running';
+}
+
+function filterActivityInternal(activity: Activity, filter: ActivityFilter): boolean {
+ switch (filter) {
+ case 'running':
+ return isActiveStatusInternal(activity.status);
+ case 'failed':
+ return activity.status === 'failed';
+ case 'completed':
+ return activity.status === 'success' || activity.status === 'cancelled';
+ }
+}
+
+function createActivityStore() {
+ let _activities = $state<Activity[]>([]);
+ let _details = $state<Record<string, ActivityDetail>>({});
+ let _expandedActivityIds = $state<Record<string, boolean>>({});
+ let _detailLoadingIds = $state<Record<string, boolean>>({});
+ let _detailErrorIds = $state<Record<string, boolean>>({});
+ let _filter = $state<ActivityFilter>('running');
+ let _open = $state(false);
+ let _loading = $state(false);
+ let _connected = $state(false);
+ let _streamError = $state(false);
+ let _currentEnvironmentId = $state(LOCAL_DOCKER_ENVIRONMENT_ID);
+
+ let started = false;
+ let streamGeneration = 0;
+ let streamAbortController: AbortController | null = null;
+ let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
+ let unsubscribeEnvironment: (() => void) | null = null;
+ let reconnectAttempt = 0;
+
+ function clearReconnectTimerInternal() {
+ if (reconnectTimer) {
+ clearTimeout(reconnectTimer);
+ reconnectTimer = null;
+ }
+ }
+
+ function abortStreamInternal() {
+ clearReconnectTimerInternal();
+ streamAbortController?.abort();
+ streamAbortController = null;
+ _connected = false;
+ }
+
+ function resetEnvironmentStateInternal(environmentId: string) {
+ _currentEnvironmentId = environmentId || LOCAL_DOCKER_ENVIRONMENT_ID;
+ _activities = [];
+ _details = {};
+ _expandedActivityIds = {};
+ _detailLoadingIds = {};
+ _detailErrorIds = {};
+ _connected = false;
+ _streamError = false;
+ _loading = true;
+ reconnectAttempt = 0;
+ }
+
+ async function refreshInternal(environmentId = _currentEnvironmentId, generation = streamGeneration) {
+ _loading = true;
+ try {
+ const result = await activityService.getActivities({ pagination: { page: 1, limit: ACTIVITY_LIST_LIMIT } }, environmentId);
+ if (generation !== streamGeneration || environmentId !== _currentEnvironmentId) {
+ return;
+ }
+ replaceSnapshotInternal(result.data ?? []);
+ } catch (error) {
+ console.warn('Failed to refresh activities:', error);
+ } finally {
+ if (generation === streamGeneration && environmentId === _currentEnvironmentId) {
+ _loading = false;
+ }
+ }
+ }
+
+ function replaceSnapshotInternal(activities: Activity[]) {
+ _activities = sortActivitiesInternal(activities);
+ // Drop expansion state for activities that no longer exist in the snapshot.
+ const present = new Set(_activities.map((activity) => activity.id));
+ const nextExpanded: Record<string, boolean> = {};
+ for (const id of Object.keys(_expandedActivityIds)) {
+ if (_expandedActivityIds[id] && present.has(id)) {
+ nextExpanded[id] = true;
+ }
+ }
+ _expandedActivityIds = nextExpanded;
+ }
+
+ function mergeActivityInternal(activity: Activity) {
+ const index = _activities.findIndex((item) => item.id === activity.id);
+ if (index >= 0) {
+ _activities = sortActivitiesInternal([..._activities.slice(0, index), activity, ..._activities.slice(index + 1)]);
+ } else {
+ _activities = sortActivitiesInternal([activity, ..._activities]).slice(0, ACTIVITY_LIST_LIMIT);
+ }
+
+ const existingDetail = _details[activity.id];
+ if (existingDetail) {
+ _details = {
+ ..._details,
+ [activity.id]: {
+ ...existingDetail,
+ activity
+ }
+ };
+ }
+ }
+
+ function mergeMessageInternal(message: ActivityMessage) {
+ const detail = _details[message.activityId];
+ if (!detail) {
+ return;
+ }
+
+ const exists = detail.messages.some((item) => item.id === message.id);
+ const messages = exists ? detail.messages : [...detail.messages, message].slice(-ACTIVITY_DETAIL_LIMIT);
+ _details = {
+ ..._details,
+ [message.activityId]: {
+ ...detail,
+ messages
+ }
+ };
+ }
+
+ function applyStreamEventInternal(event: ActivityStreamEvent) {
+ switch (event.type) {
+ case 'snapshot':
+ replaceSnapshotInternal(event.activities ?? []);
+ _loading = false;
+ break;
+ case 'activity':
+ if (event.activity) {
+ mergeActivityInternal(event.activity);
+ }
+ break;
+ case 'message':
+ if (event.message) {
+ mergeMessageInternal(event.message);
+ }
+ break;
+ case 'heartbeat':
+ _connected = true;
+ break;
+ }
+ }
+
+ async function connectStreamInternal(environmentId: string, generation: number) {
+ if (!browser || generation !== streamGeneration) {
+ return;
+ }
+
+ streamAbortController = new AbortController();
+ try {
+ const response = await activityService.openActivityStream(environmentId, streamAbortController.signal, ACTIVITY_LIST_LIMIT);
+ if (generation !== streamGeneration || !response.body) {
+ streamAbortController = null;
+ return;
+ }
+
+ _connected = true;
+ _streamError = false;
+ reconnectAttempt = 0;
+ await readJSONLinesInternal(response.body, generation);
+ } catch (error) {
+ if (!streamAbortController?.signal.aborted && generation === streamGeneration) {
+ console.warn('Activity stream disconnected:', error);
+ }
+ } finally {
+ streamAbortController = null;
+ if (generation === streamGeneration) {
+ _connected = false;
+ scheduleReconnectInternal(environmentId, generation);
+ }
+ }
+ }
+
+ async function readJSONLinesInternal(stream: ReadableStream<Uint8Array>, generation: number) {
+ const reader = stream.getReader();
+ const decoder = new TextDecoder();
+ let buffer = '';
+
+ try {
+ while (generation === streamGeneration) {
+ const { done, value } = await reader.read();
+ if (done) {
+ break;
+ }
+
+ buffer += decoder.decode(value, { stream: true });
+ const lines = buffer.split('\n');
+ buffer = lines.pop() ?? '';
+ for (const line of lines) {
+ handleStreamLineInternal(line);
+ }
+ }
+
+ buffer += decoder.decode();
+ if (buffer.trim()) {
+ handleStreamLineInternal(buffer);
+ }
+ } finally {
+ reader.releaseLock();
+ }
+ }
+
+ function handleStreamLineInternal(line: string) {
+ const trimmed = line.trim();
+ if (!trimmed) {
+ return;
+ }
+
+ try {
+ applyStreamEventInternal(JSON.parse(trimmed) as ActivityStreamEvent);
+ } catch (error) {
+ console.warn('Failed to parse activity stream line:', error);
+ }
+ }
+
+ function scheduleReconnectInternal(environmentId: string, generation: number) {
+ if (!browser || !started || generation !== streamGeneration) {
+ return;
+ }
+
+ if (reconnectAttempt >= MAX_RECONNECT_ATTEMPTS) {
+ _streamError = true;
+ return;
+ }
+
+ clearReconnectTimerInternal();
+ const delay = Math.min(1000 * 2 ** reconnectAttempt, MAX_RECONNECT_DELAY);
+ reconnectAttempt += 1;
+ reconnectTimer = setTimeout(() => {
+ void connectStreamInternal(environmentId, generation);
+ }, delay);
+ }
+
+ function restartForEnvironmentInternal(environmentId: string) {
+ streamGeneration += 1;
+ abortStreamInternal();
+ resetEnvironmentStateInternal(environmentId);
+ const generation = streamGeneration;
+ void refreshInternal(environmentId, generation);
+ void connectStreamInternal(environmentId, generation);
+ }
+
+ async function loadDetailInternal(activityId: string) {
+ if (_details[activityId] || _detailLoadingIds[activityId]) {
+ return;
+ }
+
+ _detailLoadingIds = { ..._detailLoadingIds, [activityId]: true };
+ try {
+ const detail = await activityService.getActivity(activityId, _currentEnvironmentId, ACTIVITY_DETAIL_LIMIT);
+ _details = { ..._details, [activityId]: detail };
+ const nextErrors = { ..._detailErrorIds };
+ delete nextErrors[activityId];
+ _detailErrorIds = nextErrors;
+ } catch (error) {
+ console.warn('Failed to load activity detail:', error);
+ _detailErrorIds = { ..._detailErrorIds, [activityId]: true };
+ } finally {
+ const next = { ..._detailLoadingIds };
+ delete next[activityId];
+ _detailLoadingIds = next;
+ }
+ }
+
+ function setActivityExpanded(activityId: string, expanded: boolean) {
+ if (!activityId) {
+ return;
+ }
+
+ if (expanded) {
+ if (_expandedActivityIds[activityId]) {
+ return;
+ }
+ _expandedActivityIds = { ..._expandedActivityIds, [activityId]: true };
+ void loadDetailInternal(activityId);
+ } else {
+ if (!_expandedActivityIds[activityId]) {
+ return;
+ }
+ const next = { ..._expandedActivityIds };
+ delete next[activityId];
+ _expandedActivityIds = next;
+ }
+ }
+
+ function toggleActivity(activityId: string) {
+ setActivityExpanded(activityId, !_expandedActivityIds[activityId]);
+ }
+
+ return {
+ get activities(): Activity[] {
+ return _activities;
+ },
+ get filteredActivities(): Activity[] {
+ return _activities.filter((activity) => filterActivityInternal(activity, _filter));
+ },
+ get activeCount(): number {
+ return _activities.filter((activity) => isActiveStatusInternal(activity.status)).length;
+ },
+ get filter(): ActivityFilter {
+ return _filter;
+ },
+ get open(): boolean {
+ return _open;
+ },
+ get loading(): boolean {
+ return _loading;
+ },
+ get connected(): boolean {
+ return _connected;
+ },
+ get streamError(): boolean {
+ return _streamError;
+ },
+ get currentEnvironmentId(): string {
+ return _currentEnvironmentId;
+ },
+ isExpanded(activityId: string): boolean {
+ return !!_expandedActivityIds[activityId];
+ },
+ isDetailLoading(activityId: string): boolean {
+ return !!_detailLoadingIds[activityId];
+ },
+ isDetailError(activityId: string): boolean {
+ return !!_detailErrorIds[activityId];
+ },
+ getDetail(activityId: string): ActivityDetail | null {
+ const activity = _details[activityId]?.activity ?? _activities.find((item) => item.id === activityId);
+ if (!activity) {
+ return null;
+ }
+ return _details[activityId] ?? { activity, messages: [] };
+ },
+ getActivity(activityId: string): Activity | null {
+ return _details[activityId]?.activity ?? _activities.find((item) => item.id === activityId) ?? null;
+ },
+ start: async () => {
+ if (!browser || started) {
+ return;
+ }
+
+ started = true;
+ await environmentStore.ready;
+ restartForEnvironmentInternal(environmentStore.selected?.id ?? LOCAL_DOCKER_ENVIRONMENT_ID);
+ unsubscribeEnvironment = environmentStore.subscribeSelected((environment) => {
+ restartForEnvironmentInternal(environment?.id ?? LOCAL_DOCKER_ENVIRONMENT_ID);
+ });
+ },
+ stop: () => {
+ started = false;
+ unsubscribeEnvironment?.();
+ unsubscribeEnvironment = null;
+ streamGeneration += 1;
+ abortStreamInternal();
+ },
+ refresh: () => refreshInternal(),
+ clearHistory: async () => {
+ await activityService.clearHistory(_currentEnvironmentId);
+ _details = {};
+ _expandedActivityIds = {};
+ _detailLoadingIds = {};
+ _detailErrorIds = {};
+ await refreshInternal();
+ },
+ setFilter: (filter: ActivityFilter) => {
+ _filter = filter;
+ },
+ setOpen: (open: boolean) => {
+ _open = open;
+ },
+ openCenter: (activityId?: string) => {
+ _open = true;
+ if (activityId) {
+ setActivityExpanded(activityId, true);
+ }
+ },
+ retryLoadDetail: (activityId: string) => {
+ const nextErrors = { ..._detailErrorIds };
+ delete nextErrors[activityId];
+ _detailErrorIds = nextErrors;
+ const nextDetails = { ..._details };
+ delete nextDetails[activityId];
+ _details = nextDetails;
+ void loadDetailInternal(activityId);
+ },
+ retryStream: () => {
+ _streamError = false;
+ reconnectAttempt = 0;
+ restartForEnvironmentInternal(_currentEnvironmentId);
+ },
+ setActivityExpanded,
+ toggleActivity
+ };
+}
+
+export const activityStore = createActivityStore();
diff --git a/frontend/src/lib/types/activity.type.ts b/frontend/src/lib/types/activity.type.ts
new file mode 100644
index 000000000..8c2a8a571
--- /dev/null
+++ b/frontend/src/lib/types/activity.type.ts
@@ -0,0 +1,82 @@
+export type ActivityStatus = 'queued' | 'running' | 'success' | 'failed' | 'cancelled';
+
+export type ActivityType =
+ | 'image_pull'
+ | 'image_build'
+ | 'image_update_check'
+ | 'project_pull'
+ | 'project_build'
+ | 'project_deploy'
+ | 'project_redeploy'
+ | 'project_down'
+ | 'project_restart'
+ | 'project_destroy'
+ | 'container_start'
+ | 'container_stop'
+ | 'container_restart'
+ | 'container_redeploy'
+ | 'container_delete'
+ | 'vulnerability_scan'
+ | 'auto_update'
+ | 'system_prune'
+ | 'resource_action';
+
+export type ActivityMessageLevel = 'info' | 'warning' | 'error' | 'success';
+
+export type ActivityFilter = 'running' | 'failed' | 'completed';
+
+export interface Activity {
+ id: string;
+ environmentId: string;
+ sourceEnvironmentId?: string;
+ sourceEnvironmentName?: string;
+ type: ActivityType;
+ status: ActivityStatus;
+ resourceType?: string;
+ resourceId?: string;
+ resourceName?: string;
+ progress?: number | null;
+ step?: string;
+ latestMessage?: string;
+ startedBy?: ActivityStartedBy;
+ startedAt: string;
+ endedAt?: string;
+ durationMs?: number;
+ error?: string;
+ metadata?: Record<string, unknown>;
+ createdAt: string;
+ updatedAt?: string;
+}
+
+export interface ActivityStartedBy {
+ userId?: string;
+ username: string;
+ displayName?: string;
+}
+
+export interface ActivityMessage {
+ id: string;
+ activityId: string;
+ level: ActivityMessageLevel;
+ message: string;
+ payload?: Record<string, unknown>;
+ createdAt: string;
+}
+
+export interface ActivityDetail {
+ activity: Activity;
+ messages: ActivityMessage[];
+}
+
+export interface ActivityClearHistoryResult {
+ deleted: number;
+}
+
+export interface ActivityStreamEvent {
+ type: 'snapshot' | 'activity' | 'message' | 'heartbeat';
+ activityId?: string;
+ activity?: Activity;
+ activities?: Activity[];
+ message?: ActivityMessage;
+ timestamp: string;
+}
diff --git a/frontend/src/lib/types/automation.ts b/frontend/src/lib/types/automation.ts
index bca9bca7d..37ccc4c53 100644
--- a/frontend/src/lib/types/automation.ts
+++ b/frontend/src/lib/types/automation.ts
@@ -17,6 +17,7 @@ export interface AutoUpdateResult {
failed: number;
items: AutoUpdateResourceResult[];
duration: string;
+ activityId?: string;
}
export interface AutoUpdateResourceResult {
diff --git a/frontend/src/lib/types/docker.ts b/frontend/src/lib/types/docker.ts
index f3bcf3b80..60642bda0 100644
--- a/frontend/src/lib/types/docker.ts
+++ b/frontend/src/lib/types/docker.ts
@@ -341,6 +341,7 @@ export interface ImageUpdateInfoDto {
authUsername?: string;
authRegistry?: string;
usedCredential?: boolean;
+ activityId?: string;
}
export interface ImageUsageCounts {
@@ -623,6 +624,7 @@ export interface VolumeSummaryDto {
inUse: boolean;
usageData?: VolumeUsageData;
size: number;
+ activityId?: string;
}
export interface VolumeDetailDto extends VolumeSummaryDto {
diff --git a/frontend/src/lib/types/environment.ts b/frontend/src/lib/types/environment.ts
index def2279d4..63eb4085a 100644
--- a/frontend/src/lib/types/environment.ts
+++ b/frontend/src/lib/types/environment.ts
@@ -158,6 +158,7 @@ export interface VulnerabilityScanResult {
imageName: string;
scanTime: string;
status: VulnerabilityScanStatus;
+ activityId?: string;
scanPhase?: 'creating_container' | 'scanning_image' | 'storing_results';
summary?: SeveritySummary;
vulnerabilities?: Vulnerability[];
@@ -170,6 +171,7 @@ export interface VulnerabilityScanSummary {
imageId: string;
scanTime: string;
status: VulnerabilityScanStatus;
+ activityId?: string;
scanPhase?: 'creating_container' | 'scanning_image' | 'storing_results';
summary?: SeveritySummary;
error?: string;
diff --git a/frontend/src/lib/types/settings.ts b/frontend/src/lib/types/settings.ts
index 7f73169db..5e4ad5349 100644
--- a/frontend/src/lib/types/settings.ts
+++ b/frontend/src/lib/types/settings.ts
@@ -17,6 +17,8 @@ export type Settings = {
pollingInterval: number;
dockerClientRefreshInterval?: string;
environmentHealthInterval: number;
+ activityHistoryRetentionDays: number;
+ activityHistoryMaxEntries: number;
defaultDeployPullPolicy: 'missing' | 'always' | 'never';
scheduledPruneEnabled?: boolean;
scheduledPruneInterval?: number;
diff --git a/frontend/src/lib/types/swarm.ts b/frontend/src/lib/types/swarm.ts
index 05f8ae274..6a042093a 100644
--- a/frontend/src/lib/types/swarm.ts
+++ b/frontend/src/lib/types/swarm.ts
@@ -536,6 +536,7 @@ export interface Project {
gitRepositoryURL?: string;
hasBuildDirective?: boolean;
redeployDisabled?: boolean;
+ activityId?: string;
updateInfo?: ProjectUpdateInfo;
services?: ProjectService[];
runtimeServices?: RuntimeService[];
diff --git a/frontend/src/lib/utils/activity-toast.ts b/frontend/src/lib/utils/activity-toast.ts
new file mode 100644
index 000000000..fdf978fe9
--- /dev/null
+++ b/frontend/src/lib/utils/activity-toast.ts
@@ -0,0 +1,41 @@
+import { activityStore } from '$lib/stores/activity.store.svelte';
+import { m } from '$lib/paraglide/messages';
+
+export function activityToastOptions(activityId?: string) {
+ if (!activityId) {
+ return undefined;
+ }
+
+ return {
+ action: {
+ label: m.activity_view_activity(),
+ onClick: () => activityStore.openCenter(activityId)
+ }
+ };
+}
+
+export function extractActivityId(value: unknown): string | undefined {
+ if (!value || typeof value !== 'object') {
+ return undefined;
+ }
+
+ const activityId = (value as { activityId?: unknown }).activityId;
+ if (typeof activityId === 'string' && activityId.trim()) {
+ return activityId;
+ }
+
+ if (Array.isArray(value)) {
+ for (const item of value) {
+ const nested = extractActivityId(item);
+ if (nested) return nested;
+ }
+ return undefined;
+ }
+
+ for (const item of Object.values(value)) {
+ const nested = extractActivityId(item);
+ if (nested) return nested;
+ }
+
+ return undefined;
+}
diff --git a/frontend/src/routes/(app)/+layout.svelte b/frontend/src/routes/(app)/+layout.svelte
index 585f64c58..75f85858d 100644
--- a/frontend/src/routes/(app)/+layout.svelte
+++ b/frontend/src/routes/(app)/+layout.svelte
@@ -5,6 +5,7 @@
import * as Sidebar from '$lib/components/ui/sidebar/index.js';
import AppSidebar from '$lib/components/sidebar/sidebar.svelte';
import MobileNav from '$lib/components/mobile-nav/mobile-nav.svelte';
+ import ActivityCenter from '$lib/components/activity/activity-center.svelte';
import { IsMobile } from '$lib/hooks/is-mobile.svelte.js';
import { IsTablet } from '$lib/hooks/is-tablet.svelte.js';
import { getEffectiveNavigationSettings, navigationSettingsOverridesStore } from '$lib/utils/navigation';
@@ -105,3 +106,5 @@
</main>
</Sidebar.Provider>
{/if}
+
+<ActivityCenter />
diff --git a/frontend/src/routes/(app)/containers/+page.svelte b/frontend/src/routes/(app)/containers/+page.svelte
index 0062eb887..e69da3309 100644
--- a/frontend/src/routes/(app)/containers/+page.svelte
+++ b/frontend/src/routes/(app)/containers/+page.svelte
@@ -16,6 +16,7 @@
import type { SearchPaginationSortRequest } from '$lib/types/shared';
import type { ContainerListRequestOptions } from '$lib/services/container-service';
import ContainerEnvironmentSync from './components/container-environment-sync.svelte';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { data } = $props();
@@ -55,8 +56,8 @@
const checkUpdatesMutation = createMutation(() => ({
mutationKey: queryKeys.containers.checkUpdates(envId),
mutationFn: () => imageService.runAutoUpdate(),
- onSuccess: async () => {
- toast.success(m.containers_check_updates_success());
+ onSuccess: async (data) => {
+ toast.success(m.containers_check_updates_success(), activityToastOptions(extractActivityId(data)));
await refreshContainers();
},
onError: () => {
diff --git a/frontend/src/routes/(app)/containers/container-table.actions.ts b/frontend/src/routes/(app)/containers/container-table.actions.ts
index dfe95fcd0..6c40b304f 100644
--- a/frontend/src/routes/(app)/containers/container-table.actions.ts
+++ b/frontend/src/routes/(app)/containers/container-table.actions.ts
@@ -4,6 +4,7 @@ import { containerService, type ContainersPaginatedResponse } from '$lib/service
import type { ContainerSummaryDto } from '$lib/types/docker';
import { handleApiResultWithCallbacks } from '$lib/utils/api';
import { tryCatch } from '$lib/utils/api';
+import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
import { toast } from 'svelte-sonner';
import { getContainerDisplayName, type ActionStatus } from './container-table.helpers';
@@ -94,8 +95,8 @@ export function createContainerActions({
setLoadingState: (value) => {
actionStatus[id] = value ? config.status : '';
},
- async onSuccess() {
- toast.success(config.success());
+ async onSuccess(data) {
+ toast.success(config.success(), activityToastOptions(extractActivityId(data)));
await reloadContainers();
}
});
@@ -135,8 +136,8 @@ export function createContainerActions({
setLoadingState: (value) => {
actionStatus[id] = value ? 'removing' : '';
},
- async onSuccess() {
- toast.success(m.containers_remove_success());
+ async onSuccess(data) {
+ toast.success(m.containers_remove_success(), activityToastOptions(extractActivityId(data)));
await reloadContainers();
}
});
@@ -157,19 +158,19 @@ export function createContainerActions({
action: async () => {
actionStatus[container.id] = 'updating';
try {
- toast.info(m.containers_update_pulling_image());
-
const result = await containerService.updateContainer(container.id);
+ const toastOptions = activityToastOptions(extractActivityId(result));
if (result.failed > 0) {
const failedItem = result.items?.find((item: { status?: string; error?: string }) => item.status === 'failed');
toast.error(
- m.containers_update_failed({ name: containerName }) + (failedItem?.error ? `: ${failedItem.error}` : '')
+ m.containers_update_failed({ name: containerName }) + (failedItem?.error ? `: ${failedItem.error}` : ''),
+ toastOptions
);
} else if (result.updated > 0) {
- toast.success(m.containers_update_success({ name: containerName }));
+ toast.success(m.containers_update_success({ name: containerName }), toastOptions);
} else {
- toast.info(m.image_update_up_to_date_title());
+ toast.info(m.image_update_up_to_date_title(), toastOptions);
}
await reloadContainers();
@@ -199,8 +200,8 @@ export function createContainerActions({
setLoadingState: (value) => {
actionStatus[container.id] = value ? 'redeploying' : '';
},
- async onSuccess() {
- toast.success(m.container_redeploy_success());
+ async onSuccess(data) {
+ toast.success(m.container_redeploy_success(), activityToastOptions(extractActivityId(data)));
await refreshContainers();
}
});
diff --git a/frontend/src/routes/(app)/dashboard/+page.svelte b/frontend/src/routes/(app)/dashboard/+page.svelte
index f333cb59a..a507df312 100644
--- a/frontend/src/routes/(app)/dashboard/+page.svelte
+++ b/frontend/src/routes/(app)/dashboard/+page.svelte
@@ -9,6 +9,7 @@
import { ArcaneButton } from '$lib/components/arcane-button/index.js';
import { handleApiResultWithCallbacks } from '$lib/utils/api';
import { tryCatch } from '$lib/utils/api';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
import { openConfirmDialog } from '$lib/components/confirm-dialog';
import { environmentStore } from '$lib/stores/environment.store.svelte';
import userStore from '$lib/stores/user-store';
@@ -365,8 +366,8 @@
result: await tryCatch(systemService.startAllStoppedContainers()),
message: m.dashboard_start_all_failed(),
setLoadingState: (value) => (isLoading.starting = value),
- onSuccess: async () => {
- toast.success(m.dashboard_start_all_success());
+ onSuccess: async (data) => {
+ toast.success(m.dashboard_start_all_success(), activityToastOptions(extractActivityId(data)));
await refreshData();
}
});
@@ -385,8 +386,8 @@
result: await tryCatch(systemService.stopAllContainers()),
message: m.dashboard_stop_all_failed(),
setLoadingState: (value) => (isLoading.stopping = value),
- onSuccess: async () => {
- toast.success(m.dashboard_stop_all_success());
+ onSuccess: async (data) => {
+ toast.success(m.dashboard_stop_all_success(), activityToastOptions(extractActivityId(data)));
await refreshData();
}
});
@@ -413,12 +414,12 @@
result: await tryCatch(systemService.pruneAll(pruneRequest)),
message: m.dashboard_prune_failed({ types: typesString }),
setLoadingState: (value) => (isLoading.pruning = value),
- onSuccess: async () => {
+ onSuccess: async (data) => {
isPruneDialogOpen = false;
if (selectedTypes.length === 1) {
- toast.success(m.dashboard_prune_success_one({ types: typesString }));
+ toast.success(m.dashboard_prune_success_one({ types: typesString }), activityToastOptions(extractActivityId(data)));
} else {
- toast.success(m.dashboard_prune_success_many({ types: typesString }));
+ toast.success(m.dashboard_prune_success_many({ types: typesString }), activityToastOptions(extractActivityId(data)));
}
await refreshData();
}
diff --git a/frontend/src/routes/(app)/dashboard/dashboard-all-environments-view.svelte b/frontend/src/routes/(app)/dashboard/dashboard-all-environments-view.svelte
index 78dbf4ccc..73a275be4 100644
--- a/frontend/src/routes/(app)/dashboard/dashboard-all-environments-view.svelte
+++ b/frontend/src/routes/(app)/dashboard/dashboard-all-environments-view.svelte
@@ -29,6 +29,7 @@
import { capitalizeFirstLetter } from '$lib/utils/formatting';
import { tryCatch } from '$lib/utils/api';
import { getEnvironmentStatusVariant, isEnvironmentOnline, resolveEnvironmentStatus } from '$lib/utils/docker';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
import { createStatsWebSocket, type ReconnectingWebSocket } from '$lib/utils/ws';
import { bytes } from '$lib/utils/formatting';
import {
@@ -615,17 +616,17 @@
setLoadingState: (value) => {
pruningEnvironmentId = value ? environmentId : null;
},
- onSuccess: async () => {
+ onSuccess: async (data) => {
isPruneDialogOpen = false;
pruneEnvironment = null;
+ const toastOptions = {
+ ...(activityToastOptions(extractActivityId(data)) ?? {}),
+ description: targetEnvironment.environment.name
+ };
if (selectedTypes.length === 1) {
- toast.success(m.dashboard_prune_success_one({ types: typesString }), {
- description: targetEnvironment.environment.name
- });
+ toast.success(m.dashboard_prune_success_one({ types: typesString }), toastOptions);
} else {
- toast.success(m.dashboard_prune_success_many({ types: typesString }), {
- description: targetEnvironment.environment.name
- });
+ toast.success(m.dashboard_prune_success_many({ types: typesString }), toastOptions);
}
await refreshOverview();
}
diff --git a/frontend/src/routes/(app)/images/+page.svelte b/frontend/src/routes/(app)/images/+page.svelte
index 8fc59db22..8c8b9f775 100644
--- a/frontend/src/routes/(app)/images/+page.svelte
+++ b/frontend/src/routes/(app)/images/+page.svelte
@@ -18,6 +18,7 @@
import { CloseIcon, VolumesIcon, LocalFolderComputerIcon } from '$lib/icons';
import { createMutation, createQuery } from '@tanstack/svelte-query';
import PruneModeCard from '$lib/components/prune/prune-mode-card.svelte';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { data } = $props();
@@ -59,8 +60,8 @@
mode: imagePruneMode,
...(imagePruneMode === 'olderThan' ? { until: imagePruneUntil } : {})
}),
- onSuccess: async () => {
- toast.success(m.images_pruned_success());
+ onSuccess: async (data) => {
+ toast.success(m.images_pruned_success(), activityToastOptions(extractActivityId(data)));
await Promise.all([imagesQuery.refetch(), imageUsageCountsQuery.refetch()]);
isConfirmPruneDialogOpen = false;
},
@@ -72,8 +73,8 @@
const checkUpdatesMutation = createMutation(() => ({
mutationKey: ['images', 'check-updates', envId],
mutationFn: () => imageService.checkAllImages(),
- onSuccess: async () => {
- toast.success(m.images_update_check_completed());
+ onSuccess: async (data) => {
+ toast.success(m.images_update_check_completed(), activityToastOptions(extractActivityId(data)));
await imagesQuery.refetch();
},
onError: () => {
diff --git a/frontend/src/routes/(app)/images/[imageId]/+page.svelte b/frontend/src/routes/(app)/images/[imageId]/+page.svelte
index 907ee64a6..3628523af 100644
--- a/frontend/src/routes/(app)/images/[imageId]/+page.svelte
+++ b/frontend/src/routes/(app)/images/[imageId]/+page.svelte
@@ -13,6 +13,7 @@
import { m } from '$lib/paraglide/messages';
import { imageService } from '$lib/services/image-service.js';
import { vulnerabilityService } from '$lib/services/vulnerability-service.js';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
import {
startVulnerabilityScanPolling,
stabilizeFailedVulnerabilitySummary,
@@ -72,10 +73,11 @@
vulnerabilityScan = result;
lastScanRequestedAt = result.scanTime || new Date().toISOString();
if (result.status === 'completed') {
- toast.success(m.vuln_scan_completed());
+ toast.success(m.vuln_scan_completed(), activityToastOptions(result.activityId));
} else if (result.status === 'failed') {
- toast.error(result.error || m.vuln_scan_failed());
+ toast.error(result.error || m.vuln_scan_failed(), activityToastOptions(result.activityId));
} else {
+ toast.info(m.vuln_scan_started(), activityToastOptions(result.activityId));
beginScanPolling(true);
}
} catch (error) {
@@ -151,10 +153,11 @@
} as VulnerabilityScanResult;
}
if (showToast) {
+ const toastOptions = activityToastOptions(extractActivityId(resolvedSummary));
if (resolvedSummary.status === 'completed') {
- toast.success(m.vuln_scan_completed());
+ toast.success(m.vuln_scan_completed(), toastOptions);
} else {
- toast.error(resolvedSummary.error || m.vuln_scan_failed());
+ toast.error(resolvedSummary.error || m.vuln_scan_failed(), toastOptions);
}
}
},
@@ -221,8 +224,8 @@
result: await tryCatch(imageService.deleteImage(id, { force })),
message: m.images_remove_failed(),
setLoadingState: (value) => (isLoading.removing = value),
- onSuccess: async () => {
- toast.success(m.images_remove_success());
+ onSuccess: async (data) => {
+ toast.success(m.images_remove_success(), activityToastOptions(extractActivityId(data)));
goto('/images');
}
});
diff --git a/frontend/src/routes/(app)/images/image-table.svelte b/frontend/src/routes/(app)/images/image-table.svelte
index d66442b7b..32fe28f8e 100644
--- a/frontend/src/routes/(app)/images/image-table.svelte
+++ b/frontend/src/routes/(app)/images/image-table.svelte
@@ -27,6 +27,7 @@
import { isLikelyStaleFailedSummary, isVulnerabilityScanInProgress } from '$lib/utils/docker';
import { environmentStore } from '$lib/stores/environment.store.svelte';
import { hasPermission } from '$lib/utils/auth';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
import {
DownloadIcon,
@@ -157,8 +158,8 @@
result,
message: m.images_remove_failed(),
setLoadingState: () => {},
- onSuccess: async () => {
- toast.success(m.images_remove_success());
+ onSuccess: async (data) => {
+ toast.success(m.images_remove_success(), activityToastOptions(extractActivityId(data)));
await refreshImages();
}
});
@@ -181,8 +182,8 @@
result,
message: m.images_pull_failed(),
setLoadingState: () => {},
- onSuccess: async () => {
- toast.success(m.images_pull_success({ repoTag }));
+ onSuccess: async (data) => {
+ toast.success(m.images_pull_success({ repoTag }), activityToastOptions(extractActivityId(data)));
await refreshImages();
}
});
@@ -204,6 +205,7 @@
imageId: data.imageId,
scanTime: data.scanTime,
status: data.status,
+ activityId: data.activityId,
scanPhase: data.scanPhase,
summary: data.summary,
error: data.error
@@ -211,14 +213,15 @@
await handleVulnerabilityScanChanged(imageId, summary);
if (data.status === 'completed') {
- toast.success(m.vuln_scan_completed());
+ toast.success(m.vuln_scan_completed(), activityToastOptions(data.activityId));
return;
}
if (data.status === 'failed') {
- toast.error(data.error || m.vuln_scan_failed());
+ toast.error(data.error || m.vuln_scan_failed(), activityToastOptions(data.activityId));
return;
}
+ toast.info(m.vuln_scan_started(), activityToastOptions(data.activityId));
startBatchScanPolling();
}
});
@@ -439,7 +442,7 @@
{#snippet TagCell({ item }: { item: ImageSummaryDto })}
{#if item.repoTags && item.repoTags.length > 0 && item.repoTags[0] !== '<none>:<none>'}
<div class="flex flex-wrap gap-1.5">
- {#each item.repoTags.slice(0, 2) as repoTag}
+ {#each item.repoTags.slice(0, 2) as repoTag, tagIndex (`${repoTag}-${tagIndex}`)}
{@const tag = repoTag.split(':').pop() || repoTag}
<Badge variant="outline" class="font-mono text-xs">{tag}</Badge>
{/each}
@@ -477,7 +480,7 @@
{@const visibleUsage = hasOverflow ? item.usedBy.slice(0, maxVisible) : item.usedBy}
{@const overflowUsage = hasOverflow ? item.usedBy.slice(maxVisible) : []}
<div class="flex flex-wrap gap-1.5">
- {#each visibleUsage as usage}
+ {#each visibleUsage as usage, usageIndex (`${usage.type}-${usage.id ?? usage.name}-${usageIndex}`)}
{#if usage.type === 'project'}
{#if usage.id}
<a class="inline-flex" href={`/projects/${encodeURIComponent(usage.id)}`}>
@@ -531,7 +534,7 @@
</Tooltip.Trigger>
<Tooltip.Content class="pointer-events-auto">
<div class="flex max-w-xs flex-wrap gap-1.5">
- {#each overflowUsage as usage}
+ {#each overflowUsage as usage, usageIndex (`${usage.type}-${usage.id ?? usage.name}-${usageIndex}`)}
{#if usage.type === 'project'}
{#if usage.id}
<a class="inline-flex" href={`/projects/${encodeURIComponent(usage.id)}`}>
diff --git a/frontend/src/routes/(app)/networks/+page.svelte b/frontend/src/routes/(app)/networks/+page.svelte
index f4fa7b988..4189199bc 100644
--- a/frontend/src/routes/(app)/networks/+page.svelte
+++ b/frontend/src/routes/(app)/networks/+page.svelte
@@ -13,6 +13,7 @@
import { untrack } from 'svelte';
import { ResourcePageLayout, type ActionButton, type StatCardConfig } from '$lib/layouts/index.js';
import { createMutation, createQuery } from '@tanstack/svelte-query';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { data } = $props();
@@ -33,8 +34,11 @@
mutationKey: ['networks', 'create', envId],
mutationFn: ({ name, options }: { name: string; options: NetworkCreateOptions }) =>
networkService.createNetwork(name, options),
- onSuccess: async (_data, variables) => {
- toast.success(m.common_create_success({ resource: `${m.resource_network()} "${variables.name}"` }));
+ onSuccess: async (data, variables) => {
+ toast.success(
+ m.common_create_success({ resource: `${m.resource_network()} "${variables.name}"` }),
+ activityToastOptions(extractActivityId(data))
+ );
await networksQuery.refetch();
isCreateDialogOpen = false;
},
diff --git a/frontend/src/routes/(app)/networks/[networkId]/+page.svelte b/frontend/src/routes/(app)/networks/[networkId]/+page.svelte
index ec9d92262..a5f9b85d9 100644
--- a/frontend/src/routes/(app)/networks/[networkId]/+page.svelte
+++ b/frontend/src/routes/(app)/networks/[networkId]/+page.svelte
@@ -27,6 +27,7 @@
import { m } from '$lib/paraglide/messages';
import { networkService } from '$lib/services/network-service';
import { ResourceDetailLayout, type DetailAction } from '$lib/layouts';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { data }: PageProps = $props();
let errorMessage = $state('');
@@ -87,8 +88,11 @@
result: await tryCatch(networkService.deleteNetwork(network.id)),
message: m.networks_remove_failed({ name: network?.name ?? shortId }),
setLoadingState: (value) => (isRemoving = value),
- onSuccess: async () => {
- toast.success(m.networks_remove_success({ name: network?.name ?? shortId }));
+ onSuccess: async (data) => {
+ toast.success(
+ m.networks_remove_success({ name: network?.name ?? shortId }),
+ activityToastOptions(extractActivityId(data))
+ );
goto('/networks');
},
onError: (error) => {
@@ -317,7 +321,7 @@
</Card.Header>
<Card.Content class="p-4">
<div class="grid grid-cols-1 gap-3 lg:grid-cols-2 2xl:grid-cols-3">
- {#each network.peers as peer}
+ {#each network.peers as peer (`${peer.Name ?? ''}:${peer.IP ?? ''}`)}
<Card.Root variant="subtle">
<Card.Content class="flex flex-col gap-2 p-4">
<div class="text-muted-foreground text-xs font-semibold tracking-wide break-all uppercase">{peer.Name}</div>
@@ -345,7 +349,7 @@
</Card.Header>
<Card.Content class="p-4">
<div class="space-y-3">
- {#each Object.entries(network.services) as [name, service]}
+ {#each Object.entries(network.services) as [name, service] (name)}
<Card.Root variant="outlined">
<Card.Content class="p-4">
<div class="space-y-2">
@@ -377,7 +381,7 @@
>{m.networks_service_ports_label()}:</span
>
<div class="flex flex-wrap gap-1">
- {#each service.Ports as port}
+ {#each service.Ports as port (port)}
<code class="bg-muted text-muted-foreground rounded px-1.5 py-0.5 font-mono text-xs sm:text-sm">
{port}
</code>
diff --git a/frontend/src/routes/(app)/networks/network-table.svelte b/frontend/src/routes/(app)/networks/network-table.svelte
index 77426dc74..fe58e506b 100644
--- a/frontend/src/routes/(app)/networks/network-table.svelte
+++ b/frontend/src/routes/(app)/networks/network-table.svelte
@@ -17,6 +17,7 @@
import { m } from '$lib/paraglide/messages';
import { networkService } from '$lib/services/network-service';
import { NetworksIcon, GlobeIcon, InspectIcon, TrashIcon, EllipsisIcon } from '$lib/icons';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
type FieldVisibility = Record<string, boolean>;
@@ -67,8 +68,11 @@
result: await tryCatch(networkService.deleteNetwork(id)),
message: m.common_delete_failed({ resource: `${m.resource_network()} "${safeName}"` }),
setLoadingState: (value) => (isLoading.remove = value),
- onSuccess: async () => {
- toast.success(m.common_delete_success({ resource: `${m.resource_network()} "${safeName}"` }));
+ onSuccess: async (data) => {
+ toast.success(
+ m.common_delete_success({ resource: `${m.resource_network()} "${safeName}"` }),
+ activityToastOptions(extractActivityId(data))
+ );
await refreshNetworks();
}
});
@@ -113,7 +117,8 @@
toast.success(
m.common_delete_success({
resource: `${m.resource_network()} "${network.name ?? m.common_unknown()}"`
- })
+ }),
+ activityToastOptions(extractActivityId(result.data))
);
}
}
diff --git a/frontend/src/routes/(app)/projects/+page.svelte b/frontend/src/routes/(app)/projects/+page.svelte
index 8c7468f24..762edcc2b 100644
--- a/frontend/src/routes/(app)/projects/+page.svelte
+++ b/frontend/src/routes/(app)/projects/+page.svelte
@@ -15,6 +15,7 @@
import { untrack } from 'svelte';
import { createMutation, createQuery } from '@tanstack/svelte-query';
import { ResourcePageLayout, type ActionButton, type StatCardConfig } from '$lib/layouts/index.js';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { data } = $props();
@@ -66,7 +67,7 @@
// map to narrow the redeploy to projects that actually have updates.
// This avoids hitting every project (and its registry) when nothing has
// changed, which is especially expensive on instances with many projects.
- await imageService.checkAllImages();
+ const imageCheckResults = await imageService.checkAllImages();
const images = await imageService.getImagesForEnvironment(envId, { pagination: { page: 1, limit: 10000 } });
const projectIdsWithUpdates = new Set<string>();
@@ -80,7 +81,7 @@
}
if (projectIdsWithUpdates.size === 0) {
- return { updated: 0 };
+ return { updated: 0, activityId: extractActivityId(imageCheckResults) };
}
const allProjects = await projectService.getProjectsForEnvironment(envId, { pagination: { page: 1, limit: 1000 } });
@@ -100,13 +101,14 @@
throw new Error(`${failed.length} project(s) failed to update (${succeeded} succeeded)`);
}
- return { updated: results.length };
+ return { updated: results.length, activityId: extractActivityId(imageCheckResults) };
},
onSuccess: async (result) => {
+ const toastOptions = activityToastOptions(result.activityId);
if (result && result.updated === 0) {
- toast.success(m.image_update_up_to_date_title());
+ toast.success(m.image_update_up_to_date_title(), toastOptions);
} else {
- toast.success(m.compose_update_success());
+ toast.success(m.compose_update_success(), toastOptions);
}
await Promise.all([projectsQuery.refetch(), projectStatusCountsQuery.refetch()]);
},
diff --git a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
index ddab9d9ff..824fd3501 100644
--- a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
+++ b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
@@ -41,6 +41,7 @@
import { createMutation, createQuery, useQueryClient } from '@tanstack/svelte-query';
import ProjectUpdateItem from '$lib/components/project-update-item.svelte';
import IfPermitted from '$lib/components/if-permitted.svelte';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { data } = $props();
let projectId = $derived(data.projectId);
@@ -345,10 +346,11 @@
.find((result) => !!result?.error?.trim())
?.error?.trim();
const hasErrors = !!firstError;
+ const toastOptions = activityToastOptions(extractActivityId(results));
if (hasErrors) {
- toast.error(firstError || m.containers_check_updates_failed());
+ toast.error(firstError || m.containers_check_updates_failed(), toastOptions);
} else {
- toast.success(m.images_update_check_completed());
+ toast.success(m.images_update_check_completed(), toastOptions);
}
await Promise.all([
refreshProjectDetails(),
@@ -438,7 +440,7 @@
};
rebaseEditorDraft(savedProject);
await syncProjectQueries(savedProject);
- toast.success(m.common_update_success({ resource: m.project() }));
+ toast.success(m.common_update_success({ resource: m.project() }), activityToastOptions(extractActivityId(savedProject)));
}
});
}
diff --git a/frontend/src/routes/(app)/projects/components/ProjectContainersTable.svelte b/frontend/src/routes/(app)/projects/components/ProjectContainersTable.svelte
index 45dcd4321..26cc979cd 100644
--- a/frontend/src/routes/(app)/projects/components/ProjectContainersTable.svelte
+++ b/frontend/src/routes/(app)/projects/components/ProjectContainersTable.svelte
@@ -23,6 +23,7 @@
import * as ArcaneTooltip from '$lib/components/arcane-tooltip';
import IconImage from '$lib/components/icon-image.svelte';
import { getArcaneIconUrlFromLabels } from '$lib/utils/docker';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
import {
StartIcon,
StopIcon,
@@ -130,8 +131,8 @@
setLoadingState: (value) => {
actionStatus[id] = value ? statusMap[action] : '';
},
- async onSuccess() {
- toast.success(messageMap[action].success);
+ async onSuccess(data) {
+ toast.success(messageMap[action].success, activityToastOptions(extractActivityId(data)));
await onRefresh?.();
}
});
@@ -164,8 +165,8 @@
setLoadingState: (value) => {
actionStatus[id] = value ? 'removing' : '';
},
- async onSuccess() {
- toast.success(m.containers_remove_success());
+ async onSuccess(data) {
+ toast.success(m.containers_remove_success(), activityToastOptions(extractActivityId(data)));
await onRefresh?.();
}
});
diff --git a/frontend/src/routes/(app)/projects/new/+page.svelte b/frontend/src/routes/(app)/projects/new/+page.svelte
index 6839557d3..2569efe1a 100644
--- a/frontend/src/routes/(app)/projects/new/+page.svelte
+++ b/frontend/src/routes/(app)/projects/new/+page.svelte
@@ -28,6 +28,7 @@
import { hasPermission } from '$lib/utils/auth';
import IfPermitted from '$lib/components/if-permitted.svelte';
import { ComposeEditorSplit } from '$lib/components/compose';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { data } = $props();
@@ -96,7 +97,10 @@
message: m.common_create_failed({ resource: `${m.resource_project()} "${name}"` }),
setLoadingState: (value) => (saving = value),
onSuccess: async (project) => {
- toast.success(m.common_create_success({ resource: `${m.resource_project()} "${name}"` }));
+ toast.success(
+ m.common_create_success({ resource: `${m.resource_project()} "${name}"` }),
+ activityToastOptions(extractActivityId(project))
+ );
goto(`/projects/${project.id}`, { invalidateAll: true });
}
});
diff --git a/frontend/src/routes/(app)/projects/projects-table.actions.ts b/frontend/src/routes/(app)/projects/projects-table.actions.ts
index 0b3c631b4..cb44f8da5 100644
--- a/frontend/src/routes/(app)/projects/projects-table.actions.ts
+++ b/frontend/src/routes/(app)/projects/projects-table.actions.ts
@@ -6,6 +6,7 @@ import { projectService } from '$lib/services/project-service';
import type { SearchPaginationSortRequest } from '$lib/types/shared';
import { handleApiResultWithCallbacks } from '$lib/utils/api';
import { tryCatch } from '$lib/utils/api';
+import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
import { toast } from 'svelte-sonner';
import type { ActionStatus } from './projects-table.helpers';
@@ -123,8 +124,8 @@ export function createProjectActions({
setLoadingState: (value) => {
actionStatus[id] = value ? config.status : '';
},
- onSuccess: async () => {
- toast.success(config.success());
+ onSuccess: async (data) => {
+ toast.success(config.success(), activityToastOptions(extractActivityId(data)));
await refreshProjects();
}
});
@@ -164,8 +165,8 @@ export function createProjectActions({
setLoadingState: (value) => {
actionStatus[id] = value ? 'destroying' : '';
},
- onSuccess: async () => {
- toast.success(m.compose_destroy_success());
+ onSuccess: async (data) => {
+ toast.success(m.compose_destroy_success(), activityToastOptions(extractActivityId(data)));
await refreshProjects();
}
});
diff --git a/frontend/src/routes/(app)/settings/+page.svelte b/frontend/src/routes/(app)/settings/+page.svelte
index 112f800b8..df11fe8f5 100644
--- a/frontend/src/routes/(app)/settings/+page.svelte
+++ b/frontend/src/routes/(app)/settings/+page.svelte
@@ -15,7 +15,8 @@
CloseIcon,
JobsIcon,
CodeIcon,
- GlobeIcon
+ GlobeIcon,
+ ActivityIcon
} from '$lib/icons';
import { ArcaneButton } from '$lib/components/arcane-button/index.js';
import { Card } from '$lib/components/ui/card';
@@ -49,7 +50,8 @@
apikey: ApiKeyIcon,
jobs: JobsIcon,
code: CodeIcon,
- globe: GlobeIcon
+ globe: GlobeIcon,
+ activity: ActivityIcon
};
onMount(async () => {
diff --git a/frontend/src/routes/(app)/settings/activity/+page.svelte b/frontend/src/routes/(app)/settings/activity/+page.svelte
new file mode 100644
index 000000000..60df08997
--- /dev/null
+++ b/frontend/src/routes/(app)/settings/activity/+page.svelte
@@ -0,0 +1,92 @@
+<script lang="ts">
+ import { onMount } from 'svelte';
+ import { z } from 'zod/v4';
+ import settingsStore from '$lib/stores/config-store';
+ import { m } from '$lib/paraglide/messages';
+ import { SettingsPageLayout } from '$lib/layouts';
+ import { Label } from '$lib/components/ui/label';
+ import { ActivityIcon } from '$lib/icons';
+ import TextInputWithLabel from '$lib/components/form/text-input-with-label.svelte';
+ import { createSettingsForm } from '$lib/utils/settings';
+
+ let { data } = $props();
+
+ const isReadOnly = $derived.by(() => $settingsStore?.uiConfigDisabled);
+
+ const formSchema = z.object({
+ activityHistoryRetentionDays: z.coerce.number().int().min(0).max(3650),
+ activityHistoryMaxEntries: z.coerce.number().int().min(0).max(100000)
+ });
+
+ const getFormDefaults = () => {
+ const settings = $settingsStore || data.settings!;
+ return {
+ activityHistoryRetentionDays: settings.activityHistoryRetentionDays,
+ activityHistoryMaxEntries: settings.activityHistoryMaxEntries
+ };
+ };
+
+ const { formInputs, registerOnMount } = createSettingsForm({
+ schema: formSchema,
+ currentSettings: getFormDefaults(),
+ getCurrentSettings: getFormDefaults,
+ successMessage: m.activity_settings_saved()
+ });
+
+ onMount(() => registerOnMount());
+</script>
+
+<SettingsPageLayout
+ title={m.activity_settings_title()}
+ description={m.activity_settings_description()}
+ icon={ActivityIcon}
+ pageType="form"
+ showReadOnlyTag={isReadOnly}
+>
+ {#snippet mainContent()}
+ <fieldset disabled={isReadOnly} class="relative space-y-8">
+ <div class="space-y-4">
+ <h3 class="text-lg font-medium">{m.activity_history_section_title()}</h3>
+ <div class="bg-card rounded-lg border shadow-sm">
+ <div class="space-y-6 p-6">
+ <div class="grid gap-4 md:grid-cols-[1fr_1.5fr] md:gap-8">
+ <div>
+ <Label class="text-base">{m.activity_history_retention_days()}</Label>
+ <p class="text-muted-foreground mt-1 text-sm">{m.activity_history_retention_days_description()}</p>
+ </div>
+ <div class="max-w-xs">
+ <TextInputWithLabel
+ bind:value={$formInputs.activityHistoryRetentionDays.value}
+ error={$formInputs.activityHistoryRetentionDays.error}
+ label={m.activity_history_retention_days()}
+ placeholder={m.activity_history_retention_days_placeholder()}
+ helpText={m.activity_history_retention_days_help()}
+ type="number"
+ />
+ </div>
+ </div>
+
+ <div class="border-t pt-6">
+ <div class="grid gap-4 md:grid-cols-[1fr_1.5fr] md:gap-8">
+ <div>
+ <Label class="text-base">{m.activity_history_max_entries()}</Label>
+ <p class="text-muted-foreground mt-1 text-sm">{m.activity_history_max_entries_description()}</p>
+ </div>
+ <div class="max-w-xs">
+ <TextInputWithLabel
+ bind:value={$formInputs.activityHistoryMaxEntries.value}
+ error={$formInputs.activityHistoryMaxEntries.error}
+ label={m.activity_history_max_entries()}
+ placeholder={m.activity_history_max_entries_placeholder()}
+ helpText={m.activity_history_max_entries_help()}
+ type="number"
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </fieldset>
+ {/snippet}
+</SettingsPageLayout>
diff --git a/frontend/src/routes/(app)/settings/activity/+page.ts b/frontend/src/routes/(app)/settings/activity/+page.ts
new file mode 100644
index 000000000..41fcb0fd6
--- /dev/null
+++ b/frontend/src/routes/(app)/settings/activity/+page.ts
@@ -0,0 +1,20 @@
+import type { PageLoad } from './$types';
+import { settingsService } from '$lib/services/settings-service';
+import { environmentStore } from '$lib/stores/environment.store.svelte';
+import { queryKeys } from '$lib/query/query-keys';
+
+export const load: PageLoad = async ({ parent }) => {
+ const { queryClient } = await parent();
+ const envId = await environmentStore.getCurrentEnvironmentId();
+
+ try {
+ const settings = await queryClient.fetchQuery({
+ queryKey: queryKeys.settings.byEnvironment(envId),
+ queryFn: () => settingsService.getSettingsForEnvironmentMerged(envId)
+ });
+ return { settings };
+ } catch (error) {
+ console.error('Failed to load activity settings:', error);
+ throw error;
+ }
+};
diff --git a/frontend/src/routes/(app)/swarm/nodes/swarm-node-label-dialog.svelte b/frontend/src/routes/(app)/swarm/nodes/swarm-node-label-dialog.svelte
index 39d88c243..8cb406486 100644
--- a/frontend/src/routes/(app)/swarm/nodes/swarm-node-label-dialog.svelte
+++ b/frontend/src/routes/(app)/swarm/nodes/swarm-node-label-dialog.svelte
@@ -48,7 +48,7 @@
>
<form onsubmit={handleSubmit} class="space-y-4 px-6 py-4">
<div class="space-y-2">
- <Label for="label-key" class={isReservedPrefix ? 'text-red-500' : ''}>Key</Label>
+ <Label for="label-key" class={isReservedPrefix ? 'text-red-500' : ''}>{m.swarm_node_label_key()}</Label>
<Input
id="label-key"
bind:value={key}
@@ -58,14 +58,15 @@
/>
{#if isReservedPrefix}
<p class="text-[11px] font-medium text-red-500">
- Prefixes 'engine.labels' and 'com.docker.swarm' are reserved for system use.
+ {m.swarm_node_label_reserved_prefixes()}
</p>
{/if}
</div>
<div class="space-y-2">
- <Label for="label-value">Value</Label>
+ <Label for="label-value">{m.swarm_node_label_value()}</Label>
<Input id="label-value" bind:value placeholder={m.swarm_service_form_value_placeholder()} />
</div>
+ <button type="submit" class="hidden" aria-label={m.swarm_service_form_add_label()}></button>
</form>
{#snippet footer()}
diff --git a/frontend/src/routes/(app)/volumes/+page.svelte b/frontend/src/routes/(app)/volumes/+page.svelte
index 5db7c36bb..0cf3ea7d5 100644
--- a/frontend/src/routes/(app)/volumes/+page.svelte
+++ b/frontend/src/routes/(app)/volumes/+page.svelte
@@ -11,9 +11,11 @@
import { queryKeys } from '$lib/query/query-keys';
import { untrack } from 'svelte';
import { ResourcePageLayout, type ActionButton, type StatCardConfig } from '$lib/layouts/index.js';
- import { createMutation, createQuery } from '@tanstack/svelte-query';
+ import { createMutation, createQuery, useQueryClient } from '@tanstack/svelte-query';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { data } = $props();
+ const queryClient = useQueryClient();
let volumes = $state(untrack(() => data.volumes));
let requestOptions = $state(untrack(() => data.volumeRequestOptions));
@@ -31,10 +33,13 @@
const createVolumeMutation = createMutation(() => ({
mutationKey: ['volumes', 'create', envId],
mutationFn: (options: VolumeCreateRequest) => volumeService.createVolume(options),
- onSuccess: async (_data, options) => {
+ onSuccess: async (data, options) => {
const name = options.name?.trim() || m.common_unknown();
- toast.success(m.common_create_success({ resource: `${m.resource_volume()} "${name}"` }));
- await volumesQuery.refetch();
+ toast.success(
+ m.common_create_success({ resource: `${m.resource_volume()} "${name}"` }),
+ activityToastOptions(extractActivityId(data))
+ );
+ await loadVolumes();
isCreateDialogOpen = false;
},
onError: (_error, options) => {
@@ -53,8 +58,16 @@
await createVolumeMutation.mutateAsync(options);
}
+ async function loadVolumes(options = requestOptions) {
+ requestOptions = options;
+ volumes = await queryClient.fetchQuery({
+ queryKey: queryKeys.volumes.table(envId, options),
+ queryFn: () => volumeService.getVolumesForEnvironment(envId, options)
+ });
+ }
+
async function refresh() {
- await volumesQuery.refetch();
+ await loadVolumes();
}
const isRefreshing = $derived(volumesQuery.isFetching && !volumesQuery.isPending);
@@ -103,15 +116,7 @@
<ResourcePageLayout title={m.volumes_title()} subtitle={m.volumes_subtitle()} {actionButtons} {statCards}>
{#snippet mainContent()}
- <VolumeTable
- bind:volumes
- bind:selectedIds
- bind:requestOptions
- onRefreshData={async (options) => {
- requestOptions = options;
- await volumesQuery.refetch();
- }}
- />
+ <VolumeTable bind:volumes bind:selectedIds bind:requestOptions onRefreshData={loadVolumes} />
{/snippet}
{#snippet additionalContent()}
diff --git a/frontend/src/routes/(app)/volumes/[volumeName]/+page.svelte b/frontend/src/routes/(app)/volumes/[volumeName]/+page.svelte
index 97f8d824e..fba9c0a30 100644
--- a/frontend/src/routes/(app)/volumes/[volumeName]/+page.svelte
+++ b/frontend/src/routes/(app)/volumes/[volumeName]/+page.svelte
@@ -20,6 +20,7 @@
import settingsStore from '$lib/stores/config-store';
import { environmentStore } from '$lib/stores/environment.store.svelte';
import { hasPermission } from '$lib/utils/auth';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { data } = $props();
let volume = $state(untrack(() => data.volume));
@@ -60,8 +61,8 @@
result: await tryCatch(volumeService.deleteVolume(safeName)),
message: m.volumes_remove_failed({ name: safeName }),
setLoadingState: (value) => (isLoading.remove = value),
- onSuccess: async () => {
- toast.success(m.volumes_remove_success({ name: safeName }));
+ onSuccess: async (data) => {
+ toast.success(m.volumes_remove_success({ name: safeName }), activityToastOptions(extractActivityId(data)));
goto('/volumes');
}
});
diff --git a/frontend/src/routes/(app)/volumes/components/volume-backup-table.svelte b/frontend/src/routes/(app)/volumes/components/volume-backup-table.svelte
index f43c02659..e7c23a137 100644
--- a/frontend/src/routes/(app)/volumes/components/volume-backup-table.svelte
+++ b/frontend/src/routes/(app)/volumes/components/volume-backup-table.svelte
@@ -34,6 +34,7 @@
import { environmentStore } from '$lib/stores/environment.store.svelte';
import { hasPermission } from '$lib/utils/auth';
import IfPermitted from '$lib/components/if-permitted.svelte';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let { volumeName }: { volumeName: string } = $props();
@@ -85,8 +86,8 @@
async function handleCreate() {
creating = true;
try {
- await volumeBackupService.createBackup(volumeName);
- toast.success(m.common_success());
+ const result = await volumeBackupService.createBackup(volumeName);
+ toast.success(m.common_success(), activityToastOptions(extractActivityId(result)));
await loadData(requestOptions);
} catch (e: any) {
toast.error(e.message || m.common_failed());
@@ -104,8 +105,8 @@
destructive: true,
action: async () => {
try {
- await volumeBackupService.deleteBackup(backup.id);
- toast.success(m.common_delete_success({ resource: 'Backup' }));
+ const result = await volumeBackupService.deleteBackup(backup.id);
+ toast.success(m.common_delete_success({ resource: 'Backup' }), activityToastOptions(extractActivityId(result)));
await loadData(requestOptions);
} catch (e: any) {
toast.error(e.message || m.common_delete_failed({ resource: 'Backup' }));
@@ -173,8 +174,8 @@
destructive: !!usageWarning,
action: async () => {
try {
- await volumeBackupService.restoreBackup(volumeName, backup.id);
- toast.success(m.volumes_backup_restore_success());
+ const result = await volumeBackupService.restoreBackup(volumeName, backup.id);
+ toast.success(m.volumes_backup_restore_success(), activityToastOptions(extractActivityId(result)));
await loadData(requestOptions);
} catch (e: any) {
toast.error(e.message || m.common_failed());
@@ -190,8 +191,11 @@
restoringFiles = true;
try {
- await volumeBackupService.restoreBackupFiles(volumeName, restoreTarget.id, selectedPaths);
- toast.success(m.volumes_backup_restore_files_success({ count: selectedPaths.length }));
+ const result = await volumeBackupService.restoreBackupFiles(volumeName, restoreTarget.id, selectedPaths);
+ toast.success(
+ m.volumes_backup_restore_files_success({ count: selectedPaths.length }),
+ activityToastOptions(extractActivityId(result))
+ );
showRestoreFiles = false;
} catch (e: any) {
toast.error(e.message || m.common_failed());
@@ -378,7 +382,7 @@
<div class="text-muted-foreground flex items-center justify-center py-8 text-sm">No files found in this backup.</div>
{:else}
<div class="divide-border/40 divide-y">
- {#each filteredBackupFiles as filePath}
+ {#each filteredBackupFiles as filePath (filePath)}
<div class="flex items-center gap-3 px-3 py-2">
<Checkbox.Root
checked={selectedPaths.includes(filePath)}
diff --git a/frontend/src/routes/(app)/volumes/volume-table.svelte b/frontend/src/routes/(app)/volumes/volume-table.svelte
index a6c074e8b..e763c41c5 100644
--- a/frontend/src/routes/(app)/volumes/volume-table.svelte
+++ b/frontend/src/routes/(app)/volumes/volume-table.svelte
@@ -24,6 +24,7 @@
import { SvelteMap } from 'svelte/reactivity';
import { environmentStore } from '$lib/stores/environment.store.svelte';
import { hasPermission } from '$lib/utils/auth';
+ import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
let {
volumes = $bindable(),
@@ -114,8 +115,11 @@
result: await tryCatch(volumeService.deleteVolume(safeName)),
message: m.common_remove_failed({ resource: `${m.resource_volume()} "${safeName}"` }),
setLoadingState: (value) => (isLoading.removing = value),
- onSuccess: async () => {
- toast.success(m.common_remove_success({ resource: `${m.resource_volume()} "${safeName}"` }));
+ onSuccess: async (data) => {
+ toast.success(
+ m.common_remove_success({ resource: `${m.resource_volume()} "${safeName}"` }),
+ activityToastOptions(extractActivityId(data))
+ );
await refreshVolumes();
}
});
diff --git a/go.work.sum b/go.work.sum
index 419036c7b..44af362de 100644
--- a/go.work.sum
+++ b/go.work.sum
@@ -762,6 +762,8 @@ github.com/letsencrypt/boulder v0.20251110.0/go.mod h1:ogKCJQwll82m7OVHWyTuf8eeF
github.com/letsencrypt/boulder v0.20260223.0 h1:xdS2OnJNUasR6TgVIOpqqcvdkOu47+PQQMBk9ThuWBw=
github.com/letsencrypt/boulder v0.20260223.0/go.mod h1:r3aTSA7UZ7dbDfiGK+HLHJz0bWNbHk6YSPiXgzl23sA=
github.com/lib/pq v0.0.0-20150723085316-0dad96c0b94f/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
+github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
+github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.5.3 h1:C8fxWnhYyME3n0klPOhVM7PtYUB3eV1W3DeFmN3j53Y=
github.com/magiconair/properties v1.5.3/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
@@ -804,6 +806,7 @@ github.com/mistifyio/go-zfs/v3 v3.1.0 h1:FZaylcg0hjUp27i23VcJJQiuBeAZjrC8lPqCGM1
github.com/mistifyio/go-zfs/v3 v3.1.0/go.mod h1:CzVgeB0RvF2EGzQnytKVvVSDwmKJXxkOTUGbNrTja/k=
github.com/mistifyio/go-zfs/v4 v4.0.0 h1:sU0+5dX45tdDK5xNZ3HBi95nxUc48FS92qbIZEvpAg4=
github.com/mistifyio/go-zfs/v4 v4.0.0/go.mod h1:weotFtXTHvBwhr9Mv96KYnDkTPBOHFUbm9cBmQpesL0=
+github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 29abe484b..77468c5fd 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -24,6 +24,8 @@ overrides:
fast-uri: '>=3.1.2'
ws: '>=8.20.1'
+packageExtensionsChecksum: sha256-Yj0m2AD9TZO/cWup5bCg2l8l7VHtLu5doy9Oybhgv+w=
+
importers:
.:
@@ -5246,6 +5248,7 @@ snapshots:
dependencies:
+ '@codemirror/search': 6.7.0
codemirror: 6.0.2
svelte: 5.56.1
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index ba15f5497..950768442 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -2,6 +2,12 @@ packages:
- frontend
- tests
- email-templates
+
+packageExtensions:
+ dependencies:
+ "@codemirror/search": ^6.7.0
+
overrides:
devalue: ">=5.8.1"
valibot: ^1.2.0
diff --git a/tests/setup/gitops.setup.ts b/tests/setup/gitops.setup.ts
index 575489199..ad881eb63 100644
--- a/tests/setup/gitops.setup.ts
+++ b/tests/setup/gitops.setup.ts
@@ -18,7 +18,7 @@ setup('create gitops sync in arcane', async ({ page }) => {
// Step 1: Create a Git Repository in Arcane pointing to GitHub
await page.goto('/customize/git-repositories');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// Check if test repo already exists
const existingRepo = page.getByRole('cell', { name: GITOPS_REPO_NAME });
@@ -68,7 +68,7 @@ setup('create gitops sync in arcane', async ({ page }) => {
// Step 2: Create GitOps Sync
await page.goto('/environments/0/gitops');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// Check if sync already exists
const existingSync = page.getByRole('cell', { name: GITOPS_SYNC_NAME });
@@ -151,7 +151,7 @@ setup('create gitops sync in arcane', async ({ page }) => {
// Step 3: Trigger initial sync to create the managed project
console.log('Triggering initial sync...');
await page.reload();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// Find the sync row and trigger sync
const syncRow = page.locator('tr').filter({ hasText: GITOPS_SYNC_NAME });
@@ -178,7 +178,7 @@ setup('create gitops sync in arcane', async ({ page }) => {
// Verify project was created
await page.goto('/projects');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.waitForTimeout(2000);
console.log('GitOps test setup complete!');
diff --git a/tests/spec/activity-center.spec.ts b/tests/spec/activity-center.spec.ts
new file mode 100644
index 000000000..ccf1d7a38
--- /dev/null
+++ b/tests/spec/activity-center.spec.ts
@@ -0,0 +1,114 @@
+import { test, expect, type Page } from '@playwright/test';
+
+function extractActivityId(value: unknown): string | undefined {
+ if (!value || typeof value !== 'object') return undefined;
+
+ const activityId = (value as { activityId?: unknown }).activityId;
+ if (typeof activityId === 'string' && activityId.trim()) return activityId;
+
+ if (Array.isArray(value)) {
+ for (const item of value) {
+ const nested = extractActivityId(item);
+ if (nested) return nested;
+ }
+ return undefined;
+ }
+
+ for (const item of Object.values(value)) {
+ const nested = extractActivityId(item);
+ if (nested) return nested;
+ }
+
+ return undefined;
+}
+
+function extractCreatedNetworkId(value: unknown): string | undefined {
+ if (!value || typeof value !== 'object') return undefined;
+ const data = (value as { data?: { id?: unknown } }).data;
+ return typeof data?.id === 'string' ? data.id : undefined;
+}
+
+async function createNetworkViaUI(page: Page, networkName: string) {
+ await page.goto('/networks');
+ await page.waitForLoadState('load');
+ await expect(page.getByRole('heading', { level: 1, name: 'Networks' })).toBeVisible();
+
+ await page.getByRole('button', { name: 'Create Network' }).first().click();
+ const dialog = page.getByRole('dialog');
+ await expect(dialog).toBeVisible();
+ await dialog.locator('#network-name').fill(networkName);
+
+ const createRequest = page.waitForResponse(
+ (response) => {
+ const request = response.request();
+ return (
+ request.method() === 'POST' &&
+ /\/api\/environments\/[^/]+\/networks$/.test(new URL(response.url()).pathname)
+ );
+ },
+ { timeout: 15000 }
+ );
+
+ await dialog.getByRole('button', { name: 'Create Network' }).click();
+ const createResponse = await createRequest;
+ const body = await createResponse.json();
+ if (!createResponse.ok()) {
+ throw new Error(`Failed to create network ${networkName}: ${createResponse.status()}`);
+ }
+
+ return {
+ activityId: extractActivityId(body),
+ networkId: extractCreatedNetworkId(body)
+ };
+}
+
+async function removeNetworkViaApi(page: Page, networkId: string | undefined) {
+ if (!networkId) return;
+ await page.request
+ .delete(`/api/environments/0/networks/${encodeURIComponent(networkId)}`)
+ .catch(() => undefined);
+}
+
+async function openActivityCenter(page: Page) {
+ await page.getByRole('button', { name: 'Open activity center' }).first().click();
+ const activityCenter = page.getByRole('dialog', { name: 'Activity Center' });
+ await expect(activityCenter).toBeVisible();
+ return activityCenter;
+}
+
+test.describe('Activity Center', () => {
+ test('shows completed activity details for UI-triggered work', async ({ page }) => {
+ const networkName = `e2e-activity-network-${Date.now()}`;
+ let networkId: string | undefined;
+
+ try {
+ const created = await createNetworkViaUI(page, networkName);
+ networkId = created.networkId;
+ expect(created.activityId).toBeTruthy();
+
+ const activityCenter = await openActivityCenter(page);
+ await expect(activityCenter.getByRole('button', { name: 'Running' })).toBeVisible();
+ await expect(activityCenter.getByRole('button', { name: 'Failed' })).toBeVisible();
+ await activityCenter.getByRole('button', { name: 'Completed' }).click();
+
+ const activityItem = activityCenter
+ .locator('button[aria-label="Activity Center"]')
+ .filter({ hasText: networkName })
+ .first();
+ await expect(activityItem).toBeVisible();
+ await expect(activityItem).toContainText('Resource Action');
+ await expect(activityItem).toContainText('Success');
+ await expect(activityItem).toContainText('Local');
+ await expect(activityItem).toContainText(/Started by/i);
+
+ await activityItem.click();
+ await expect(activityCenter.getByText('Output', { exact: true })).toBeVisible();
+ await expect(activityCenter.getByText('Creating network').first()).toBeVisible();
+ await expect(activityCenter.getByText('Network created successfully').first()).toBeVisible();
+ await expect(activityCenter.getByText('Source environment')).toBeVisible();
+ await expect(activityCenter.getByText('Started by', { exact: true })).toBeVisible();
+ } finally {
+ await removeNetworkViaApi(page, networkId);
+ }
+ });
+});
diff --git a/tests/spec/api-keys.spec.ts b/tests/spec/api-keys.spec.ts
index 531eec264..b11a42b49 100644
--- a/tests/spec/api-keys.spec.ts
+++ b/tests/spec/api-keys.spec.ts
@@ -5,7 +5,7 @@ const API_KEYS_ROUTE = '/settings/api-keys';
async function navigateToApiKeys(page: Page) {
await page.goto(API_KEYS_ROUTE);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
}
test.describe('API Keys Page', () => {
diff --git a/tests/spec/builds.spec.ts b/tests/spec/builds.spec.ts
index ade00d741..5a3c6290a 100644
--- a/tests/spec/builds.spec.ts
+++ b/tests/spec/builds.spec.ts
@@ -20,7 +20,7 @@ const FIELD_LABELS = {
async function navigateToBuildWorkspace(page: Page) {
await page.goto(ROUTES.page);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByRole('heading', { level: 1, name: /Build Workspace/i })).toBeVisible();
}
diff --git a/tests/spec/container-grouped-pagination.spec.ts b/tests/spec/container-grouped-pagination.spec.ts
index 429b4b110..f7763b601 100644
--- a/tests/spec/container-grouped-pagination.spec.ts
+++ b/tests/spec/container-grouped-pagination.spec.ts
@@ -153,7 +153,7 @@ test('grouped containers do not split the same project across pages', async ({ p
});
await page.goto('/containers');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.setViewportSize({ width: 1440, height: 900 });
diff --git a/tests/spec/containers.spec.ts b/tests/spec/containers.spec.ts
index 0571b3e3c..1d30cb403 100644
--- a/tests/spec/containers.spec.ts
+++ b/tests/spec/containers.spec.ts
@@ -6,7 +6,7 @@ const CONTAINERS_ROUTE = '/containers';
async function navigateToContainers(page: Page) {
await page.goto(CONTAINERS_ROUTE);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
}
let containersData: Paginated<ContainerSummary> = { data: [], pagination: { totalItems: 0 } };
@@ -66,7 +66,7 @@ test.describe('Containers Page', () => {
test.skip(!running, 'No running container available');
await page.goto(`/containers/${running!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.getByRole('tab', { name: 'Logs' }).click();
@@ -87,7 +87,7 @@ test.describe('Containers Page', () => {
test.skip(!stopped, 'No stopped container available');
await page.goto(`/containers/${stopped!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.getByRole('tab', { name: 'Logs' }).click();
diff --git a/tests/spec/converter.spec.ts b/tests/spec/converter.spec.ts
index 0fd52b49d..60641cbea 100644
--- a/tests/spec/converter.spec.ts
+++ b/tests/spec/converter.spec.ts
@@ -23,33 +23,20 @@ const SELECTORS = {
};
async function openConvertFromDockerRun(page: Page) {
- // Wait for the page to be fully loaded
- await page.waitForLoadState('networkidle');
-
- // Split-button chevron trigger on /projects/new. (Trigger is rendered via child snippet,
- // so data-slot="dropdown-menu-trigger" may not be present on the final button element.)
- let dropdownTrigger = page.locator('button.rounded-l-none.px-2').first();
- if ((await dropdownTrigger.count()) === 0) {
- // Fallback for markup changes: use the old icon-only heuristic
- dropdownTrigger = page.locator('button:has(svg)').filter({ hasText: '' }).last();
- }
+ await page.waitForLoadState('load');
+ const createProjectGroup = page
+ .getByRole('group')
+ .filter({ has: page.getByRole('button', { name: 'Create Project' }) })
+ .first();
+ const dropdownTrigger = createProjectGroup.locator('button').last();
await expect(dropdownTrigger).toBeVisible();
await dropdownTrigger.click();
- // Prefer text match, but keep positional fallback for non-English locales.
- const menuItems = page.locator('[data-slot="dropdown-menu-item"], [role="menuitem"]');
- await expect(menuItems.first()).toBeVisible();
-
- const convertItemByText = menuItems.filter({ hasText: /Convert from Docker Run/i }).first();
- if (await convertItemByText.count()) {
- await convertItemByText.click();
- } else {
- // Item order in this menu is: template, converter, git repo, separator, ...
- await menuItems.nth(1).click();
- }
+ const menu = page.locator('[data-slot="dropdown-menu-content"]:visible').last();
+ await expect(menu).toBeVisible();
+ await menu.getByRole('menuitem', { name: /Convert from Docker Run/i }).click();
- // Ensure converter dialog is open before interacting with inputs
await expect(page.getByRole('button', SELECTORS.convertButton())).toBeVisible();
}
@@ -66,7 +53,7 @@ async function setupMockConvert(page: Page, payload: ConvertResponse) {
test.describe('Docker Run to Compose Converter', () => {
test.beforeEach(async ({ page }) => {
await page.goto(ROUTES.page);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
});
test('should convert simple docker run command', async ({ page }) => {
diff --git a/tests/spec/dashboard-system-stats.spec.ts b/tests/spec/dashboard-system-stats.spec.ts
index 2e8c93262..883921b08 100644
--- a/tests/spec/dashboard-system-stats.spec.ts
+++ b/tests/spec/dashboard-system-stats.spec.ts
@@ -124,7 +124,7 @@ test.describe('Dashboard system stats websocket', () => {
await mockDashboardStatsWebSocket(page);
await page.goto(defaultDashboardPath);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByRole('tab', { name: 'All' })).toHaveAttribute('data-state', 'active');
await expect(page.getByRole('heading', { name: 'Overview' })).toBeVisible();
@@ -146,9 +146,10 @@ test.describe('Dashboard system stats websocket', () => {
const requestPaths = collectDashboardRequestPaths(page);
await page.goto(defaultDashboardPath);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
+ await expect(page.getByRole('heading', { name: 'Environment Board' })).toBeVisible();
- expect(requestPaths).toContain('/api/dashboard/environments');
+ await expect.poll(() => requestPaths).toContain('/api/dashboard/environments');
for (const blockedPattern of [
/\/api\/environments\/[^/]+\/dashboard$/,
@@ -173,10 +174,10 @@ test.describe('Dashboard system stats websocket', () => {
const requestPaths = collectDashboardRequestPaths(page);
await page.goto(defaultDashboardPath);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.getByRole('tab', { name: 'Current' }).click();
await expect(page).toHaveURL(currentDashboardPath);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
expect(
countMatchingRequests(requestPaths, /\/api\/environments\/[^/]+\/system\/docker\/info$/)
diff --git a/tests/spec/edge-agent.spec.ts b/tests/spec/edge-agent.spec.ts
index 06f2974f9..a3de3f1e3 100644
--- a/tests/spec/edge-agent.spec.ts
+++ b/tests/spec/edge-agent.spec.ts
@@ -6,7 +6,7 @@ const ROUTES = {
async function openNewEnvironmentSheet(page: Page) {
await page.goto(ROUTES.environments);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const addButton = page.getByRole('button', { name: 'Add Environment', exact: true });
await expect(addButton).toBeVisible();
diff --git a/tests/spec/environment-settings.spec.ts b/tests/spec/environment-settings.spec.ts
index 94deaafe1..19e2708c2 100644
--- a/tests/spec/environment-settings.spec.ts
+++ b/tests/spec/environment-settings.spec.ts
@@ -4,14 +4,14 @@ const LOCAL_ENV_ID = '0';
async function openEnvironment(page: Page, environmentId: string) {
await page.goto(`/environments/${environmentId}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.locator('#env-name')).toBeVisible();
await expect(page.getByRole('button', { name: 'Save', exact: true }).first()).toBeVisible();
}
async function createDirectEnvironmentViaUI(page: Page, environmentName: string) {
await page.goto('/environments');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.getByRole('button', { name: 'Add Environment', exact: true }).click();
await expect(page.getByText('Create New Agent Environment')).toBeVisible();
@@ -27,7 +27,7 @@ async function createDirectEnvironmentViaUI(page: Page, environmentName: string)
async function deleteEnvironmentViaUI(page: Page, environmentName: string) {
await page.goto('/environments');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const envRow = page.locator('tr').filter({
has: page.getByRole('button', { name: environmentName, exact: true })
diff --git a/tests/spec/image-updates.spec.ts b/tests/spec/image-updates.spec.ts
index 16d486311..c5ec98cda 100644
--- a/tests/spec/image-updates.spec.ts
+++ b/tests/spec/image-updates.spec.ts
@@ -1,4 +1,4 @@
-import { test, expect, type Page } from '@playwright/test';
+import { test, expect, type Locator, type Page } from '@playwright/test';
import { fetchImagesWithRetry } from '../utils/fetch.util';
const ROUTES = {
@@ -42,7 +42,7 @@ interface UpdateSummary {
async function navigateToImages(page: Page) {
await page.goto(ROUTES.page);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
}
async function fetchImagesTotal(page: Page, updatesFilter?: string): Promise<number> {
@@ -59,6 +59,43 @@ async function fetchImagesTotal(page: Page, updatesFilter?: string): Promise<num
return Number.isFinite(totalItems) ? totalItems : 0;
}
+async function getCheckUpdatesAction(page: Page): Promise<Locator> {
+ const pageHeader = page
+ .locator('main header')
+ .filter({ has: page.getByRole('heading', { name: 'Images', exact: true }) })
+ .first();
+ await expect(pageHeader).toBeVisible();
+
+ const directButton = pageHeader
+ .getByRole('button', { name: 'Check Updates', exact: true })
+ .filter({ visible: true })
+ .first();
+
+ if (
+ await expect(directButton)
+ .toBeVisible({ timeout: 5000 })
+ .then(
+ () => true,
+ () => false
+ )
+ ) {
+ return directButton;
+ }
+
+ const menuTrigger = pageHeader
+ .getByRole('button', { name: 'More actions' })
+ .filter({ visible: true })
+ .first();
+ await expect(menuTrigger).toBeVisible();
+ await menuTrigger.click();
+
+ const menu = page.locator('[data-slot="dropdown-menu-content"]:visible').last();
+ await expect(menu).toBeVisible();
+ const menuItem = menu.getByRole('menuitem', { name: 'Check Updates', exact: true }).first();
+ await expect(menuItem).toBeVisible();
+ return menuItem;
+}
+
let realImages: any[] = [];
test.beforeEach(async ({ page }) => {
@@ -76,42 +113,26 @@ test.describe('Image Update UI - Check All Updates Button', () => {
test('should display the Check Updates button on images page', async ({ page }) => {
await navigateToImages(page);
- // Find the Check Updates button - it might be directly visible or in a menu
- let checkUpdatesButton = page.getByRole('button', { name: 'Check Updates' });
- const isDirectlyVisible = await checkUpdatesButton.isVisible().catch(() => false);
-
- if (!isDirectlyVisible) {
- // Try to find and click the overflow menu trigger
- const menuTrigger = page.getByRole('button', { name: 'More actions' });
- await menuTrigger.click();
- checkUpdatesButton = page.getByRole('menuitem', { name: 'Check Updates' });
- }
-
+ const checkUpdatesButton = await getCheckUpdatesAction(page);
await expect(checkUpdatesButton).toBeVisible();
});
test('should trigger bulk update check when clicking Check Updates button', async ({ page }) => {
await navigateToImages(page);
- // Find the Check Updates button - it might be directly visible or in a menu
- let checkUpdatesButton = page.getByRole('button', { name: 'Check Updates' });
- const isDirectlyVisible = await checkUpdatesButton.isVisible().catch(() => false);
-
- if (!isDirectlyVisible) {
- // Try to find and click the overflow menu trigger
- const menuTrigger = page.getByRole('button', { name: 'More actions' });
- await menuTrigger.click();
- checkUpdatesButton = page.getByRole('menuitem', { name: 'Check Updates' });
- }
-
+ const checkUpdatesButton = await getCheckUpdatesAction(page);
await expect(checkUpdatesButton).toBeVisible();
+ const checkAllResponsePromise = page.waitForResponse((response) => {
+ const request = response.request();
+ if (request.method() !== 'POST') return false;
+ return new URL(response.url()).pathname === ROUTES.apiImageUpdatesCheckAll;
+ });
+
await checkUpdatesButton.click();
- if (isDirectlyVisible) {
- // If it's a direct button, it should show a loading state
- await expect(checkUpdatesButton).toContainText(/checking/i, { timeout: 10000 });
- }
+ const checkAllResponse = await checkAllResponsePromise;
+ expect(checkAllResponse.ok()).toBeTruthy();
// Eventually a success or completion toast should appear
await expect(page.locator('li[data-sonner-toast]')).toBeVisible({ timeout: 60000 });
@@ -306,7 +327,7 @@ test.describe('Image Update UI Integration', () => {
// Navigate to image detail
await page.goto(`/images/${encodeURIComponent(testImage.id)}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// The detail page should load
await expect(page.locator('h1, h2, [data-testid="image-detail"]').first()).toBeVisible({
diff --git a/tests/spec/images.spec.ts b/tests/spec/images.spec.ts
index 79494648c..96425690f 100644
--- a/tests/spec/images.spec.ts
+++ b/tests/spec/images.spec.ts
@@ -9,7 +9,7 @@ const ROUTES = {
async function navigateToImages(page: Page) {
await page.goto(ROUTES.page);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
}
async function fetchAllImagesForUsage(page: Page): Promise<any[]> {
@@ -135,7 +135,7 @@ test.describe('Images Page', () => {
await firstRow.getByRole('button', { name: 'Open menu' }).click();
await page.getByRole('menuitem', { name: 'Pull' }).click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(
page.locator(`li[data-sonner-toast][data-type="success"] div[data-title]`)
diff --git a/tests/spec/network.spec.ts b/tests/spec/network.spec.ts
index 43610f0ca..5ad0c0cea 100644
--- a/tests/spec/network.spec.ts
+++ b/tests/spec/network.spec.ts
@@ -3,7 +3,7 @@ import { fetchNetworksCountsWithRetry } from '../utils/fetch.util';
async function navigateToNetworks(page: Page) {
await page.goto('/networks');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
}
test.beforeEach(async ({ page }) => {
@@ -28,6 +28,7 @@ async function createNetworkViaUI(page: Page, networkName: string) {
await page.getByRole('dialog').getByRole('button', { name: 'Create Network' }).click();
const createResponse = await createRequest;
+ const responseBody = await createResponse.json().catch(() => undefined);
if (!createResponse.ok()) {
const responseText = await createResponse.text().catch(() => '');
throw new Error(
@@ -35,8 +36,23 @@ async function createNetworkViaUI(page: Page, networkName: string) {
);
}
- await navigateToNetworks(page);
- await expect(await findNetworkRow(page, networkName, 15)).toBeVisible();
+ return responseBody?.data?.id ?? networkName;
+}
+
+async function createNetworkViaApi(page: Page, networkName: string) {
+ const response = await page.request.post('/api/environments/0/networks', {
+ data: {
+ name: networkName,
+ options: {
+ driver: 'bridge'
+ }
+ }
+ });
+ if (!response.ok()) {
+ throw new Error(
+ `Failed to create network ${networkName}: ${response.status()} ${await response.text()}`
+ );
+ }
}
async function findNetworkRow(page: Page, networkName: string, maxRetries = 10) {
@@ -54,19 +70,10 @@ async function findNetworkRow(page: Page, networkName: string, maxRetries = 10)
return page.locator('tbody tr', { has: page.getByText(networkName) }).first();
}
-async function removeNetworkViaUI(page: Page, networkName: string) {
- await navigateToNetworks(page);
-
- const row = await findNetworkRow(page, networkName, 4);
- if ((await row.count()) === 0) return;
-
- await row.locator('a[href*="/networks/"]').first().click();
- await expect(page).toHaveURL(/\/networks\/.+/);
- await page.getByRole('button', { name: 'Remove', exact: true }).click();
- await page.getByRole('button', { name: 'Remove', exact: true }).last().click();
- await expect(
- page.locator('li[data-sonner-toast][data-type="success"] div[data-title]')
- ).toBeVisible();
+async function removeNetworkViaApi(page: Page, networkName: string) {
+ await page.request
+ .delete(`/api/environments/0/networks/${encodeURIComponent(networkName)}`)
+ .catch(() => undefined);
}
test.describe('Networks Page', () => {
@@ -92,51 +99,45 @@ test.describe('Networks Page', () => {
const networkName = `e2e-table-network-${Date.now()}`;
await navigateToNetworks(page);
try {
- await createNetworkViaUI(page, networkName);
+ await createNetworkViaApi(page, networkName);
await navigateToNetworks(page);
await expect(page.locator('table')).toBeVisible();
await expect(page.getByRole('button', { name: 'Name' })).toBeVisible();
await expect(await findNetworkRow(page, networkName)).toBeVisible();
} finally {
- await removeNetworkViaUI(page, networkName);
+ await removeNetworkViaApi(page, networkName);
}
});
test('Open Create Network sheet', async ({ page }) => {
const networkName = `test-network-${Date.now()}`;
try {
- await createNetworkViaUI(page, networkName);
- await navigateToNetworks(page);
- await expect(await findNetworkRow(page, networkName)).toBeVisible();
+ const networkId = await createNetworkViaUI(page, networkName);
+ const response = await page.request.get(
+ `/api/environments/0/networks/${encodeURIComponent(networkId)}`
+ );
+ expect(response.ok()).toBe(true);
} finally {
- await removeNetworkViaUI(page, networkName);
+ await removeNetworkViaApi(page, networkName);
}
});
test('Inspect Network from row actions', async ({ page }) => {
const networkName = `e2e-inspect-network-${Date.now()}`;
try {
- await createNetworkViaUI(page, networkName);
- await navigateToNetworks(page);
-
- const row = await findNetworkRow(page, networkName);
- await expect(row).toBeVisible();
- await row.locator('a[href*="/networks/"]').first().click();
+ await createNetworkViaApi(page, networkName);
+ await page.goto(`/networks/${encodeURIComponent(networkName)}`);
await expect(page).toHaveURL(/\/networks\/.+/);
await expect(page.getByRole('heading', { level: 1, name: networkName })).toBeVisible();
} finally {
- await removeNetworkViaUI(page, networkName);
+ await removeNetworkViaApi(page, networkName);
}
});
- test('Remove Network from table', async ({ page }) => {
+ test('Remove Network from details page', async ({ page }) => {
const networkName = `test-remove-network-${Date.now()}`;
- await createNetworkViaUI(page, networkName);
- await navigateToNetworks(page);
- const row = await findNetworkRow(page, networkName);
- await expect(row).toBeVisible();
-
- await row.locator('a[href*="/networks/"]').first().click();
+ await createNetworkViaApi(page, networkName);
+ await page.goto(`/networks/${encodeURIComponent(networkName)}`);
await expect(page).toHaveURL(/\/networks\/.+/);
await page.getByRole('button', { name: 'Remove', exact: true }).click();
await page.getByRole('button', { name: 'Remove', exact: true }).last().click();
@@ -144,9 +145,14 @@ test.describe('Networks Page', () => {
page.locator('li[data-sonner-toast][data-type="success"] div[data-title]')
).toBeVisible();
- await navigateToNetworks(page);
- const removedRow = await findNetworkRow(page, networkName, 2);
- await expect(removedRow).not.toBeVisible();
+ await expect
+ .poll(async () => {
+ const response = await page.request.get(
+ `/api/environments/0/networks/${encodeURIComponent(networkName)}`
+ );
+ return response.status();
+ })
+ .toBe(404);
});
test('Default networks cannot be removed on details page', async ({ page }) => {
@@ -156,7 +162,7 @@ test.describe('Networks Page', () => {
.first();
await expect(bridgeRow).toBeVisible();
await bridgeRow.locator('a[href*="/networks/"]').first().click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const removeBtn = page.getByRole('button', { name: 'Remove' });
await expect(removeBtn).toBeDisabled();
@@ -165,16 +171,13 @@ test.describe('Networks Page', () => {
test('Details page shows usage badge', async ({ page }) => {
const networkName = `e2e-badge-network-${Date.now()}`;
try {
- await createNetworkViaUI(page, networkName);
- await navigateToNetworks(page);
- const row = await findNetworkRow(page, networkName);
- await expect(row).toBeVisible();
- await row.locator('a[href*="/networks/"]').first().click();
- await page.waitForLoadState('networkidle');
+ await createNetworkViaApi(page, networkName);
+ await page.goto(`/networks/${encodeURIComponent(networkName)}`);
+ await page.waitForLoadState('load');
await expect(page.getByText('Unused').first()).toBeVisible();
} finally {
- await removeNetworkViaUI(page, networkName);
+ await removeNetworkViaApi(page, networkName);
}
});
});
diff --git a/tests/spec/project.spec.ts b/tests/spec/project.spec.ts
index c206664e7..ca60ffa01 100644
--- a/tests/spec/project.spec.ts
+++ b/tests/spec/project.spec.ts
@@ -17,7 +17,7 @@ const DEPLOY_STREAM_SUCCESS =
async function navigateToProjects(page: Page) {
await page.goto(ROUTES.page);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
}
async function setCodeMirrorValue(page: Page, editor: Locator, text: string) {
@@ -52,16 +52,12 @@ async function openDropdownMenu(page: Page, trigger: Locator) {
}
async function clickProjectsPageUpdateAction(page: Page) {
- const updateProjectsButton = page.getByRole('button', { name: 'Update Projects', exact: true });
- if (await updateProjectsButton.isVisible().catch(() => false)) {
- await updateProjectsButton.click();
- return;
- }
-
- const moreActionsButton = page.getByRole('button', { name: 'More actions', exact: true });
- await expect(moreActionsButton).toBeVisible();
- await moreActionsButton.click();
- await page.getByRole('menuitem', { name: 'Update Projects', exact: true }).click();
+ const updateProjectsButton = page
+ .locator('main button:visible')
+ .filter({ hasText: 'Update Projects' })
+ .first();
+ await expect(updateProjectsButton).toBeVisible();
+ await updateProjectsButton.click();
}
async function clickProjectDetailUpdateAction(page: Page) {
@@ -139,7 +135,7 @@ async function createProjectViaUI(page: Page, projectName: string) {
const envFile = TEST_ENV_FILE.replace(/CONTAINER_NAME=.*/m, `CONTAINER_NAME=${containerName}`);
await page.goto(ROUTES.newProject);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.getByRole('button', { name: 'My New Project' }).click();
await page.getByRole('textbox', { name: 'My New Project' }).fill(projectName);
@@ -203,7 +199,7 @@ async function destroyProjectByNameViaUI(page: Page, projectName: string) {
}
await page.goto(ROUTES.page);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const searchInput = page.getByPlaceholder('Search…');
if (await searchInput.isVisible().catch(() => false)) {
@@ -302,7 +298,7 @@ test.describe('Projects Page', () => {
test('should show project actions menu', async ({ page }) => {
test.skip(!realProjects.length, 'No projects available for actions menu test');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const firstRow = page.locator('tbody tr').first();
const menu = await openDropdownMenu(page, firstRow.getByRole('button', { name: 'Open menu' }));
@@ -337,7 +333,7 @@ test.describe('Projects Page', () => {
});
await page.goto(ROUTES.page);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.locator('tbody tr').filter({ hasText: projectName })).toHaveCount(0);
await page.getByLabel('Show archived').check();
@@ -367,7 +363,7 @@ test.describe('Projects Page', () => {
test('should navigate to project details when project name is clicked', async ({ page }) => {
test.skip(!realProjects.length, 'No projects available for navigation test');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// Get the first project link that points to /projects/ (not the "Git" indicator link)
const firstProjectLink = page
.locator('tbody tr')
@@ -427,7 +423,7 @@ test.describe('Projects Page', () => {
test('should display project status badges', async ({ page }) => {
test.skip(!realProjects.length, 'No projects available for status badge test');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const runningProjects = realProjects.filter((p) => p.status === 'running');
const stoppedProjects = realProjects.filter((p) => p.status === 'stopped');
@@ -445,7 +441,7 @@ test.describe('Projects Page', () => {
test.describe('New Compose Project Page', () => {
test.beforeEach(async ({ page }) => {
await page.goto(ROUTES.newProject);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
});
test('should display the create project form', async ({ page }) => {
@@ -635,7 +631,7 @@ test.describe('New Compose Project Page', () => {
await expect(page.getByRole('button', { name: projectName })).toBeVisible();
await page.getByRole('tab', { name: 'Services' }).click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const serviceTable = page.getByRole('table');
const serviceNameWhenStopped = serviceTable.getByText('nginx', {
@@ -661,7 +657,7 @@ test.describe('New Compose Project Page', () => {
await deployButton.click();
await page.waitForTimeout(5000);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
expect(projectPullRequestCount).toBe(0);
await expect(page.getByText('Running', { exact: true }).first()).toBeVisible({
@@ -760,7 +756,7 @@ test.describe('New Compose Project Page', () => {
try {
await createProjectViaUI(page, projectName);
await page.goto(ROUTES.page);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.route('**/api/environments/*/projects/*/redeploy', async (route) => {
if (route.request().method() !== 'POST') {
@@ -837,7 +833,7 @@ test.describe('New Compose Project Page', () => {
test.describe('GitOps Managed Project', () => {
test('should navigate back to gitops when opened from the git syncs page', async ({ page }) => {
await page.goto('/environments/0/gitops');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const projectLink = page.locator('tbody tr').locator('a[href^="/projects/"]').first();
test.skip((await projectLink.count()) === 0, 'No GitOps project links found');
@@ -858,12 +854,12 @@ test.describe('GitOps Managed Project', () => {
test.skip(!gitOpsProject, 'No GitOps-managed projects found');
await page.goto(`/projects/${gitOpsProject!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// Navigate to Configuration tab
const configTab = page.getByRole('tab', { name: /Configuration|Config/i });
await configTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// Verify the GitOps read-only alert is visible (title contains "Git" and "Read-only")
await expect(page.getByText('Git Read-only')).toBeVisible();
@@ -875,11 +871,11 @@ test.describe('GitOps Managed Project', () => {
test.skip(!gitOpsProject, 'No GitOps-managed projects found');
await page.goto(`/projects/${gitOpsProject!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const configTab = page.getByRole('tab', { name: /Configuration|Config/i });
await configTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// Verify the Sync from Git button is present
await expect(page.getByRole('button', { name: 'Sync from Git' })).toBeVisible();
@@ -890,7 +886,7 @@ test.describe('GitOps Managed Project', () => {
test.skip(!gitOpsProject, 'No GitOps-managed projects with sync commit found');
await page.goto(`/projects/${gitOpsProject!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// The commit hash should be visible somewhere on the page
const commitHash = gitOpsProject!.lastSyncCommit!.substring(0, 7);
@@ -902,7 +898,7 @@ test.describe('GitOps Managed Project', () => {
test.skip(!gitOpsProject, 'No GitOps-managed projects found');
await page.goto(`/projects/${gitOpsProject!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// The name button should be disabled for GitOps-managed projects
const nameButton = page.getByRole('button', { name: gitOpsProject!.name });
@@ -914,11 +910,11 @@ test.describe('GitOps Managed Project', () => {
test.skip(!gitOpsProject, 'No GitOps-managed projects found');
await page.goto(`/projects/${gitOpsProject!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const configTab = page.getByRole('tab', { name: /Configuration|Config/i });
await configTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.waitForTimeout(800);
const composeContent = page.locator('.cm-editor:visible').first().locator('.cm-content');
@@ -932,11 +928,11 @@ test.describe('GitOps Managed Project', () => {
test.skip(!gitOpsProject, 'No GitOps-managed projects found');
await page.goto(`/projects/${gitOpsProject!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const configTab = page.getByRole('tab', { name: /Configuration|Config/i });
await configTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.waitForTimeout(800);
const envEditor = page.locator('.cm-editor:visible').nth(1);
@@ -955,7 +951,7 @@ test.describe('GitOps Managed Project', () => {
});
if (await layoutSwitch.count()) {
await layoutSwitch.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const envFileButton = page.getByRole('button', { name: '.env' }).first();
await expect(envFileButton).toBeVisible();
@@ -973,7 +969,7 @@ test.describe('GitOps Managed Project', () => {
test.skip(!regularProject, 'No regular (non-GitOps) stopped projects found');
await page.goto(`/projects/${regularProject!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// The name button should be enabled for regular projects that are stopped
const nameButton = page.getByRole('button', { name: regularProject!.name });
@@ -982,7 +978,7 @@ test.describe('GitOps Managed Project', () => {
// Navigate to Configuration tab
const configTab = page.getByRole('tab', { name: /Configuration|Config/i });
await configTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// GitOps alert should NOT be visible
await expect(page.getByText('Git Read-only')).not.toBeVisible();
@@ -998,11 +994,11 @@ test.describe('GitOps Managed Project', () => {
test.skip(!regularProject, 'No regular (non-GitOps) projects found');
await page.goto(`/projects/${regularProject!.id}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const configTab = page.getByRole('tab', { name: /Configuration|Config/i });
await configTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
// Verify no GitOps-related UI elements
await expect(page.getByText(/managed by Git\./i)).not.toBeVisible();
@@ -1016,7 +1012,7 @@ test.describe('Project Detail Page', () => {
const firstProject = realProjects[0];
await page.goto(`/projects/${firstProject.id || firstProject.name}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const backLink = page.getByRole('link', { name: /^Back$/i }).first();
await expect(backLink).toBeVisible();
@@ -1031,7 +1027,7 @@ test.describe('Project Detail Page', () => {
const firstProject = realProjects[0];
await page.goto(`/projects/${firstProject.id || firstProject.name}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByRole('button', { name: firstProject.name, exact: false })).toBeVisible();
@@ -1044,7 +1040,7 @@ test.describe('Project Detail Page', () => {
test.skip(!realProjects.length, 'No projects available for navigation test');
const firstProject = realProjects[0];
await page.goto(`/projects/${firstProject.id || firstProject.name}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByRole('tab', { name: /Services/i })).toBeVisible();
await expect(page.getByRole('tab', { name: /Configuration|Config/i })).toBeVisible();
@@ -1086,7 +1082,7 @@ test.describe('Project Detail Page', () => {
});
await page.goto(`/projects/${projectWithServices!.id || projectWithServices!.name}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const clicked = await clickProjectDetailUpdateAction(page);
test.skip(!clicked, 'Current project detail view has no clickable update action');
@@ -1101,7 +1097,7 @@ test.describe('Project Detail Page', () => {
const projectWithServices =
realProjects.find((p) => (p.serviceCount ?? 0) > 0) ?? realProjects[0]!;
await page.goto(`/projects/${projectWithServices.id || projectWithServices.name}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await page.getByRole('tab', { name: /Services/i }).click();
@@ -1125,7 +1121,7 @@ test.describe('Project Detail Page', () => {
const firstProject = realProjects[0];
await page.goto(`/projects/${firstProject.id || firstProject.name}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const configTab = page.getByRole('tab', { name: /Configuration|Config/i });
await configTab.click();
@@ -1189,11 +1185,11 @@ test.describe('Project Detail Page', () => {
test.skip(!regularProject, 'No regular (non-GitOps) projects found');
await page.goto(`/projects/${regularProject!.id || regularProject!.name}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const configTab = page.getByRole('tab', { name: /Configuration|Config/i });
await configTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
let layoutSwitch = page.getByRole('switch', {
name: /Classic|Tree View/i
@@ -1213,12 +1209,12 @@ test.describe('Project Detail Page', () => {
}
await page.reload();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const restoredConfigTab = page.getByRole('tab', { name: /Configuration|Config/i });
if ((await restoredConfigTab.getAttribute('aria-selected')) !== 'true') {
await restoredConfigTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
}
await expect(projectFilesHeading).toBeVisible();
@@ -1255,7 +1251,7 @@ test.describe('Project Detail Page', () => {
try {
const configTab = page.getByRole('tab', { name: /Configuration|Config/i });
await configTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
let composeEditor = page.locator('.cm-editor:visible').first();
await expect(composeEditor).toBeVisible();
@@ -1296,12 +1292,12 @@ test.describe('Project Detail Page', () => {
}
await page.reload();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const restoredConfigTab = page.getByRole('tab', { name: /Configuration|Config/i });
if ((await restoredConfigTab.getAttribute('aria-selected')) !== 'true') {
await restoredConfigTab.click();
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
}
composeEditor = page.locator('.cm-editor:visible').first();
@@ -1324,7 +1320,7 @@ test.describe('Project Detail Page', () => {
const targetProject = runningProject!;
await page.goto(`/projects/${targetProject.id || targetProject.name}`);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const logsTab = page.getByRole('tab', { name: /Logs/i });
await expect(logsTab).toBeEnabled();
diff --git a/tests/spec/registries.spec.ts b/tests/spec/registries.spec.ts
index 57c0efa94..5346ccd5b 100644
--- a/tests/spec/registries.spec.ts
+++ b/tests/spec/registries.spec.ts
@@ -78,7 +78,7 @@ async function mockRegistryPullUsage(
test.describe('Container Registries', () => {
test.beforeEach(async ({ page }) => {
await page.goto(route);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
});
test('should display title and subtitle, and refresh', async ({ page }) => {
@@ -118,7 +118,7 @@ test.describe('Container Registries', () => {
await mockRegistryList(page);
await mockRegistryPullUsage(page, { remaining: 76, limit: 100, observedPulls: 4 });
await page.goto(route);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const table = page.getByRole('table');
await expect(table.getByText('Pull Usage')).toBeVisible();
@@ -131,7 +131,7 @@ test.describe('Container Registries', () => {
await mockRegistryList(page);
await mockRegistryPullUsage(page, { observedPulls: 4 });
await page.goto(route);
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const table = page.getByRole('table');
await expect(table.getByText('Pull Usage')).toBeVisible();
diff --git a/tests/spec/settings-notifications.spec.ts b/tests/spec/settings-notifications.spec.ts
index e9810bf10..322c69b37 100644
--- a/tests/spec/settings-notifications.spec.ts
+++ b/tests/spec/settings-notifications.spec.ts
@@ -76,7 +76,7 @@ test.describe('Notification settings', () => {
});
await page.goto('/settings/notifications');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByRole('tab', { name: 'Email' })).toBeVisible();
return {
diff --git a/tests/spec/swarm-ui.spec.ts b/tests/spec/swarm-ui.spec.ts
index 94fbe058d..53f5d82fd 100644
--- a/tests/spec/swarm-ui.spec.ts
+++ b/tests/spec/swarm-ui.spec.ts
@@ -31,7 +31,7 @@ test.describe('Swarm UI', () => {
page
}) => {
await page.goto('/swarm/cluster');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByRole('heading', { name: 'Cluster', level: 1 })).toBeVisible();
@@ -57,7 +57,7 @@ test.describe('Swarm UI', () => {
test('configs page renders name/data fields and empty state', async ({ page }) => {
await mockConfigs(page);
await page.goto('/swarm/configs');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByRole('heading', { name: 'Configs', level: 1 })).toBeVisible();
await expect(
@@ -72,7 +72,7 @@ test.describe('Swarm UI', () => {
test('secrets page renders name/data fields and empty state', async ({ page }) => {
await mockSecrets(page);
await page.goto('/swarm/secrets');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByRole('heading', { name: 'Secrets', level: 1 })).toBeVisible();
await expect(
diff --git a/tests/spec/token-refresh.spec.ts b/tests/spec/token-refresh.spec.ts
index 18ab2b907..a05683727 100644
--- a/tests/spec/token-refresh.spec.ts
+++ b/tests/spec/token-refresh.spec.ts
@@ -85,12 +85,12 @@ test.describe('Token refresh behaviour', () => {
}) => {
await registerTokenSeeding(page);
const wasRefreshCalled = await mockRefreshSuccess(page);
- await injectVersionMismatch401Once(page, /\/api\/auth\/me$/);
+ await injectVersionMismatch401Once(page, /\/api\/auth\/me(?:\?.*)?$/);
await page.goto('/dashboard');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
- expect(wasRefreshCalled()).toBe(true);
+ await expect.poll(() => wasRefreshCalled()).toBe(true);
await expect(page).toHaveURL('/dashboard');
await expect(page.getByRole('button', { name: 'Sign in to Arcane' })).not.toBeVisible();
});
@@ -100,12 +100,12 @@ test.describe('Token refresh behaviour', () => {
}) => {
await registerTokenSeeding(page);
const wasRefreshCalled = await mockRefreshSuccess(page);
- await injectVersionMismatch401Once(page, /\/api\/environments\/0\/containers/);
+ await injectVersionMismatch401Once(page, /\/api\/environments\/[^/]+\/containers/);
await page.goto('/containers');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
- expect(wasRefreshCalled()).toBe(true);
+ await expect.poll(() => wasRefreshCalled()).toBe(true);
await expect(page).toHaveURL('/containers');
await expect(page.getByRole('heading', { name: 'Containers', level: 1 })).toBeVisible();
await expect(page.getByRole('button', { name: 'Sign in to Arcane' })).not.toBeVisible();
@@ -140,7 +140,7 @@ test.describe('Token refresh behaviour', () => {
await page.context().clearCookies();
await page.goto('/dashboard');
await page.waitForURL(/\/login/, { timeout: 10_000 });
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page).toHaveURL(/\/login/);
await expect(
page.getByRole('button', { name: 'Sign in to Arcane', exact: true })
diff --git a/tests/spec/volumes.spec.ts b/tests/spec/volumes.spec.ts
index 2ff8ce39f..9d066e4bc 100644
--- a/tests/spec/volumes.spec.ts
+++ b/tests/spec/volumes.spec.ts
@@ -11,7 +11,7 @@ test.beforeEach(async ({ page }) => {
async function openCreateVolumeSheet(page: Page) {
await page.goto('/volumes');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByRole('heading', { name: 'Volumes', level: 1 })).toBeVisible();
const createButton = page.getByRole('button', { name: 'Create Volume' }).first();
@@ -30,46 +30,46 @@ async function openCreateVolumeSheet(page: Page) {
async function createVolumeViaUI(page: Page, volumeName: string) {
await openCreateVolumeSheet(page);
await page.getByRole('dialog').locator('input[type="text"]').first().fill(volumeName);
+ const createRequest = page.waitForResponse(
+ (response) => {
+ const request = response.request();
+ return (
+ request.method() === 'POST' &&
+ /\/api\/environments\/[^/]+\/volumes$/.test(new URL(response.url()).pathname)
+ );
+ },
+ { timeout: 15000 }
+ );
await page.getByRole('dialog').getByRole('button', { name: 'Create Volume' }).click();
+ const createResponse = await createRequest;
+ if (!createResponse.ok()) {
+ throw new Error(
+ `Failed to create volume ${volumeName}: ${createResponse.status()} ${await createResponse.text()}`
+ );
+ }
await expect(
page.locator('li[data-sonner-toast][data-type="success"] div[data-title]')
).toBeVisible();
}
-async function findVolumeRow(page: Page, volumeName: string, maxRetries = 10) {
- for (let i = 0; i < maxRetries; i++) {
- const searchInput = page.getByPlaceholder(/Search/i).first();
- if (await searchInput.isVisible().catch(() => false)) {
- await searchInput.fill(volumeName);
+async function createVolumeViaApi(page: Page, volumeName: string) {
+ const response = await page.request.post('/api/environments/0/volumes', {
+ data: {
+ name: volumeName,
+ driver: 'local'
}
-
- const row = page.locator('tbody tr').filter({ hasText: volumeName }).first();
- if (await row.isVisible().catch(() => false)) return row;
- await page.waitForTimeout(500);
- await page.goto('/volumes');
- await page.waitForLoadState('networkidle');
+ });
+ if (!response.ok()) {
+ throw new Error(
+ `Failed to create volume ${volumeName}: ${response.status()} ${await response.text()}`
+ );
}
- return page.locator('tbody tr').filter({ hasText: volumeName }).first();
}
-async function removeVolumeViaUI(page: Page, volumeName: string) {
- if (page.isClosed()) {
- return;
- }
-
- await page.goto('/volumes');
- await page.waitForLoadState('networkidle');
-
- const row = await findVolumeRow(page, volumeName, 4);
- if (!(await row.isVisible().catch(() => false))) return;
-
- await row.locator('a[href*="/volumes/"]').first().click();
- await expect(page).toHaveURL(/\/volumes\/.+/);
- await page.locator('button[data-slot="arcane-button"][data-action="remove"]').click();
- await page.getByRole('button', { name: 'Remove', exact: true }).last().click();
- await expect(
- page.locator('li[data-sonner-toast][data-type="success"] div[data-title]')
- ).toBeVisible();
+async function removeVolumeViaApi(page: Page, volumeName: string) {
+ await page.request
+ .delete(`/api/environments/0/volumes/${encodeURIComponent(volumeName)}`)
+ .catch(() => undefined);
}
function facetIds(title: string) {
@@ -102,7 +102,7 @@ test.describe('Volumes Page', () => {
test('Correct Volume Stat Card Counts', async ({ page }) => {
await page.goto('/volumes');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
await expect(page.getByText(`${volumeCount.total} Total Volumes`)).toBeVisible();
});
@@ -114,7 +114,7 @@ test.describe('Volumes Page', () => {
test('Display Volume Filters', async ({ page }) => {
await page.goto('/volumes');
- await page.waitForLoadState('networkidle');
+ await page.waitForLoadState('load');
const { content } = await ensureFacetOpen(page, 'Usage');
await expect(content.getByRole('option', { name: /In Use\b/i })).toBeVisible();
@@ -125,30 +125,23 @@ test.describe('Volumes Page', () => {
const volumeName = `e2e-inspect-volume-${Date.now()}`;
try {
- await createVolumeViaUI(page, volumeName);
- await page.goto('/volumes');
- await page.waitForLoadState('networkidle');
-
- const row = await findVolumeRow(page, volumeName);
- await expect(row).toBeVisible();
- await row.locator('a[href*="/volumes/"]').first().click();
+ await createVolumeViaApi(page, volumeName);
+ await page.goto(`/volumes/${encodeURIComponent(volumeName)}`);
+ await page.waitForLoadState('load');
await expect(page).toHaveURL(new RegExp(`/volumes/.+`));
await expect(page.getByRole('heading', { level: 1, name: volumeName })).toBeVisible();
} finally {
- await removeVolumeViaUI(page, volumeName);
+ await removeVolumeViaApi(page, volumeName);
}
});
test('Remove Volume', async ({ page }) => {
const volumeName = `test-remove-volume-${Date.now()}`;
- await createVolumeViaUI(page, volumeName);
- await page.goto('/volumes');
- await page.waitForLoadState('networkidle');
+ await createVolumeViaApi(page, volumeName);
+ await page.goto(`/volumes/${encodeURIComponent(volumeName)}`);
+ await page.waitForLoadState('load');
- const row = await findVolumeRow(page, volumeName);
- await expect(row).toBeVisible();
- await row.locator('a[href*="/volumes/"]').first().click();
await expect(page).toHaveURL(new RegExp(`/volumes/.+`));
await page.locator('button[data-slot="arcane-button"][data-action="remove"]').click();
await page.getByRole('button', { name: 'Remove', exact: true }).last().click();
@@ -162,25 +155,25 @@ test.describe('Volumes Page', () => {
const volumeName = `test-volume-${Date.now()}`;
try {
await createVolumeViaUI(page, volumeName);
- await page.goto('/volumes');
- await expect(await findVolumeRow(page, volumeName)).toBeVisible();
+ const response = await page.request.get(
+ `/api/environments/0/volumes/${encodeURIComponent(volumeName)}`
+ );
+ expect(response.ok()).toBe(true);
} finally {
- await removeVolumeViaUI(page, volumeName);
+ await removeVolumeViaApi(page, volumeName);
}
});
test('Display correct volume usage badge', async ({ page }) => {
const volumeName = `e2e-badge-volume-${Date.now()}`;
try {
- await createVolumeViaUI(page, volumeName);
- await page.goto('/volumes');
- await page.waitForLoadState('networkidle');
+ await createVolumeViaApi(page, volumeName);
+ await page.goto(`/volumes/${encodeURIComponent(volumeName)}`);
+ await page.waitForLoadState('load');
- const row = await findVolumeRow(page, volumeName);
- await expect(row).toBeVisible();
- await expect(row.getByText('Unused')).toBeVisible();
+ await expect(page.getByText('Unused').first()).toBeVisible();
} finally {
- await removeVolumeViaUI(page, volumeName);
+ await removeVolumeViaApi(page, volumeName);
}
});
});
diff --git a/types/activity/activity.go b/types/activity/activity.go
new file mode 100644
index 000000000..ff7f32b86
--- /dev/null
+++ b/types/activity/activity.go
@@ -0,0 +1,102 @@
+package activity
+
+import "time"
+
+type Status string
+
+const (
+ StatusQueued Status = "queued"
+ StatusRunning Status = "running"
+ StatusSuccess Status = "success"
+ StatusFailed Status = "failed"
+ StatusCancelled Status = "cancelled"
+)
+
+type Type string
+
+const (
+ TypeImagePull Type = "image_pull"
+ TypeImageBuild Type = "image_build"
+ TypeImageUpdateCheck Type = "image_update_check"
+ TypeProjectPull Type = "project_pull"
+ TypeProjectBuild Type = "project_build"
+ TypeProjectDeploy Type = "project_deploy"
+ TypeProjectRedeploy Type = "project_redeploy"
+ TypeProjectDown Type = "project_down"
+ TypeProjectRestart Type = "project_restart"
+ TypeProjectDestroy Type = "project_destroy"
+ TypeContainerStart Type = "container_start"
+ TypeContainerStop Type = "container_stop"
+ TypeContainerRestart Type = "container_restart"
+ TypeContainerRedeploy Type = "container_redeploy"
+ TypeContainerDelete Type = "container_delete"
+ TypeVulnerabilityScan Type = "vulnerability_scan"
+ TypeAutoUpdate Type = "auto_update"
+ TypeSystemPrune Type = "system_prune"
+ TypeResourceAction Type = "resource_action"
+)
+
+type MessageLevel string
+
+const (
+ MessageLevelInfo MessageLevel = "info"
+ MessageLevelWarning MessageLevel = "warning"
+ MessageLevelError MessageLevel = "error"
+ MessageLevelSuccess MessageLevel = "success"
+)
+
+type Activity struct {
+ ID string `json:"id"`
+ EnvironmentID string `json:"environmentId"`
+ SourceEnvironmentID string `json:"sourceEnvironmentId,omitempty"`
+ SourceEnvironmentName string `json:"sourceEnvironmentName,omitempty"`
+ Type Type `json:"type"`
+ Status Status `json:"status"`
+ ResourceType *string `json:"resourceType,omitempty"`
+ ResourceID *string `json:"resourceId,omitempty"`
+ ResourceName *string `json:"resourceName,omitempty"`
+ Progress *int `json:"progress,omitempty"`
+ Step string `json:"step,omitempty"`
+ LatestMessage string `json:"latestMessage,omitempty"`
+ StartedBy *StartedBy `json:"startedBy,omitempty"`
+ StartedAt time.Time `json:"startedAt"`
+ EndedAt *time.Time `json:"endedAt,omitempty"`
+ DurationMs *int64 `json:"durationMs,omitempty"`
+ Error *string `json:"error,omitempty"`
+ Metadata map[string]any `json:"metadata,omitempty"`
+ CreatedAt time.Time `json:"createdAt"`
+ UpdatedAt *time.Time `json:"updatedAt,omitempty"`
+}
+
+type StartedBy struct {
+ UserID string `json:"userId,omitempty"`
+ Username string `json:"username"`
+ DisplayName string `json:"displayName,omitempty"`
+}
+
+type Message struct {
+ ID string `json:"id"`
+ ActivityID string `json:"activityId"`
+ Level MessageLevel `json:"level"`
+ Message string `json:"message"`
+ Payload map[string]any `json:"payload,omitempty"`
+ CreatedAt time.Time `json:"createdAt"`
+}
+
+type Detail struct {
+ Activity Activity `json:"activity"`
+ Messages []Message `json:"messages"`
+}
+
+type StreamEvent struct {
+ Type string `json:"type"`
+ ActivityID string `json:"activityId,omitempty"`
+ Activity *Activity `json:"activity,omitempty"`
+ Activities []Activity `json:"activities,omitempty"`
+ Message *Message `json:"message,omitempty"`
+ Timestamp time.Time `json:"timestamp"`
+}
+
+type ClearHistoryResult struct {
+ Deleted int64 `json:"deleted"`
+}
diff --git a/types/base/response.go b/types/base/response.go
index 499801861..bfdeee8b0 100644
--- a/types/base/response.go
+++ b/types/base/response.go
@@ -7,7 +7,8 @@ type ErrorResponse struct {
// MessageResponse represents a simple message response.
type MessageResponse struct {
- Message string `json:"message" doc:"Response message"`
+ Message string `json:"message" doc:"Response message"`
+ ActivityID *string `json:"activityId,omitempty" doc:"Background activity ID tracking this action"`
}
// PaginationResponse contains pagination metadata.
diff --git a/types/container/container.go b/types/container/container.go
index 55452116e..a86bab3eb 100644
--- a/types/container/container.go
+++ b/types/container/container.go
@@ -319,6 +319,11 @@ type ActionResult struct {
//
// Required: false
Errors []string `json:"errors,omitempty"`
+
+ // ActivityID is the background activity that tracked this action.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
// Port represents a port binding for a container.
@@ -836,6 +841,11 @@ type Details struct {
//
// Required: false
RedeployDisabled bool `json:"redeployDisabled,omitempty"`
+
+ // ActivityID is the background activity that tracked the action returning these details.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
// Created represents a newly created container.
diff --git a/types/imageupdate/image_update.go b/types/imageupdate/image_update.go
index 94ca0808b..1639f1f66 100644
--- a/types/imageupdate/image_update.go
+++ b/types/imageupdate/image_update.go
@@ -71,6 +71,11 @@ type Response struct {
//
// Required: false
UsedCredential bool `json:"usedCredential,omitempty"`
+
+ // ActivityID is the background activity that tracked this check.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
type Summary struct {
diff --git a/types/network/network.go b/types/network/network.go
index 17c1a129c..eb2c69f0b 100644
--- a/types/network/network.go
+++ b/types/network/network.go
@@ -200,6 +200,11 @@ type CreateResponse struct {
//
// Required: false
Warning string `json:"warning,omitempty"`
+
+ // ActivityID is the activity created by the network creation action.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
// CreateRequest contains the parameters for creating a network.
@@ -369,6 +374,11 @@ type PruneReport struct {
//
// Required: true
SpaceReclaimed uint64 `json:"spaceReclaimed"`
+
+ // ActivityID is the activity created by the prune action.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
// NewSummary creates a Summary from a docker network.Summary, calculating InUse and IsDefault fields.
diff --git a/types/project/project.go b/types/project/project.go
index a0aefe1cd..c72f86620 100644
--- a/types/project/project.go
+++ b/types/project/project.go
@@ -300,6 +300,11 @@ type CreateReponse struct {
//
// Required: true
UpdatedAt string `json:"updatedAt"`
+
+ // ActivityID is the activity created by the project action.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
// Details contains detailed information about a project.
@@ -449,6 +454,11 @@ type Details struct {
//
// Required: false
GitRepositoryURL string `json:"gitRepositoryURL,omitempty"`
+
+ // ActivityID is the activity created by the project action.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
// Destroy is used to destroy a project.
diff --git a/types/settings/settings.go b/types/settings/settings.go
index 051ac3f65..c3ded857f 100644
--- a/types/settings/settings.go
+++ b/types/settings/settings.go
@@ -94,6 +94,16 @@ type Update struct {
// Required: false
EnvironmentHealthInterval *string `json:"environmentHealthInterval,omitempty"`
+ // ActivityHistoryRetentionDays is the number of days of completed Activity Center history to retain.
+ //
+ // Required: false
+ ActivityHistoryRetentionDays *string `json:"activityHistoryRetentionDays,omitempty"`
+
+ // ActivityHistoryMaxEntries is the maximum completed Activity Center entries to retain per environment.
+ //
+ // Required: false
+ ActivityHistoryMaxEntries *string `json:"activityHistoryMaxEntries,omitempty"`
+
// DefaultDeployPullPolicy is the default image pull policy used for project deploys.
//
// Required: false
diff --git a/types/system/prune.go b/types/system/prune.go
index 630d8b938..b86858f39 100644
--- a/types/system/prune.go
+++ b/types/system/prune.go
@@ -295,4 +295,9 @@ type PruneAllResult struct {
//
// Required: false
Errors []string `json:"errors,omitempty"`
+
+ // ActivityID is the background activity that tracked this prune operation.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
diff --git a/types/updater/updater.go b/types/updater/updater.go
index 4064dc6ca..e8ee23443 100644
--- a/types/updater/updater.go
+++ b/types/updater/updater.go
@@ -113,6 +113,11 @@ type Result struct {
//
// Required: true
Items []ResourceResult `json:"items"`
+
+ // ActivityID is the background activity that tracked this update operation.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
// Status represents the current status of the updater.
diff --git a/types/volume/volume.go b/types/volume/volume.go
index a2eec2400..5c038364b 100644
--- a/types/volume/volume.go
+++ b/types/volume/volume.go
@@ -63,6 +63,11 @@ type Volume struct {
//
// Required: true
Containers []string `json:"containers"`
+
+ // ActivityID is the activity created by a mutating volume action.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
// UsageCounts contains counts of volumes by usage status.
@@ -94,6 +99,11 @@ type PruneReport struct {
//
// Required: true
SpaceReclaimed uint64 `json:"spaceReclaimed"`
+
+ // ActivityID is the activity created by the prune action.
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
}
// Create is used to create a new volume.
diff --git a/types/vulnerability/vulnerability.go b/types/vulnerability/vulnerability.go
index b916f445e..1c3d68de8 100644
--- a/types/vulnerability/vulnerability.go
+++ b/types/vulnerability/vulnerability.go
@@ -184,6 +184,11 @@ type ScanResult struct {
// Required: true
Status ScanStatus `json:"status"`
+ // ActivityID is the background activity tracking this scan, if available
+ //
+ // Required: false
+ ActivityID *string `json:"activityId,omitempty"`
+
// ScanPhase is the current phase of a running scan
// (e.g. creating_container, scanning_image, storing_results).
//