Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix(environments): surface sync failures and track manual sync as an activity (#3854)
Kyle Mendellc6ad1016d913
diff --git a/backend/api/api.go b/backend/api/api.goindex 494a30b42..88005123b 100644--- a/backend/api/api.go+++ b/backend/api/api.go@@ -418,7 +418,7 @@ func registerHandlersInternal(api huma.API, deps HandlerDeps, handlerAppCtx handdeps.Event.RegisterRoutes(api)deps.Activity.RegisterRoutes(api)oidc.RegisterOidc(api, deps.Auth.Service(), deps.Passkey, deps.Oidc, deps.Role.Service(), deps.User.Service(), cfg)- deps.Environment.RegisterRoutes(api)+ deps.Environment.RegisterRoutes(api, handlerAppCtx)deps.ContainerRegistry.RegisterRoutes(api)deps.Template.RegisterRoutes(api)deps.Variable.RegisterRoutes(api, cfg)diff --git a/backend/internal/di/providers.go b/backend/internal/di/providers.goindex 273a5b4fb..e7bc9ad78 100644--- a/backend/internal/di/providers.go+++ b/backend/internal/di/providers.go@@ -84,12 +84,13 @@ func provideActivityServiceInternal(module *activity.Module) *activity.ActivitySreturn module.Service()}-func provideEnvironmentModuleInternal(service *environment.EnvironmentService, settingsService *settings.SettingsService, apiKey *apikey.ApiKeyService, eventService *event.EventService, cfg *config.Config) *environment.Module {+func provideEnvironmentModuleInternal(service *environment.EnvironmentService, settingsService *settings.SettingsService, apiKey *apikey.ApiKeyService, eventService *event.EventService, cfg *config.Config, activityService *activity.ActivityService) *environment.Module {return environment.New(service, environment.Dependencies{Settings: settingsService,ApiKey: apiKey,Event: eventService,Config: cfg,+ Activity: activityService,})}diff --git a/backend/internal/environment/environment.go b/backend/internal/environment/environment.goindex 1232189d2..0030f8075 100644--- a/backend/internal/environment/environment.go+++ b/backend/internal/environment/environment.go@@ -14,14 +14,17 @@ import ("emperror.dev/errors""github.com/getarcaneapp/arcane/backend/v2/internal/apikey"+ "github.com/getarcaneapp/arcane/backend/v2/internal/common""github.com/getarcaneapp/arcane/backend/v2/internal/database""github.com/getarcaneapp/arcane/backend/v2/internal/docker""github.com/getarcaneapp/arcane/backend/v2/internal/event""github.com/getarcaneapp/arcane/backend/v2/internal/settings"+ activitylib "github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/activity""github.com/getarcaneapp/arcane/backend/v2/pkg/remenv""github.com/getarcaneapp/arcane/backend/v2/pkg/scheduler/entityjobs"httputils "github.com/getarcaneapp/arcane/backend/v2/pkg/utils/httpx""github.com/getarcaneapp/arcane/backend/v2/pkg/utils/validation"+ activitytypes "github.com/getarcaneapp/arcane/types/v2/activity""github.com/getarcaneapp/arcane/types/v2/containerregistry""go.getarcane.app/sys/crypto""gorm.io/gorm"@@ -481,3 +484,42 @@ func (s *EnvironmentService) GetEnabledRegistryCredentials(ctx context.Context)return creds, nil}++// SyncResourcesToEnvironment tracks a manual sync and attempts every resource group.+func (s *EnvironmentService) SyncResourcesToEnvironment(ctx context.Context, environmentID string, user *common.User, activityService activitylib.Service) (string, error) {+ return activitylib.RunHandlerActivity(ctx, activityService, activitylib.HandlerOptions{+ EnvironmentID: environmentID,+ Type: activitytypes.TypeResourceAction,+ ResourceType: "environment",+ ResourceID: environmentID,+ ResourceName: environmentID,+ User: user,+ Step: "Syncing environment",+ Message: "Syncing container registries, S3 destinations, and git repositories",+ SuccessMessage: "Environment synced successfully",+ Metadata: database.JSON{"action": "sync_environment"},+ }, func(ctx context.Context) error {+ var failedGroups []string++ if err := s.SyncRegistriesToEnvironment(ctx, environmentID); err != nil {+ slog.WarnContext(ctx, "Failed to sync registries", "environmentID", environmentID, "error", err.Error())+ failedGroups = append(failedGroups, "container registries")+ }++ if err := s.SyncS3DestinationsToEnvironment(ctx, environmentID); err != nil {+ slog.WarnContext(ctx, "Failed to sync S3 destinations", "environmentID", environmentID, "error", err.Error())+ failedGroups = append(failedGroups, "S3 destinations")+ }++ if err := s.SyncRepositoriesToEnvironment(ctx, environmentID); err != nil {+ slog.WarnContext(ctx, "Failed to sync git repositories", "environmentID", environmentID, "error", err.Error())+ failedGroups = append(failedGroups, "git repositories")+ }++ if len(failedGroups) > 0 {+ return errors.New("Failed to sync " + strings.Join(failedGroups, ", ") + ". Other resource groups may have synced successfully. Check the manager logs, correct the failed sync, and retry.")+ }++ return nil+ })+}diff --git a/backend/internal/environment/environment_proxy.go b/backend/internal/environment/environment_proxy.goindex b3965f5cd..b8fa38ed9 100644--- a/backend/internal/environment/environment_proxy.go+++ b/backend/internal/environment/environment_proxy.go@@ -6,6 +6,7 @@ import ("context""encoding/json/v2"+ "fmt""log/slog""maps""net/http"@@ -336,7 +337,7 @@ func doRemoteEnvironmentTunnelRequestInternal(// SyncRegistriesToEnvironment syncs all registries from this manager to a remote environmentfunc (s *EnvironmentService) SyncRegistriesToEnvironment(ctx context.Context, environmentID string) error {return s.fanOutSyncToEnvironment(ctx, environmentID, "registries", "/api/container-registries/sync",- func(ctx context.Context, reg registry.ContainerRegistry) (containerregistry.Sync, bool, error) {+ func(reg registry.ContainerRegistry) (containerregistry.Sync, bool, error) {registryType, typeErr := registry.NormalizeRegistryType(reg.RegistryType)if typeErr != nil {return containerregistry.Sync{}, false, errors.WrapIff(typeErr, "normalize registry type for sync %s", reg.ID)@@ -357,8 +358,7 @@ func (s *EnvironmentService) SyncRegistriesToEnvironment(ctx context.Context, enif registryType == registry.RegistryTypeECR {decryptedSecret, err := crypto.Decrypt(reg.AWSSecretAccessKey)if err != nil {- slog.WarnContext(ctx, "Failed to decrypt ECR secret for sync", "registryID", reg.ID, "registryURL", reg.URL, "error", err.Error())- return containerregistry.Sync{}, false, nil+ return containerregistry.Sync{}, false, fmt.Errorf("failed to decrypt ECR secret for registry %s for sync: %w", reg.ID, err)}syncItem.AWSAccessKeyID = reg.AWSAccessKeyID@@ -367,8 +367,7 @@ func (s *EnvironmentService) SyncRegistriesToEnvironment(ctx context.Context, en} else {decryptedToken, err := crypto.Decrypt(reg.Token)if err != nil {- slog.WarnContext(ctx, "Failed to decrypt registry token for sync", "registryID", reg.ID, "registryURL", reg.URL, "error", err.Error())- return containerregistry.Sync{}, false, nil+ return containerregistry.Sync{}, false, fmt.Errorf("failed to decrypt token for registry %s for sync: %w", reg.ID, err)}syncItem.Username = reg.Username@@ -386,7 +385,7 @@ func (s *EnvironmentService) SyncRegistriesToEnvironment(ctx context.Context, en// SyncS3DestinationsToEnvironment sends manager-owned destinations to one remote environment.func (s *EnvironmentService) SyncS3DestinationsToEnvironment(ctx context.Context, environmentID string) error {return s.fanOutSyncToEnvironment(ctx, environmentID, "S3 destinations", "/api/backups/s3/sync",- func(_ context.Context, destination s3domain.S3Destination) (backuptypes.S3DestinationSync, bool, error) {+ func(destination s3domain.S3Destination) (backuptypes.S3DestinationSync, bool, error) {secret, err := crypto.Decrypt(destination.SecretAccessKey)if err != nil {return backuptypes.S3DestinationSync{}, false, errors.WrapIff(err, "failed to decrypt S3 destination %s for sync", destination.ID)@@ -402,7 +401,7 @@ func (s *EnvironmentService) SyncS3DestinationsToEnvironment(ctx context.Context// SyncRepositoriesToEnvironment syncs all git repositories from this manager to a remote environmentfunc (s *EnvironmentService) SyncRepositoriesToEnvironment(ctx context.Context, environmentID string) error {return s.fanOutSyncToEnvironment(ctx, environmentID, "git repositories", "/api/git-repositories/sync",- func(ctx context.Context, repo gitrepo.GitRepository) (gitops.RepositorySync, bool, error) {+ func(repo gitrepo.GitRepository) (gitops.RepositorySync, bool, error) {item := gitops.RepositorySync{ID: repo.ID,Name: repo.Name,@@ -420,8 +419,7 @@ func (s *EnvironmentService) SyncRepositoriesToEnvironment(ctx context.Context,if repo.Token != "" {decryptedToken, err := crypto.Decrypt(repo.Token)if err != nil {- slog.WarnContext(ctx, "Failed to decrypt repository token for sync", "repositoryID", repo.ID, "repositoryName", repo.Name, "error", err.Error())- return gitops.RepositorySync{}, false, nil+ return gitops.RepositorySync{}, false, fmt.Errorf("failed to decrypt token for repository %s for sync: %w", repo.ID, err)}item.Token = decryptedToken}@@ -429,8 +427,7 @@ func (s *EnvironmentService) SyncRepositoriesToEnvironment(ctx context.Context,if repo.SSHKey != "" {decryptedSSHKey, err := crypto.Decrypt(repo.SSHKey)if err != nil {- slog.WarnContext(ctx, "Failed to decrypt repository SSH key for sync", "repositoryID", repo.ID, "repositoryName", repo.Name, "error", err.Error())- return gitops.RepositorySync{}, false, nil+ return gitops.RepositorySync{}, false, fmt.Errorf("failed to decrypt SSH key for repository %s for sync: %w", repo.ID, err)}item.SSHKey = decryptedSSHKey}@@ -445,15 +442,14 @@ func (s *EnvironmentService) SyncRepositoriesToEnvironment(ctx context.Context,// fanOutSyncToEnvironment pushes every row of Model held by this// manager to one remote environment. toSyncItem maps a row to its wire form and-// reports whether to keep it — rows whose credentials fail to decrypt are-// skipped rather than failing the whole batch — and wrap builds the request-// envelope the target endpoint expects.+// reports whether to keep it. Mapping errors abort before sending the snapshot.+// wrap builds the request envelope the target endpoint expects.func (s *EnvironmentService) fanOutSyncToEnvironment[Model any, Item any, Request any](ctx context.Context,environmentID string,kind string,path string,- toSyncItem func(context.Context, Model) (Item, bool, error),+ toSyncItem func(Model) (Item, bool, error),wrap func([]Item) Request,) error {target, err := s.resolveRemoteEnvironmentTargetInternal(ctx, environmentID)@@ -470,7 +466,7 @@ func (s *EnvironmentService) fanOutSyncToEnvironment[Model any, Item any, RequessyncItems := make([]Item, 0, len(records))for _, record := range records {- item, keep, err := toSyncItem(ctx, record)+ item, keep, err := toSyncItem(record)if err != nil {return err}diff --git a/backend/internal/environment/environment_sync_test.go b/backend/internal/environment/environment_sync_test.gonew file mode 100644index 000000000..3613f71c0--- /dev/null+++ b/backend/internal/environment/environment_sync_test.go@@ -0,0 +1,172 @@+package environment_test++import (+ "context"+ "encoding/json"+ "errors"+ "net/http"+ "net/http/httptest"+ "path/filepath"+ "sync"+ "sync/atomic"+ "testing"++ "github.com/getarcaneapp/arcane/backend/v2/internal/activity"+ "github.com/getarcaneapp/arcane/backend/v2/internal/common"+ "github.com/getarcaneapp/arcane/backend/v2/internal/database"+ "github.com/getarcaneapp/arcane/backend/v2/internal/environment"+ "github.com/getarcaneapp/arcane/backend/v2/internal/gitrepo"+ "github.com/getarcaneapp/arcane/backend/v2/internal/registry"+ s3domain "github.com/getarcaneapp/arcane/backend/v2/internal/s3"+ activitytypes "github.com/getarcaneapp/arcane/types/v2/activity"+ "github.com/getarcaneapp/arcane/types/v2/gitops"+ "github.com/libtnb/sqlite"+ "github.com/stretchr/testify/require"+ "go.getarcane.app/sys/crypto"+ "gorm.io/gorm"+)++func setupSyncDBInternal(t *testing.T) *database.DB {+ t.Helper()+ db, err := gorm.Open(sqlite.Open(filepath.Join(t.TempDir(), "sync.db")), &gorm.Config{})+ require.NoError(t, err)+ require.NoError(t, db.AutoMigrate(&environment.Environment{}, ®istry.ContainerRegistry{}, &gitrepo.GitRepository{}, &s3domain.S3Destination{}, &activity.Activity{}, &activity.ActivityMessage{}))+ sqlDB, err := db.DB()+ require.NoError(t, err)+ t.Cleanup(func() { require.NoError(t, sqlDB.Close()) })+ crypto.InitEncryption(&crypto.Config{EncryptionKey: "test-encryption-key-for-testing-32bytes-min", Environment: "test"})+ return &database.DB{DB: db}+}++func TestSyncResourcesToEnvironmentOutcomes(t *testing.T) {+ paths := []string{"/api/container-registries/sync", "/api/backups/s3/sync", "/api/git-repositories/sync"}+ cases := []struct {+ name string+ failures map[string]string+ groups string+ }{+ {name: "success"},+ {name: "registry failure", failures: map[string]string{paths[0]: "status"}, groups: "container registries"},+ {name: "S3 failure", failures: map[string]string{paths[1]: "status"}, groups: "S3 destinations"},+ {name: "repository failure", failures: map[string]string{paths[2]: "status"}, groups: "git repositories"},+ {name: "multiple failures", failures: map[string]string{paths[0]: "status", paths[2]: "status"}, groups: "container registries, git repositories"},+ {name: "all fail", failures: map[string]string{paths[0]: "status", paths[1]: "status", paths[2]: "status"}, groups: "container registries, S3 destinations, git repositories"},+ {name: "malformed response", failures: map[string]string{paths[0]: "malformed"}, groups: "container registries"},+ {name: "agent reports failure", failures: map[string]string{paths[0]: "false"}, groups: "container registries"},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ db := setupSyncDBInternal(t)+ var mu sync.Mutex+ var calls []string+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ mu.Lock()+ calls = append(calls, r.URL.Path)+ mu.Unlock()+ switch tc.failures[r.URL.Path] {+ case "status":+ http.Error(w, "private-agent-response", http.StatusUnauthorized)+ case "malformed":+ _, _ = w.Write([]byte("private-agent-response"))+ case "false":+ _, _ = w.Write([]byte(`{"success":false,"data":{"message":"private-agent-response"}}`))+ default:+ _, _ = w.Write([]byte(`{"success":true}`))+ }+ }))+ defer server.Close()+ require.NoError(t, db.Create(&environment.Environment{BaseModel: database.BaseModel{ID: "remote"}, Name: "Remote", ApiUrl: server.URL, AccessToken: new("agent-token"), Enabled: true}).Error)+ service := environment.NewEnvironmentService(db, server.Client(), nil, nil, nil, nil)+ activityService := activity.NewActivityService(db, nil)+ id, err := service.SyncResourcesToEnvironment(t.Context(), "remote", &common.User{ID: "operator", Username: "operator"}, activityService)+ require.NotEmpty(t, id)+ var recorded activity.Activity+ require.NoError(t, db.First(&recorded, "id = ?", id).Error)+ require.NotNil(t, recorded.EndedAt)+ require.NotNil(t, recorded.DurationMs)+ require.Equal(t, "remote", recorded.EnvironmentID)+ if tc.groups == "" {+ require.NoError(t, err)+ require.Equal(t, activitytypes.StatusSuccess, recorded.Status)+ require.Equal(t, "Environment synced successfully", recorded.LatestMessage)+ require.Nil(t, recorded.Error)+ } else {+ require.EqualError(t, err, "Failed to sync "+tc.groups+". Other resource groups may have synced successfully. Check the manager logs, correct the failed sync, and retry.")+ require.Equal(t, activitytypes.StatusFailed, recorded.Status)+ require.NotNil(t, recorded.Error)+ require.Equal(t, err.Error(), *recorded.Error)+ require.Equal(t, err.Error(), recorded.LatestMessage)+ require.NotContains(t, err.Error(), "private-agent-response")+ require.NotContains(t, err.Error(), "agent-token")+ }+ mu.Lock()+ defer mu.Unlock()+ require.Equal(t, paths, calls)+ })+ }+}++func TestSyncCredentialDecryptionAbortsSnapshot(t *testing.T) {+ for _, kind := range []string{"registry token", "ECR secret", "repository token", "repository SSH key", "S3 secret"} {+ t.Run(kind, func(t *testing.T) {+ db := setupSyncDBInternal(t)+ var calls atomic.Int32+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ calls.Add(1)+ _, _ = w.Write([]byte(`{"success":true}`))+ }))+ defer server.Close()+ require.NoError(t, db.Create(&environment.Environment{BaseModel: database.BaseModel{ID: "remote"}, ApiUrl: server.URL, AccessToken: new("agent-token")}).Error)+ service := environment.NewEnvironmentService(db, server.Client(), nil, nil, nil, nil)+ var syncResource func(context.Context, string) error+ switch kind {+ case "registry token", "ECR secret":+ row := registry.ContainerRegistry{BaseModel: database.BaseModel{ID: "bad-credential"}, URL: "registry.example.com", RegistryType: registry.RegistryTypeGeneric, Token: "invalid-ciphertext"}+ if kind == "ECR secret" {+ row.RegistryType = registry.RegistryTypeECR+ row.AWSSecretAccessKey = "invalid-ciphertext"+ }+ require.NoError(t, db.Create(&row).Error)+ syncResource = service.SyncRegistriesToEnvironment+ case "repository token", "repository SSH key":+ row := gitrepo.GitRepository{BaseModel: database.BaseModel{ID: "bad-credential"}, Name: "Repository", URL: "https://example.com/repo.git"}+ if kind == "repository token" {+ row.Token = "invalid-ciphertext"+ } else {+ row.SSHKey = "invalid-ciphertext"+ }+ require.NoError(t, db.Create(&row).Error)+ syncResource = service.SyncRepositoriesToEnvironment+ case "S3 secret":+ require.NoError(t, db.Create(&s3domain.S3Destination{BaseModel: database.BaseModel{ID: "bad-credential"}, Name: "Backup", SecretAccessKey: "invalid-ciphertext"}).Error)+ syncResource = service.SyncS3DestinationsToEnvironment+ }+ err := syncResource(t.Context(), "remote")+ require.Error(t, err)+ require.Contains(t, err.Error(), "bad-credential")+ require.NotNil(t, errors.Unwrap(err))+ require.Zero(t, calls.Load(), "an incomplete snapshot must never reach the agent")+ })+ }+}++func TestSyncRepositoriesPreservesEmptyCredentials(t *testing.T) {+ db := setupSyncDBInternal(t)+ require.NoError(t, db.Create(&gitrepo.GitRepository{BaseModel: database.BaseModel{ID: "public-repo"}, Name: "Public", URL: "https://example.com/public.git", AuthType: "none"}).Error)+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ var payload gitops.RepositorySyncRequest+ if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {+ t.Error(err)+ w.WriteHeader(http.StatusBadRequest)+ return+ }+ if rows := payload.Repositories; len(rows) != 1 || rows[0].ID != "public-repo" {+ t.Errorf("missing public repository: %v", payload)+ }+ _, _ = w.Write([]byte(`{"success":true}`))+ }))+ defer server.Close()+ require.NoError(t, db.Create(&environment.Environment{BaseModel: database.BaseModel{ID: "remote"}, ApiUrl: server.URL, AccessToken: new("token")}).Error)+ service := environment.NewEnvironmentService(db, server.Client(), nil, nil, nil, nil)+ require.NoError(t, service.SyncRepositoriesToEnvironment(t.Context(), "remote"))+}diff --git a/backend/internal/environment/handler.go b/backend/internal/environment/handler.goindex adc21fd64..2dbe287ad 100644--- a/backend/internal/environment/handler.go+++ b/backend/internal/environment/handler.go@@ -27,6 +27,7 @@ import ("github.com/getarcaneapp/arcane/backend/v2/internal/middleware""github.com/getarcaneapp/arcane/backend/v2/internal/settings""github.com/getarcaneapp/arcane/backend/v2/pkg/authz"+ activitylib "github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/activity""github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/edge""github.com/getarcaneapp/arcane/backend/v2/pkg/utils""github.com/getarcaneapp/arcane/backend/v2/pkg/utils/handlerutil"@@ -35,6 +36,7 @@ import ("github.com/getarcaneapp/arcane/types/v2/base""github.com/getarcaneapp/arcane/types/v2/environment""github.com/getarcaneapp/arcane/types/v2/version"+ "github.com/samber/mo""go.getarcane.app/streams/agg")@@ -56,6 +58,8 @@ type EnvironmentHandler struct {eventService *event.EventServicecfg *config.ConfigstreamHub *agg.Hub[[]environment.Environment]+ activityService activitylib.Service+ appCtx context.Context}// ============================================================================@@ -146,7 +150,7 @@ type DownloadEnvironmentMTLSFileInput struct {// ============================================================================// NewHandler builds the environment HTTP handler and its stream producer.-func NewHandler(environmentService *EnvironmentService, settingsService *settings.SettingsService, apiKeyService *apikey.ApiKeyService, eventService *event.EventService, cfg *config.Config) *EnvironmentHandler {+func NewHandler(environmentService *EnvironmentService, settingsService *settings.SettingsService, apiKeyService *apikey.ApiKeyService, eventService *event.EventService, cfg *config.Config, activityService activitylib.Service) *EnvironmentHandler {return &EnvironmentHandler{environmentService: environmentService,settingsService: settingsService,@@ -154,6 +158,7 @@ func NewHandler(environmentService *EnvironmentService, settingsService *settingeventService: eventService,cfg: cfg,streamHub: agg.NewHub[[]environment.Environment](),+ activityService: activityService,}}@@ -252,7 +257,7 @@ func RegisterEnvironments(api huma.API, h *EnvironmentHandler) {Method: "POST",Path: "/environments/{id}/sync",Summary: "Sync environment",- Description: "Sync container registries and git repositories to a remote environment",+ Description: "Sync container registries, S3 destinations, and git repositories to a remote environment. Returns an error if any resource group fails; other groups may still sync successfully.",Tags: []string{"Environments"},Security: handlerutil.DefaultOperationSecurity(),}, authz.PermEnvironmentsSync, h.SyncEnvironment)@@ -862,25 +867,23 @@ func (h *EnvironmentHandler) PairAgent(ctx context.Context, input *PairAgentInpu// SyncEnvironment syncs manager-owned resources to an environment.func (h *EnvironmentHandler) SyncEnvironment(ctx context.Context, input *SyncEnvironmentInput) (*handlerutil.Out[base.MessageResponse], error) {- // Sync registries- if err := h.environmentService.SyncRegistriesToEnvironment(ctx, input.ID); err != nil {- slog.WarnContext(ctx, "Failed to sync registries", "environmentID", input.ID, "error", err.Error())- }-- if err := h.environmentService.SyncS3DestinationsToEnvironment(ctx, input.ID); err != nil {- slog.WarnContext(ctx, "Failed to sync S3 destinations", "environmentID", input.ID, "error", err.Error())+ user, err := handlerutil.RequireUser(ctx)+ if err != nil {+ return nil, err}- // Sync git repositories- if err := h.environmentService.SyncRepositoriesToEnvironment(ctx, input.ID); err != nil {- slog.WarnContext(ctx, "Failed to sync git repositories", "environmentID", input.ID, "error", err.Error())+ runtimeCtx := utils.ActivityRuntimeContext(ctx, h.appCtx)+ activityID, err := h.environmentService.SyncResourcesToEnvironment(runtimeCtx, input.ID, user, h.activityService)+ if err != nil {+ return nil, huma.Error500InternalServerError(err.Error())}return &handlerutil.Out[base.MessageResponse]{Body: base.ApiResponse[base.MessageResponse]{Success: true,Data: base.MessageResponse{- Message: "Environment synced successfully",+ Message: "Environment synced successfully",+ ActivityID: mo.EmptyableToOption(strings.TrimSpace(activityID)).ToPointer(),},},}, nildiff --git a/backend/internal/environment/module.go b/backend/internal/environment/module.goindex bc56277b3..dcfb4e640 100644--- a/backend/internal/environment/module.go+++ b/backend/internal/environment/module.go@@ -9,6 +9,8 @@ import ("github.com/getarcaneapp/arcane/backend/v2/internal/config""github.com/getarcaneapp/arcane/backend/v2/internal/event""github.com/getarcaneapp/arcane/backend/v2/internal/settings"+ activitylib "github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/activity"+ "github.com/getarcaneapp/arcane/backend/v2/pkg/utils/handlerutil")type Dependencies struct {@@ -16,6 +18,7 @@ type Dependencies struct {ApiKey *apikey.ApiKeyServiceEvent *event.EventServiceConfig *config.Config+ Activity activitylib.Service}type Module struct {@@ -26,7 +29,7 @@ type Module struct {func New(service *EnvironmentService, deps Dependencies) *Module {return &Module{service: service,- handler: NewHandler(service, deps.Settings, deps.ApiKey, deps.Event, deps.Config),+ handler: NewHandler(service, deps.Settings, deps.ApiKey, deps.Event, deps.Config, deps.Activity),}}@@ -44,10 +47,11 @@ func (m *Module) Handler() *EnvironmentHandler {return m.handler}-func (m *Module) RegisterRoutes(api huma.API) {+func (m *Module) RegisterRoutes(api huma.API, appCtx handlerutil.ActivityAppContext) {if m == nil {- RegisterEnvironments(api, NewHandler(nil, nil, nil, nil, nil))+ RegisterEnvironments(api, NewHandler(nil, nil, nil, nil, nil, nil))return}+ m.handler.appCtx = appCtx.Context()RegisterEnvironments(api, m.handler)}