Skip to content

Modern Docker Management, Designed for Everyone

chore: fix go lint issues

Kyle Mendellfc9083123f02
diff --git a/backend/internal/api/image_handler.go b/backend/internal/api/image_handler.go
index 4d9bb50e3..c4dbde5d1 100644
--- a/backend/internal/api/image_handler.go
+++ b/backend/internal/api/image_handler.go
@@ -94,6 +94,7 @@ func (h *ImageHandler) Remove(c *gin.Context) {
}
func (h *ImageHandler) Pull(c *gin.Context) {
+ ctx := c.Request.Context()
var req dto.ImagePullDto
if err := c.ShouldBindJSON(&req); err != nil {
@@ -109,7 +110,7 @@ func (h *ImageHandler) Pull(c *gin.Context) {
c.Writer.Header().Set("Connection", "keep-alive")
c.Writer.Header().Set("X-Accel-Buffering", "no")
- err := h.imageService.PullImage(c.Request.Context(), req.ImageName, c.Writer)
+ err := h.imageService.PullImage(ctx, req.ImageName, c.Writer)
if err != nil {
if !c.Writer.Written() {
@@ -125,7 +126,9 @@ func (h *ImageHandler) Pull(c *gin.Context) {
})
}
} else {
- slog.Error("Error during image pull stream or post-stream operation", "imageName", req.ImageName, "error", err.Error())
+ slog.ErrorContext(ctx, "Error during image pull stream or post-stream operation",
+ slog.String("imageName", req.ImageName),
+ slog.String("error", err.Error()))
fmt.Fprintf(c.Writer, `{"error": {"code": 500, "message": "Stream interrupted or post-stream operation failed: %s"}}\n`, strings.ReplaceAll(err.Error(), "\"", "'"))
if flusher, ok := c.Writer.(http.Flusher); ok {
flusher.Flush()
@@ -134,7 +137,8 @@ func (h *ImageHandler) Pull(c *gin.Context) {
return
}
- slog.Info("Image pull stream completed and database sync attempted", "imageName", req.ImageName)
+ slog.InfoContext(ctx, "Image pull stream completed and database sync attempted",
+ slog.String("imageName", req.ImageName))
}
func (h *ImageHandler) Prune(c *gin.Context) {
diff --git a/backend/internal/api/system_handler.go b/backend/internal/api/system_handler.go
index 48afc5a8a..c2c10fcf1 100644
--- a/backend/internal/api/system_handler.go
+++ b/backend/internal/api/system_handler.go
@@ -215,11 +215,12 @@ func (h *SystemHandler) TestDockerConnection(c *gin.Context) {
}
func (h *SystemHandler) PruneAll(c *gin.Context) {
- slog.Info("System prune operation initiated")
+ ctx := c.Request.Context()
+ slog.InfoContext(ctx, "System prune operation initiated")
var req dto.PruneSystemDto
if err := c.ShouldBindJSON(&req); err != nil {
- slog.Error("Failed to bind prune request JSON",
+ slog.ErrorContext(ctx, "Failed to bind prune request JSON",
slog.String("error", err.Error()),
slog.String("client_ip", c.ClientIP()))
c.JSON(http.StatusBadRequest, gin.H{
@@ -229,16 +230,16 @@ func (h *SystemHandler) PruneAll(c *gin.Context) {
return
}
- slog.Info("Prune request parsed successfully",
+ slog.InfoContext(ctx, "Prune request parsed successfully",
slog.Bool("containers", req.Containers),
slog.Bool("images", req.Images),
slog.Bool("volumes", req.Volumes),
slog.Bool("networks", req.Networks),
slog.Bool("dangling", req.Dangling))
- result, err := h.systemService.PruneAll(c.Request.Context(), req)
+ result, err := h.systemService.PruneAll(ctx, req)
if err != nil {
- slog.Error("System prune operation failed",
+ slog.ErrorContext(ctx, "System prune operation failed",
slog.String("error", err.Error()),
slog.String("client_ip", c.ClientIP()))
c.JSON(http.StatusInternalServerError, gin.H{
@@ -248,7 +249,7 @@ func (h *SystemHandler) PruneAll(c *gin.Context) {
return
}
- slog.Info("System prune operation completed successfully",
+ slog.InfoContext(ctx, "System prune operation completed successfully",
slog.Int("containers_pruned", len(result.ContainersPruned)),
slog.Int("images_deleted", len(result.ImagesDeleted)),
slog.Int("volumes_deleted", len(result.VolumesDeleted)),
diff --git a/backend/internal/bootstrap/bootstrap.go b/backend/internal/bootstrap/bootstrap.go
index 7840a9b00..30e3ae6c4 100644
--- a/backend/internal/bootstrap/bootstrap.go
+++ b/backend/internal/bootstrap/bootstrap.go
@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
- "log"
"log/slog"
"net/http"
"os"
@@ -33,12 +32,14 @@ type App struct {
}
func InitializeApp() (*App, error) {
+ ctx := context.Background()
+
if err := godotenv.Load(); err != nil {
- log.Println("No .env file found, using environment variables")
+ slog.InfoContext(ctx, "No .env file found, using environment variables")
}
cfg := config.Load()
- appCtx, cancelApp := context.WithCancel(context.Background())
+ appCtx, cancelApp := context.WithCancel(ctx)
utils.InitEncryption(cfg)
@@ -65,25 +66,29 @@ func InitializeApp() (*App, error) {
router := setupRouter(cfg, appServices)
if dockerClient, err := dockerClientService.CreateConnection(context.Background()); err != nil {
- log.Printf("Warning: Docker connection failed during init: %v. Local Docker features may be unavailable.", err)
+ slog.WarnContext(appCtx, "Docker connection failed during init, local Docker features may be unavailable",
+ slog.String("error", err.Error()))
} else {
dockerClient.Close()
}
- log.Println("Performing initial Docker image synchronization with the database...")
+ slog.InfoContext(appCtx, "Performing initial Docker image synchronization with the database")
if _, err := appServices.Image.ListImages(appCtx); err != nil {
- log.Printf("⚠️ Warning: Initial Docker image synchronization failed: %v. Image data may be stale.", err)
+ slog.WarnContext(appCtx, "Initial Docker image synchronization failed, image data may be stale",
+ slog.String("error", err.Error()))
} else {
- log.Println("Initial Docker image synchronization complete.")
+ slog.InfoContext(appCtx, "Initial Docker image synchronization complete")
}
if err := appServices.User.CreateDefaultAdmin(); err != nil {
- log.Printf("Warning: failed to create default admin user: %v", err)
+ slog.WarnContext(appCtx, "Failed to create default admin user",
+ slog.String("error", err.Error()))
}
if cfg.OidcEnabled {
if err := appServices.Auth.SyncOidcEnvToDatabase(context.Background()); err != nil {
- log.Printf("⚠️ Warning: Failed to sync OIDC environment variables to database: %v", err)
+ slog.WarnContext(appCtx, "Failed to sync OIDC environment variables to database",
+ slog.String("error", err.Error()))
}
}
@@ -105,13 +110,13 @@ func (app *App) Start() {
registerJobs(app.AppCtx, app.Scheduler, app.Services)
go func() {
- slog.Info("Starting scheduler goroutine")
+ slog.InfoContext(app.AppCtx, "Starting scheduler goroutine")
if err := app.Scheduler.Run(app.AppCtx); err != nil {
if !errors.Is(err, context.Canceled) {
- slog.Error("Job scheduler exited with error", slog.Any("error", err))
+ slog.ErrorContext(app.AppCtx, "Job scheduler exited with error", slog.Any("error", err))
}
}
- slog.Info("Scheduler goroutine finished")
+ slog.InfoContext(app.AppCtx, "Scheduler goroutine finished")
}()
srv := &http.Server{
@@ -121,16 +126,17 @@ func (app *App) Start() {
}
go func() {
- log.Printf("Starting server on port %s", app.Config.Port)
+ slog.InfoContext(app.AppCtx, "Starting server", slog.String("port", app.Config.Port))
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
- log.Fatalf("Failed to start server: %v", err)
+ slog.ErrorContext(app.AppCtx, "Failed to start server", slog.String("error", err.Error()))
+ os.Exit(1)
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
- log.Println("Shutting down server and scheduler...")
+ slog.InfoContext(app.AppCtx, "Shutting down server and scheduler")
app.CancelApp()
@@ -138,8 +144,8 @@ func (app *App) Start() {
defer cancelShutdown()
if err := srv.Shutdown(shutdownCtx); err != nil {
- log.Printf("Server forced to shutdown: %v", err)
+ slog.ErrorContext(shutdownCtx, "Server forced to shutdown", slog.String("error", err.Error()))
}
- log.Println("Server exiting")
+ slog.InfoContext(app.AppCtx, "Server exiting")
}
diff --git a/backend/internal/bootstrap/jobs_bootstrap.go b/backend/internal/bootstrap/jobs_bootstrap.go
index 6be2d9d91..020b1cfd1 100644
--- a/backend/internal/bootstrap/jobs_bootstrap.go
+++ b/backend/internal/bootstrap/jobs_bootstrap.go
@@ -19,10 +19,10 @@ func initializeScheduler() (*job.Scheduler, error) {
func registerJobs(appCtx context.Context, scheduler *job.Scheduler, appServices *api.Services) {
if err := job.RegisterAutoUpdateJob(appCtx, scheduler, appServices.AutoUpdate, appServices.Settings); err != nil {
- slog.Error("Failed to register auto-update job", slog.Any("error", err))
+ slog.ErrorContext(appCtx, "Failed to register auto-update job", slog.Any("error", err))
}
if err := job.RegisterStackSyncJob(appCtx, scheduler, appServices.Stack); err != nil {
- slog.Error("Failed to register stack sync job", slog.Any("error", err))
+ slog.ErrorContext(appCtx, "Failed to register stack sync job", slog.Any("error", err))
}
}
diff --git a/backend/internal/job/job.go b/backend/internal/job/job.go
index ed78e8c36..be45a6180 100644
--- a/backend/internal/job/job.go
+++ b/backend/internal/job/job.go
@@ -22,20 +22,20 @@ func NewScheduler() (*Scheduler, error) {
}
func (s *Scheduler) Run(ctx context.Context) error {
- slog.Info("Starting job scheduler")
+ slog.InfoContext(ctx, "Starting job scheduler")
s.scheduler.Start() // Start the scheduler, non-blocking
// Wait for the context to be done (e.g., application shutdown)
<-ctx.Done()
- slog.Info("Shutting down job scheduler...")
+ slog.InfoContext(ctx, "Shutting down job scheduler...")
err := s.scheduler.Shutdown()
if err != nil {
- slog.Error("Error shutting down job scheduler", slog.Any("error", err))
+ slog.ErrorContext(ctx, "Error shutting down job scheduler", slog.Any("error", err))
return fmt.Errorf("error during scheduler shutdown: %w", err)
}
- slog.Info("Job scheduler shut down successfully")
+ slog.InfoContext(ctx, "Job scheduler shut down successfully")
return nil
}
@@ -50,19 +50,19 @@ func (s *Scheduler) RegisterJob(
gocron.WithContext(ctx),
gocron.WithEventListeners(
gocron.BeforeJobRuns(func(jobID uuid.UUID, jobName string) {
- slog.Info("Job starting",
+ slog.InfoContext(ctx, "Job starting",
slog.String("name", name),
slog.String("id", jobID.String()),
)
}),
gocron.AfterJobRuns(func(jobID uuid.UUID, jobName string) {
- slog.Info("Job finished successfully",
+ slog.InfoContext(ctx, "Job finished successfully",
slog.String("name", name),
slog.String("id", jobID.String()),
)
}),
gocron.AfterJobRunsWithError(func(jobID uuid.UUID, jobName string, err error) {
- slog.Error("Job failed",
+ slog.ErrorContext(ctx, "Job failed",
slog.String("name", name),
slog.String("id", jobID.String()),
slog.Any("error", err),
@@ -73,7 +73,7 @@ func (s *Scheduler) RegisterJob(
task := gocron.NewTask(func() {
if err := taskFunc(ctx); err != nil {
- slog.Error("Error executing task function",
+ slog.ErrorContext(ctx, "Error executing task function",
slog.String("name", name),
slog.Any("error", err),
)
@@ -90,6 +90,6 @@ func (s *Scheduler) RegisterJob(
return fmt.Errorf("failed to register job %q: %w", name, err)
}
- slog.Info("Job registered successfully", slog.String("name", name))
+ slog.InfoContext(ctx, "Job registered successfully", slog.String("name", name))
return nil
}
diff --git a/backend/internal/job/stack_sync_job.go b/backend/internal/job/stack_sync_job.go
index 90eab8821..f81481aba 100644
--- a/backend/internal/job/stack_sync_job.go
+++ b/backend/internal/job/stack_sync_job.go
@@ -17,20 +17,20 @@ func RegisterStackSyncJob(
scheduler *Scheduler,
stackService *services.StackService,
) error {
- slog.Info("Registering stack sync job", "jobName", StackSyncJobName)
+ slog.InfoContext(ctx, "Registering stack sync job", "jobName", StackSyncJobName)
taskFunc := func(jobCtx context.Context) error {
- slog.Info("Running stack sync job", "jobName", StackSyncJobName)
+ slog.InfoContext(jobCtx, "Running stack sync job", "jobName", StackSyncJobName)
// Sync all stacks with filesystem (this handles both discovery and updates)
if err := stackService.SyncAllStacksFromFilesystem(jobCtx); err != nil {
- slog.Error("Failed to sync stacks with filesystem",
+ slog.ErrorContext(jobCtx, "Failed to sync stacks with filesystem",
"jobName", StackSyncJobName,
slog.Any("error", err))
return err
}
- slog.Info("Stack sync job completed", "jobName", StackSyncJobName)
+ slog.InfoContext(jobCtx, "Stack sync job completed", "jobName", StackSyncJobName)
return nil
}
@@ -49,6 +49,6 @@ func RegisterStackSyncJob(
return fmt.Errorf("failed to register stack sync job %q: %w", StackSyncJobName, err)
}
- slog.Info("Stack sync job registered successfully", "jobName", StackSyncJobName)
+ slog.InfoContext(ctx, "Stack sync job registered successfully", "jobName", StackSyncJobName)
return nil
}
diff --git a/backend/internal/services/auto_update_service.go b/backend/internal/services/auto_update_service.go
index b97520d99..0f34d4099 100644
--- a/backend/internal/services/auto_update_service.go
+++ b/backend/internal/services/auto_update_service.go
@@ -135,7 +135,9 @@ func (s *AutoUpdateService) CheckForUpdates(ctx context.Context, req dto.AutoUpd
result.Failed++
}
- s.recordAutoUpdate(ctx, res)
+ if err := s.recordAutoUpdate(ctx, res); err != nil {
+ log.Printf("Failed to record auto-update result: %v", err)
+ }
}
for err := range errorsChan {
@@ -802,17 +804,14 @@ func (s *AutoUpdateService) checkStackImagesForUpdates(ctx context.Context, stac
hasUpdates := false
imageUpdates := make(map[string]string)
- // Get current service information to retrieve actual image IDs
services, err := s.stackService.GetStackServices(ctx, stack.ID)
if err != nil {
return false, nil, fmt.Errorf("failed to get stack services: %w", err)
}
- // Create a map of service name to current image ID for quick lookup
serviceImageIDs := make(map[string]string)
for _, svc := range services {
if svc.Image != "" {
- // Extract the current image ID from the service
currentImageID, err := s.getImageDigest(ctx, svc.Image)
if err != nil {
log.Printf("Warning: Failed to get current image digest for service %s: %v", svc.Name, err)
@@ -827,7 +826,6 @@ func (s *AutoUpdateService) checkStackImagesForUpdates(ctx context.Context, stac
continue
}
- // Get the current image ID for this service, or use empty string if not found
currentImageID := serviceImageIDs[serviceName]
hasUpdate, newDigest, err := s.checkImageForUpdate(ctx, imageRef, currentImageID, settings)
diff --git a/backend/internal/services/container_service.go b/backend/internal/services/container_service.go
index 91109a75e..9f526f36f 100644
--- a/backend/internal/services/container_service.go
+++ b/backend/internal/services/container_service.go
@@ -434,6 +434,7 @@ func (s *ContainerService) readAllLogs(logs io.ReadCloser, logsChan chan<- strin
return nil
}
+//nolint:gocognit
func (s *ContainerService) ListContainersPaginated(ctx context.Context, req utils.SortedPaginationRequest, includeAll bool) ([]map[string]interface{}, utils.PaginationResponse, error) {
dockerContainers, err := s.ListContainers(ctx, includeAll)
if err != nil {
diff --git a/backend/internal/services/image_update_service.go b/backend/internal/services/image_update_service.go
index c64b06219..40b52ded9 100644
--- a/backend/internal/services/image_update_service.go
+++ b/backend/internal/services/image_update_service.go
@@ -7,6 +7,8 @@ import (
"strings"
"time"
+ "log/slog"
+
"github.com/docker/docker/api/types/image"
"github.com/ofkm/arcane-backend/internal/database"
"github.com/ofkm/arcane-backend/internal/models"
@@ -98,8 +100,12 @@ func (s *ImageUpdateService) CheckImageUpdate(ctx context.Context, imageRef stri
CheckTime: time.Now(),
ResponseTimeMs: int(time.Since(startTime).Milliseconds()),
}
- s.saveUpdateResult(ctx, imageRef, result)
- return result, nil
+ if saveErr := s.saveUpdateResult(ctx, imageRef, result); saveErr != nil {
+ slog.WarnContext(ctx, "Failed to save update result",
+ slog.String("imageRef", imageRef),
+ slog.String("error", saveErr.Error()))
+ }
+ return result, err
}
if !digestResult.HasUpdate && !s.isSpecialTag(parts.Tag) {
@@ -110,18 +116,30 @@ func (s *ImageUpdateService) CheckImageUpdate(ctx context.Context, imageRef stri
CheckTime: time.Now(),
ResponseTimeMs: int(time.Since(startTime).Milliseconds()),
}
- s.saveUpdateResult(ctx, imageRef, result)
- return result, nil
+ if saveErr := s.saveUpdateResult(ctx, imageRef, result); saveErr != nil {
+ slog.WarnContext(ctx, "Failed to save update result",
+ slog.String("imageRef", imageRef),
+ slog.String("error", saveErr.Error()))
+ }
+ return result, err
}
if tagResult.HasUpdate {
tagResult.ResponseTimeMs = int(time.Since(startTime).Milliseconds())
- s.saveUpdateResult(ctx, imageRef, tagResult)
+ if saveErr := s.saveUpdateResult(ctx, imageRef, tagResult); saveErr != nil {
+ slog.WarnContext(ctx, "Failed to save update result",
+ slog.String("imageRef", imageRef),
+ slog.String("error", saveErr.Error()))
+ }
return tagResult, nil
}
}
digestResult.ResponseTimeMs = int(time.Since(startTime).Milliseconds())
- s.saveUpdateResult(ctx, imageRef, digestResult)
+ if saveErr := s.saveUpdateResult(ctx, imageRef, digestResult); saveErr != nil {
+ slog.WarnContext(ctx, "Failed to save update result",
+ slog.String("imageRef", imageRef),
+ slog.String("error", saveErr.Error()))
+ }
return digestResult, nil
}
@@ -378,7 +396,8 @@ func (s *ImageUpdateService) parseImageReference(imageRef string) *ImageParts {
} else {
parts := strings.Split(imageRef, "/")
- if len(parts) == 1 {
+ switch {
+ case len(parts) == 1:
registry = "docker.io"
if strings.Contains(parts[0], ":") {
repoParts := strings.Split(parts[0], ":")
@@ -388,7 +407,7 @@ func (s *ImageUpdateService) parseImageReference(imageRef string) *ImageParts {
repository = "library/" + parts[0]
tag = "latest"
}
- } else if strings.Contains(parts[0], ".") || strings.Contains(parts[0], ":") {
+ case strings.Contains(parts[0], ".") || strings.Contains(parts[0], ":"):
registry = parts[0]
repository = strings.Join(parts[1:], "/")
@@ -399,7 +418,7 @@ func (s *ImageUpdateService) parseImageReference(imageRef string) *ImageParts {
} else {
tag = "latest"
}
- } else {
+ default:
registry = "docker.io"
repository = imageRef
@@ -602,7 +621,11 @@ func (s *ImageUpdateService) CheckImageUpdateByID(ctx context.Context, imageID s
return nil, err
}
- s.saveUpdateResultByID(ctx, imageID, result)
+ if saveErr := s.saveUpdateResultByID(ctx, imageID, result); saveErr != nil {
+ slog.WarnContext(ctx, "Failed to save update result by ID",
+ slog.String("imageID", imageID),
+ slog.String("error", saveErr.Error()))
+ }
return result, nil
}
@@ -816,11 +839,12 @@ func (s *ImageUpdateService) CompareVersions(ctx context.Context, imageRef, curr
var changeLevel string
if currentVer.Major != nil && targetVer.Major != nil {
- if *targetVer.Major > *currentVer.Major {
+ switch {
+ case *targetVer.Major > *currentVer.Major:
changeLevel = "major"
- } else if targetVer.Minor != nil && currentVer.Minor != nil && *targetVer.Minor > *currentVer.Minor {
+ case targetVer.Minor != nil && currentVer.Minor != nil && *targetVer.Minor > *currentVer.Minor:
changeLevel = "minor"
- } else {
+ default:
changeLevel = "patch"
}
} else {
diff --git a/backend/internal/services/network_service.go b/backend/internal/services/network_service.go
index 36df68b4e..de521c885 100644
--- a/backend/internal/services/network_service.go
+++ b/backend/internal/services/network_service.go
@@ -224,7 +224,7 @@ func (s *NetworkService) GetUserDefinedNetworks(ctx context.Context) ([]network.
return userDefined, nil
}
-// ListNetworksPaginated returns paginated Docker networks
+//nolint:gocognit
func (s *NetworkService) ListNetworksPaginated(ctx context.Context, req utils.SortedPaginationRequest) ([]map[string]interface{}, utils.PaginationResponse, error) {
networks, err := s.ListNetworks(ctx)
if err != nil {
diff --git a/backend/internal/services/system_service.go b/backend/internal/services/system_service.go
index f10709ebf..1fdd20ad0 100644
--- a/backend/internal/services/system_service.go
+++ b/backend/internal/services/system_service.go
@@ -60,7 +60,7 @@ type ContainerActionResult struct {
}
func (s *SystemService) PruneAll(ctx context.Context, req dto.PruneSystemDto) (*PruneAllResult, error) {
- slog.Info("Starting selective prune operation",
+ slog.InfoContext(ctx, "Starting selective prune operation",
slog.Bool("containers", req.Containers),
slog.Bool("images", req.Images),
slog.Bool("volumes", req.Volumes),
@@ -72,7 +72,7 @@ func (s *SystemService) PruneAll(ctx context.Context, req dto.PruneSystemDto) (*
}
if req.Containers {
- slog.Debug("Processing container pruning")
+ slog.DebugContext(ctx, "Processing container pruning")
if err := s.pruneContainers(ctx, result); err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Container pruning failed: %v", err))
result.Success = false
@@ -84,12 +84,12 @@ func (s *SystemService) PruneAll(ctx context.Context, req dto.PruneSystemDto) (*
if settingsErr != nil {
danglingOnly = req.Dangling
result.Errors = append(result.Errors, fmt.Sprintf("Warning: Could not get prune mode from settings, using request parameter: %v", settingsErr))
- slog.Warn("Could not get prune mode from settings, using request parameter",
+ slog.WarnContext(ctx, "Could not get prune mode from settings, using request parameter",
slog.String("error", settingsErr.Error()),
slog.Bool("fallback_dangling", req.Dangling))
}
- slog.Debug("Processing image pruning",
+ slog.DebugContext(ctx, "Processing image pruning",
slog.Bool("settings_dangling_mode", danglingOnly),
slog.Bool("request_dangling", req.Dangling))
@@ -98,14 +98,14 @@ func (s *SystemService) PruneAll(ctx context.Context, req dto.PruneSystemDto) (*
result.Success = false
}
- slog.Debug("Processing build cache pruning as part of image pruning")
+ slog.DebugContext(ctx, "Processing build cache pruning as part of image pruning")
if buildCacheErr := s.pruneBuildCache(ctx, result, !danglingOnly); buildCacheErr != nil {
- slog.Warn("Build cache pruning encountered an error", slog.String("error", buildCacheErr.Error()))
+ slog.WarnContext(ctx, "Build cache pruning encountered an error", slog.String("error", buildCacheErr.Error()))
}
}
if req.Volumes {
- slog.Debug("Processing volume pruning")
+ slog.DebugContext(ctx, "Processing volume pruning")
if err := s.pruneVolumes(ctx, result); err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Volume pruning failed: %v", err))
result.Success = false
@@ -113,14 +113,14 @@ func (s *SystemService) PruneAll(ctx context.Context, req dto.PruneSystemDto) (*
}
if req.Networks {
- slog.Debug("Processing network pruning")
+ slog.DebugContext(ctx, "Processing network pruning")
if err := s.pruneNetworks(ctx, result); err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Network pruning failed: %v", err))
result.Success = false
}
}
- slog.Info("Selective prune operation completed",
+ slog.InfoContext(ctx, "Selective prune operation completed",
slog.Bool("success", result.Success),
slog.Int("containers_pruned", len(result.ContainersPruned)),
slog.Int("images_deleted", len(result.ImagesDeleted)),
@@ -251,7 +251,7 @@ func (s *SystemService) pruneContainers(ctx context.Context, result *PruneAllRes
}
func (s *SystemService) pruneImages(ctx context.Context, danglingOnly bool, result *PruneAllResult) error {
- slog.Debug("Starting image pruning", slog.Bool("dangling_only", danglingOnly))
+ slog.DebugContext(ctx, "Starting image pruning", slog.Bool("dangling_only", danglingOnly))
dockerClient, err := s.dockerService.CreateConnection(ctx)
if err != nil {
@@ -262,10 +262,10 @@ func (s *SystemService) pruneImages(ctx context.Context, danglingOnly bool, resu
var filterArgs filters.Args
if danglingOnly {
- slog.Debug("Configured to prune only dangling images")
+ slog.DebugContext(ctx, "Configured to prune only dangling images")
filterArgs = filters.NewArgs(filters.Arg("dangling", "true"))
} else {
- slog.Debug("Configured to prune all unused images (including non-dangling)")
+ slog.DebugContext(ctx, "Configured to prune all unused images (including non-dangling)")
filterArgs = filters.NewArgs(filters.Arg("dangling", "false"))
}
@@ -274,7 +274,7 @@ func (s *SystemService) pruneImages(ctx context.Context, danglingOnly bool, resu
return fmt.Errorf("failed to prune images: %w", err)
}
- slog.Info("Image pruning completed",
+ slog.InfoContext(ctx, "Image pruning completed",
slog.Int("images_deleted", len(report.ImagesDeleted)),
slog.Uint64("bytes_reclaimed", report.SpaceReclaimed))
@@ -286,11 +286,11 @@ func (s *SystemService) pruneImages(ctx context.Context, danglingOnly bool, resu
}
if prunedDockerID != "" {
- slog.Debug("Attempting to delete image from database", slog.String("docker_id", prunedDockerID))
+ slog.DebugContext(ctx, "Attempting to delete image from database", slog.String("docker_id", prunedDockerID))
if dbErr := s.imageService.DeleteImageByDockerID(ctx, prunedDockerID); dbErr != nil {
errMsg := fmt.Sprintf("Failed to delete image %s from database: %v", prunedDockerID, dbErr)
result.Errors = append(result.Errors, errMsg)
- slog.Error("Failed to delete image from database",
+ slog.ErrorContext(ctx, "Failed to delete image from database",
slog.String("docker_id", prunedDockerID),
slog.String("error", dbErr.Error()))
}
@@ -304,7 +304,7 @@ func (s *SystemService) pruneBuildCache(ctx context.Context, result *PruneAllRes
dockerClient, err := s.dockerService.CreateConnection(ctx)
if err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Build cache pruning failed (connection): %v", err))
- slog.Error("Error connecting to Docker for build cache prune", slog.String("error", err.Error()))
+ slog.ErrorContext(ctx, "Error connecting to Docker for build cache prune", slog.String("error", err.Error()))
return fmt.Errorf("failed to connect to Docker for build cache prune: %w", err)
}
defer dockerClient.Close()
@@ -313,15 +313,15 @@ func (s *SystemService) pruneBuildCache(ctx context.Context, result *PruneAllRes
All: pruneAllCache,
}
- slog.Debug("Starting build cache pruning", slog.Bool("prune_all", pruneAllCache))
+ slog.DebugContext(ctx, "Starting build cache pruning", slog.Bool("prune_all", pruneAllCache))
report, err := dockerClient.BuildCachePrune(ctx, options)
if err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Build cache pruning failed: %v", err))
- slog.Error("Error pruning build cache", slog.String("error", err.Error()))
+ slog.ErrorContext(ctx, "Error pruning build cache", slog.String("error", err.Error()))
return fmt.Errorf("failed to prune build cache: %w", err)
}
- slog.Info("Build cache pruning completed",
+ slog.InfoContext(ctx, "Build cache pruning completed",
slog.Int("cache_entries_deleted", len(report.CachesDeleted)),
slog.Uint64("bytes_reclaimed", report.SpaceReclaimed))
@@ -351,7 +351,7 @@ func (s *SystemService) pruneNetworks(ctx context.Context, result *PruneAllResul
}
func (s *SystemService) PruneSystem(ctx context.Context, all bool) (*PruneAllResult, error) {
- slog.Info("Starting system-wide prune operation", slog.Bool("all", all))
+ slog.InfoContext(ctx, "Starting system-wide prune operation", slog.Bool("all", all))
result := &PruneAllResult{
Success: true,
@@ -362,52 +362,52 @@ func (s *SystemService) PruneSystem(ctx context.Context, all bool) (*PruneAllRes
settings, err := s.settingsService.GetSettings(ctx)
if err == nil && settings.PruneMode != nil {
danglingOnly = *settings.PruneMode == "dangling"
- slog.Debug("Retrieved prune mode from settings",
+ slog.DebugContext(ctx, "Retrieved prune mode from settings",
slog.String("prune_mode", *settings.PruneMode),
slog.Bool("dangling_only", danglingOnly))
} else {
danglingOnly = false
if err != nil {
- slog.Warn("Failed to get prune mode from settings, defaulting to all unused",
+ slog.WarnContext(ctx, "Failed to get prune mode from settings, defaulting to all unused",
slog.String("error", err.Error()))
}
}
}
- slog.Debug("Starting container pruning")
+ slog.DebugContext(ctx, "Starting container pruning")
if err := s.pruneContainers(ctx, result); err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Container pruning failed: %v", err))
result.Success = false
- slog.Error("Container pruning failed", slog.String("error", err.Error()))
+ slog.ErrorContext(ctx, "Container pruning failed", slog.String("error", err.Error()))
}
- slog.Debug("Starting image pruning", slog.Bool("dangling_only", danglingOnly))
+ slog.DebugContext(ctx, "Starting image pruning", slog.Bool("dangling_only", danglingOnly))
if err := s.pruneImages(ctx, danglingOnly, result); err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Image pruning failed: %v", err))
result.Success = false
- slog.Error("Image pruning failed", slog.String("error", err.Error()))
+ slog.ErrorContext(ctx, "Image pruning failed", slog.String("error", err.Error()))
}
- slog.Debug("Starting build cache pruning", slog.Bool("prune_all_cache", !danglingOnly))
+ slog.DebugContext(ctx, "Starting build cache pruning", slog.Bool("prune_all_cache", !danglingOnly))
if buildCacheErr := s.pruneBuildCache(ctx, result, !danglingOnly); buildCacheErr != nil {
- slog.Warn("Build cache pruning encountered an error", slog.String("error", buildCacheErr.Error()))
+ slog.WarnContext(ctx, "Build cache pruning encountered an error", slog.String("error", buildCacheErr.Error()))
}
- slog.Debug("Starting volume pruning")
+ slog.DebugContext(ctx, "Starting volume pruning")
if err := s.pruneVolumes(ctx, result); err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Volume pruning failed: %v", err))
result.Success = false
- slog.Error("Volume pruning failed", slog.String("error", err.Error()))
+ slog.ErrorContext(ctx, "Volume pruning failed", slog.String("error", err.Error()))
}
- slog.Debug("Starting network pruning")
+ slog.DebugContext(ctx, "Starting network pruning")
if err := s.pruneNetworks(ctx, result); err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("Network pruning failed: %v", err))
result.Success = false
- slog.Error("Network pruning failed", slog.String("error", err.Error()))
+ slog.ErrorContext(ctx, "Network pruning failed", slog.String("error", err.Error()))
}
- slog.Info("System-wide prune operation completed",
+ slog.InfoContext(ctx, "System-wide prune operation completed",
slog.Bool("success", result.Success),
slog.Int("containers_pruned", len(result.ContainersPruned)),
slog.Int("images_deleted", len(result.ImagesDeleted)),
diff --git a/backend/internal/services/volume_service.go b/backend/internal/services/volume_service.go
index ff937e8fc..fd02fc432 100644
--- a/backend/internal/services/volume_service.go
+++ b/backend/internal/services/volume_service.go
@@ -173,6 +173,7 @@ func (s *VolumeService) GetVolumeUsage(ctx context.Context, name string) (bool,
return inUse, usingContainers, nil
}
+//nolint:gocognit
func (s *VolumeService) ListVolumesPaginated(ctx context.Context, req utils.SortedPaginationRequest) ([]map[string]interface{}, utils.PaginationResponse, error) {
volumes, err := s.ListVolumes(ctx)
if err != nil {
diff --git a/backend/internal/utils/page_util.go b/backend/internal/utils/page_util.go
index ee4223213..3076c0c19 100644
--- a/backend/internal/utils/page_util.go
+++ b/backend/internal/utils/page_util.go
@@ -227,6 +227,7 @@ func CalculateTotalPages(totalItems int64, pageSize int) int64 {
return (totalItems + int64(pageSize) - 1) / int64(pageSize)
}
+//nolint:gocognit
func SortSliceByField(data []map[string]interface{}, field, direction string) {
if field == "" {
return
diff --git a/backend/internal/utils/registry_utils.go b/backend/internal/utils/registry_utils.go
index c3d83912b..1e527ca43 100644
--- a/backend/internal/utils/registry_utils.go
+++ b/backend/internal/utils/registry_utils.go
@@ -53,13 +53,14 @@ func (r *RegistryUtils) SplitImageReference(reference string) (string, string, s
registry = DEFAULT_REGISTRY
repositoryAndTag = reference
default:
- if splits[0] == "docker.io" {
+ switch {
+ case splits[0] == "docker.io":
registry = DEFAULT_REGISTRY
repositoryAndTag = strings.Join(splits[1:], "/")
- } else if splits[0] == "localhost" || strings.Contains(splits[0], ".") || strings.Contains(splits[0], ":") {
+ case splits[0] == "localhost" || strings.Contains(splits[0], ".") || strings.Contains(splits[0], ":"):
registry = splits[0]
repositoryAndTag = strings.Join(splits[1:], "/")
- } else {
+ default:
registry = DEFAULT_REGISTRY
repositoryAndTag = reference
}