Skip to content

Modern Docker Management, Designed for Everyone

fear: add image polling job

Kyle Mendell51e365ebf4a2
diff --git a/backend/internal/bootstrap/jobs_bootstrap.go b/backend/internal/bootstrap/jobs_bootstrap.go
index 00231f211..8f3b3d1dc 100644
--- a/backend/internal/bootstrap/jobs_bootstrap.go
+++ b/backend/internal/bootstrap/jobs_bootstrap.go
@@ -28,4 +28,8 @@ func registerJobs(appCtx context.Context, scheduler *job.Scheduler, appServices
if err := job.RegisterFilesystemWatcherJob(appCtx, scheduler, appServices.Stack, appServices.Settings); err != nil {
slog.ErrorContext(appCtx, "Failed to register filesystem watcher job", slog.Any("error", err))
}
+
+ if err := job.RegisterImagePollingJob(appCtx, scheduler, appServices.ImageUpdate, appServices.Settings); err != nil {
+ slog.ErrorContext(appCtx, "Failed to register image polling job", slog.Any("error", err))
+ }
}
diff --git a/backend/internal/dto/settings_dto.go b/backend/internal/dto/settings_dto.go
index 9ea00e3ad..880c0f508 100644
--- a/backend/internal/dto/settings_dto.go
+++ b/backend/internal/dto/settings_dto.go
@@ -27,7 +27,6 @@ type UpdateSettingsDto struct {
AuthOidcEnabled *string `json:"authOidcEnabled,omitempty"`
AuthSessionTimeout *string `json:"authSessionTimeout,omitempty"`
AuthPasswordPolicy *string `json:"authPasswordPolicy,omitempty"`
- AuthRbacEnabled *string `json:"authRbacEnabled,omitempty"`
AuthOidcConfig *string `json:"authOidcConfig,omitempty"`
// Onboarding settings
diff --git a/backend/internal/job/image_polling_job.go b/backend/internal/job/image_polling_job.go
new file mode 100644
index 000000000..3656b0ff5
--- /dev/null
+++ b/backend/internal/job/image_polling_job.go
@@ -0,0 +1,102 @@
+package job
+
+import (
+ "context"
+ "log/slog"
+ "time"
+
+ "github.com/go-co-op/gocron/v2"
+ "github.com/ofkm/arcane-backend/internal/services"
+)
+
+type ImagePollingJob struct {
+ imageUpdateService *services.ImageUpdateService
+ settingsService *services.SettingsService
+}
+
+func NewImagePollingJob(imageUpdateService *services.ImageUpdateService, settingsService *services.SettingsService) *ImagePollingJob {
+ return &ImagePollingJob{
+ imageUpdateService: imageUpdateService,
+ settingsService: settingsService,
+ }
+}
+
+func RegisterImagePollingJob(ctx context.Context, scheduler *Scheduler, imageUpdateService *services.ImageUpdateService, settingsService *services.SettingsService) error {
+ pollingEnabled := settingsService.GetBoolSetting(ctx, "pollingEnabled", true)
+ pollingInterval := settingsService.GetIntSetting(ctx, "pollingInterval", 60)
+
+ if !pollingEnabled {
+ slog.InfoContext(ctx, "polling disabled; job not registered")
+ return nil
+ }
+
+ interval := time.Duration(pollingInterval) * time.Minute
+ if interval < 5*time.Minute {
+ slog.WarnContext(ctx, "polling interval too low; using default",
+ "requested_seconds", pollingInterval,
+ "effective_interval", "60m")
+ interval = 60 * time.Minute
+ }
+
+ slog.InfoContext(ctx, "registering image polling job", "interval", interval.String())
+
+ job := NewImagePollingJob(imageUpdateService, settingsService)
+ jobDefinition := gocron.DurationJob(interval)
+
+ return scheduler.RegisterJob(
+ ctx,
+ "ArcaneImagePolling",
+ jobDefinition,
+ job.Execute,
+ false,
+ )
+}
+
+func (j *ImagePollingJob) Execute(ctx context.Context) error {
+ slog.InfoContext(ctx, "image scan run started")
+
+ results, err := j.imageUpdateService.CheckAllImages(ctx, 0)
+ if err != nil {
+ slog.ErrorContext(ctx, "image scan failed", "err", err)
+ return err
+ }
+
+ total := len(results)
+ updates := 0
+ errors := 0
+ for _, r := range results {
+ if r == nil {
+ continue
+ }
+ if r.Error != "" {
+ errors++
+ continue
+ }
+ if r.HasUpdate {
+ updates++
+ }
+ }
+
+ slog.InfoContext(ctx, "image scan run completed",
+ "checked", total,
+ "updates", updates,
+ "errors", errors,
+ )
+
+ return nil
+}
+
+func UpdateImagePollingJobSchedule(ctx context.Context, scheduler *Scheduler, imageUpdateService *services.ImageUpdateService, settingsService *services.SettingsService) error {
+ pollingEnabled := settingsService.GetBoolSetting(ctx, "pollingEnabled", true)
+ pollingInterval := settingsService.GetIntSetting(ctx, "pollingInterval", 300)
+
+ if !pollingEnabled {
+ slog.InfoContext(ctx, "polling job disabled; job will be skipped")
+ return nil
+ }
+
+ interval := time.Duration(pollingInterval) * time.Second
+ slog.InfoContext(ctx, "polling settings changed", "interval", interval.String())
+
+ return nil
+}
diff --git a/backend/internal/middleware/auth_middleware.go b/backend/internal/middleware/auth_middleware.go
index 69569f41f..4dbdf1775 100644
--- a/backend/internal/middleware/auth_middleware.go
+++ b/backend/internal/middleware/auth_middleware.go
@@ -118,22 +118,6 @@ func userHasRole(user *models.User, role string) bool {
return false
}
-// Backward-compatible helpers
-
-// func AuthMiddlewareHandler(authService *services.AuthService) gin.HandlerFunc {
-// return NewAuthMiddleware(authService).WithAdminNotRequired().Add()
-// }
-
-// func OptionalAuthMiddleware(authService *services.AuthService) gin.HandlerFunc {
-// return NewAuthMiddleware(authService).WithAdminNotRequired().WithSuccessOptional().Add()
-// }
-
-// func AdminOnlyMiddleware(authService *services.AuthService) gin.HandlerFunc {
-// return NewAuthMiddleware(authService).WithAdminRequired().Add()
-// }
-
-// Accessors
-
func GetCurrentUserID(c *gin.Context) (string, bool) {
userID, exists := c.Get("userID")
if !exists {
diff --git a/backend/internal/models/settings.go b/backend/internal/models/settings.go
index 24972e3da..206082878 100644
--- a/backend/internal/models/settings.go
+++ b/backend/internal/models/settings.go
@@ -58,7 +58,6 @@ type Settings struct {
AuthOidcEnabled SettingVariable `key:"authOidcEnabled,public"`
AuthSessionTimeout SettingVariable `key:"authSessionTimeout"`
AuthPasswordPolicy SettingVariable `key:"authPasswordPolicy"`
- AuthRbacEnabled SettingVariable `key:"authRbacEnabled"`
AuthOidcConfig SettingVariable `key:"authOidcConfig,sensitive"`
// Onboarding
diff --git a/backend/internal/services/image_update_service.go b/backend/internal/services/image_update_service.go
index 4c63c74ad..740e21413 100644
--- a/backend/internal/services/image_update_service.go
+++ b/backend/internal/services/image_update_service.go
@@ -847,7 +847,6 @@ func (s *ImageUpdateService) saveUpdateResultByID(ctx context.Context, imageID s
currentVersion = image.Tag
}
- // map auth fields to pointers
var authMethod *string
if result.AuthMethod != "" {
authMethod = &result.AuthMethod
@@ -875,7 +874,6 @@ func (s *ImageUpdateService) saveUpdateResultByID(ctx context.Context, imageID s
ResponseTimeMs: result.ResponseTimeMs,
LastError: lastError,
- // new auth fields
AuthMethod: authMethod,
AuthUsername: authUsername,
AuthRegistry: authRegistry,
diff --git a/backend/internal/services/settings_service.go b/backend/internal/services/settings_service.go
index 037e8f010..796b2aa05 100644
--- a/backend/internal/services/settings_service.go
+++ b/backend/internal/services/settings_service.go
@@ -55,9 +55,9 @@ func (s *SettingsService) getDefaultSettings() *models.Settings {
// Docker settings
StacksDirectory: models.SettingVariable{Value: "data/projects"},
AutoUpdate: models.SettingVariable{Value: "true"},
- AutoUpdateInterval: models.SettingVariable{Value: "3600"},
+ AutoUpdateInterval: models.SettingVariable{Value: "1440"},
PollingEnabled: models.SettingVariable{Value: "true"},
- PollingInterval: models.SettingVariable{Value: "300"},
+ PollingInterval: models.SettingVariable{Value: "60"},
PruneMode: models.SettingVariable{Value: "dangling"},
BaseServerURL: models.SettingVariable{Value: ""},
EnableGravatar: models.SettingVariable{Value: "true"},
@@ -67,7 +67,6 @@ func (s *SettingsService) getDefaultSettings() *models.Settings {
AuthOidcEnabled: models.SettingVariable{Value: "false"},
AuthSessionTimeout: models.SettingVariable{Value: "1440"},
AuthPasswordPolicy: models.SettingVariable{Value: "strong"},
- AuthRbacEnabled: models.SettingVariable{Value: "false"},
AuthOidcConfig: models.SettingVariable{Value: "{}"},
// Onboarding settings