Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions backend/internal/configschema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,61 @@ var overrideDocRules = map[string]overrideDocRule{
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
},
"scheduledPruneContainers": {
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
deprecated: true,
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
note: "Legacy boolean prune flag retained for migration compatibility. Prefer PRUNE_CONTAINER_MODE.",
},
"scheduledPruneImages": {
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
deprecated: true,
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
note: "Legacy boolean prune flag retained for migration compatibility. Prefer PRUNE_IMAGE_MODE.",
},
"scheduledPruneVolumes": {
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
deprecated: true,
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
note: "Legacy boolean prune flag retained for migration compatibility. Prefer PRUNE_VOLUME_MODE.",
},
"scheduledPruneNetworks": {
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
deprecated: true,
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
note: "Legacy boolean prune flag retained for migration compatibility. Prefer PRUNE_NETWORK_MODE.",
},
"scheduledPruneBuildCache": {
deprecated: true,
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
note: "Legacy boolean prune flag retained for migration compatibility. Prefer PRUNE_BUILD_CACHE_MODE.",
},
"pruneContainerMode": {
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
},
"pruneContainerUntil": {
requires: "SCHEDULED_PRUNE_ENABLED=true and PRUNE_CONTAINER_MODE=olderThan to have effect at runtime.",
},
"pruneImageMode": {
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
},
"pruneImageUntil": {
requires: "SCHEDULED_PRUNE_ENABLED=true and PRUNE_IMAGE_MODE=olderThan to have effect at runtime.",
},
"pruneVolumeMode": {
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
},
"pruneNetworkMode": {
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
},
"pruneNetworkUntil": {
requires: "SCHEDULED_PRUNE_ENABLED=true and PRUNE_NETWORK_MODE=olderThan to have effect at runtime.",
},
"pruneBuildCacheMode": {
requires: "SCHEDULED_PRUNE_ENABLED=true to have effect at runtime.",
},
"pruneBuildCacheUntil": {
requires: "SCHEDULED_PRUNE_ENABLED=true and PRUNE_BUILD_CACHE_MODE=olderThan to have effect at runtime.",
},
"dockerPruneMode": {
deprecated: true,
note: "Legacy prune mode retained for migration compatibility. Prefer the granular scheduled prune mode settings.",
},
"vulnerabilityScanInterval": {
requires: "VULNERABILITY_SCAN_ENABLED=true to have effect at runtime.",
},
Expand Down
10 changes: 9 additions & 1 deletion backend/internal/configschema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ var expectedSettingOverrideKeys = []string{
"dockerApiTimeout",
"dockerHost",
"dockerImagePullTimeout",
"dockerPruneMode",
"enableGravatar",
"environmentHealthInterval",
"eventCleanupInterval",
Expand Down Expand Up @@ -308,6 +307,15 @@ var expectedSettingOverrideKeys = []string{
"pollingInterval",
"projectsDirectory",
"proxyRequestTimeout",
"pruneBuildCacheMode",
"pruneBuildCacheUntil",
"pruneContainerMode",
"pruneContainerUntil",
"pruneImageMode",
"pruneImageUntil",
"pruneNetworkMode",
"pruneNetworkUntil",
"pruneVolumeMode",
"registryTimeout",
"scheduledPruneBuildCache",
"scheduledPruneContainers",
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/huma/handlers/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestDashboardHandlerGetDashboardReturnsSnapshot(t *testing.T) {
require.Len(t, snapshot.Images.Data, 2)
require.Equal(t, 1, snapshot.Containers.Counts.RunningContainers)
require.Equal(t, 1, snapshot.Containers.Counts.StoppedContainers)
require.Equal(t, "dangling", snapshot.Settings.DockerPruneMode)
require.Equal(t, dashboardtypes.SnapshotSettings{}, snapshot.Settings)
require.ElementsMatch(t, []dashboardtypes.ActionItem{
{Kind: dashboardtypes.ActionItemKindStoppedContainers, Count: 1, Severity: dashboardtypes.ActionItemSeverityWarning},
{Kind: dashboardtypes.ActionItemKindImageUpdates, Count: 1, Severity: dashboardtypes.ActionItemSeverityWarning},
Expand Down
75 changes: 61 additions & 14 deletions backend/internal/huma/handlers/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/getarcaneapp/arcane/backend/pkg/pagination"
"github.com/getarcaneapp/arcane/types/base"
"github.com/getarcaneapp/arcane/types/image"
"github.com/getarcaneapp/arcane/types/system"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -114,6 +115,8 @@ type PruneImagesInput struct {
EnvironmentID string `path:"id" doc:"Environment ID"`
Dangling bool `query:"dangling" doc:"Only remove dangling images"`
Body *struct {
Mode *string `json:"mode,omitempty"`
Until *string `json:"until,omitempty"`
Dangling *bool `json:"dangling,omitempty"`
Filters map[string][]string `json:"filters,omitempty"`
}
Expand Down Expand Up @@ -549,21 +552,13 @@ func (h *ImageHandler) PruneImages(ctx context.Context, input *PruneImagesInput)
return nil, huma.Error500InternalServerError("service not available")
}

dangling := input.Dangling
if input.Body != nil {
if input.Body.Dangling != nil {
dangling = *input.Body.Dangling
} else if vals, ok := input.Body.Filters["dangling"]; ok {
for _, v := range vals {
if v == "true" || v == "1" {
dangling = true
break
}
}
}
}
mode := resolvePruneImageModeInternal(input)
until := resolvePruneImageUntilInternal(input)

report, err := h.imageService.PruneImages(ctx, dangling)
report, err := h.imageService.PruneImages(ctx, system.PruneImagesOptions{
Mode: system.PruneImageMode(mode),
Until: until,
})
if err != nil {
return nil, huma.Error500InternalServerError((&common.ImagePruneError{Err: err}).Error())
}
Expand All @@ -578,6 +573,58 @@ func (h *ImageHandler) PruneImages(ctx context.Context, input *PruneImagesInput)
}, nil
}

func resolvePruneImageModeInternal(input *PruneImagesInput) string {
mode := resolveLegacyPruneImageModeInternal(input.Dangling)
if input.Body == nil {
return mode
}

if input.Body.Mode != nil && strings.TrimSpace(*input.Body.Mode) != "" {
return strings.TrimSpace(*input.Body.Mode)
}

if input.Body.Dangling != nil {
return resolveLegacyPruneImageModeInternal(*input.Body.Dangling)
}

if vals, ok := input.Body.Filters["dangling"]; ok {
for _, value := range vals {
switch value {
case "true", "1":
return "dangling"
case "false", "0":
return "all"
}
}
}

return mode
}

func resolvePruneImageUntilInternal(input *PruneImagesInput) string {
if input.Body == nil {
return ""
}

if input.Body.Until != nil {
return strings.TrimSpace(*input.Body.Until)
}

if vals, ok := input.Body.Filters["until"]; ok && len(vals) > 0 {
return strings.TrimSpace(vals[0])
}

return ""
}

func resolveLegacyPruneImageModeInternal(dangling bool) string {
if dangling {
return "dangling"
}

return "all"
}

// GetImageUsageCounts returns counts of images by usage status.
func (h *ImageHandler) GetImageUsageCounts(ctx context.Context, input *GetImageUsageCountsInput) (*GetImageUsageCountsOutput, error) {
if h.dockerService == nil || h.imageService == nil {
Expand Down
3 changes: 1 addition & 2 deletions backend/internal/huma/handlers/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ func (h *SystemHandler) PruneAll(ctx context.Context, input *PruneAllInput) (*Pr
"images", input.Body.Images,
"volumes", input.Body.Volumes,
"networks", input.Body.Networks,
"build_cache", input.Body.BuildCache,
"dangling", input.Body.Dangling)
"build_cache", input.Body.BuildCache)

result, err := h.systemService.PruneAll(ctx, input.Body)
if err != nil {
Expand Down
Loading
Loading