Skip to content

Modern Docker Management, Designed for Everyone

fix: x-arcane.icon-light/icon-dark overwriting service-level icons (#2888)

Kyle Mendell90c8cdab9157
diff --git a/backend/internal/services/container_service.go b/backend/internal/services/container_service.go
index 04889f7e8..f4bcca2ea 100644
--- a/backend/internal/services/container_service.go
+++ b/backend/internal/services/container_service.go
@@ -1154,7 +1154,7 @@ func (s *ContainerService) applyContainerDetailsIconInternal(ctx context.Context
func (s *ContainerService) resolveContainerIconInternal(ctx context.Context, labels map[string]string, metadataByProject map[string]projects.ArcaneComposeMetadata) iconcatalog.ResolvedIconSet {
explicitIcon := projects.FindArcaneIconSet(labels)
- if iconSetHasBothVariantsInternal(explicitIcon) {
+ if !explicitIcon.IsEmpty() {
return s.resolveIconSetInternal(ctx, explicitIcon)
}
@@ -1173,10 +1173,6 @@ func (s *ContainerService) resolveContainerIconInternal(ctx context.Context, lab
))
}
-func iconSetHasBothVariantsInternal(iconSet iconcatalog.IconSet) bool {
- return strings.TrimSpace(iconSet.Light) != "" && strings.TrimSpace(iconSet.Dark) != ""
-}
-
func (s *ContainerService) getCachedProjectIconMetadataInternal(ctx context.Context, projectName string, metadataByProject map[string]projects.ArcaneComposeMetadata) projects.ArcaneComposeMetadata {
if metadataByProject != nil {
if meta, ok := metadataByProject[projectName]; ok {
diff --git a/backend/pkg/projects/custom_labels_test.go b/backend/pkg/projects/custom_labels_test.go
index 0f271d752..a282f0507 100644
--- a/backend/pkg/projects/custom_labels_test.go
+++ b/backend/pkg/projects/custom_labels_test.go
@@ -36,6 +36,30 @@ x-arcane:
require.Equal(t, []string{"https://www.example.com"}, meta.ProjectURLS)
}
+func TestParseArcaneComposeMetadata_ServiceLabelIconsOutrankProjectIcon(t *testing.T) {
+ tempDir := t.TempDir()
+
+ composeContent := `x-arcane:
+ icon-light: umami
+ icon-dark: umami
+services:
+ umami:
+ image: ghcr.io/umami-software/umami:latest
+ db:
+ image: postgres:16
+ labels:
+ com.getarcaneapp.arcane.icon-light: postgres
+ com.getarcaneapp.arcane.icon-dark: postgres
+`
+ composePath := filepath.Join(tempDir, "compose.yaml")
+ require.NoError(t, os.WriteFile(composePath, []byte(composeContent), 0o600))
+
+ meta, err := ParseArcaneComposeMetadata(context.Background(), composePath, tempDir, false)
+ require.NoError(t, err)
+ require.Equal(t, IconSet{Light: "postgres", Dark: "postgres"}, meta.ServiceIconSets["db"])
+ require.NotContains(t, meta.ServiceIconSets, "umami")
+}
+
func TestParseArcaneComposeMetadata_IncludeSupport(t *testing.T) {
tempDir := t.TempDir()
diff --git a/backend/pkg/utils/iconcatalog/iconcatalog.go b/backend/pkg/utils/iconcatalog/iconcatalog.go
index 07804a8fd..379f8323a 100644
--- a/backend/pkg/utils/iconcatalog/iconcatalog.go
+++ b/backend/pkg/utils/iconcatalog/iconcatalog.go
@@ -30,39 +30,14 @@ func (s IconSet) IsEmpty() bool {
strings.TrimSpace(s.Dark) == ""
}
-func (s IconSet) HasVariant() bool {
- return strings.TrimSpace(s.Light) != "" || strings.TrimSpace(s.Dark) != ""
-}
-
+// FirstNonEmpty returns the first set that defines any icon value. Levels are
+// isolated: a set that defines one variant never inherits the others from
+// lower-precedence sets.
func FirstNonEmpty(sets ...IconSet) IconSet {
- merged := IconSet{}
- fallback := ""
-
for _, set := range sets {
- if fallback == "" {
- fallback = strings.TrimSpace(set.Icon)
- }
- if merged.Light == "" {
- merged.Light = strings.TrimSpace(set.Light)
- }
- if merged.Dark == "" {
- merged.Dark = strings.TrimSpace(set.Dark)
- }
- }
-
- if strings.TrimSpace(merged.Light) != "" || strings.TrimSpace(merged.Dark) != "" {
- if fallback != "" {
- if merged.Light == "" {
- merged.Light = fallback
- }
- if merged.Dark == "" {
- merged.Dark = fallback
- }
+ if !set.IsEmpty() {
+ return set
}
- return merged
- }
- if fallback != "" {
- return IconSet{Icon: fallback}
}
return IconSet{}
}
@@ -77,14 +52,8 @@ func Resolve(catalog string, set IconSet) ResolvedIconSet {
}
}
- light := strings.TrimSpace(set.Light)
- if light == "" {
- light = strings.TrimSpace(set.Icon)
- }
- dark := strings.TrimSpace(set.Dark)
- if dark == "" {
- dark = strings.TrimSpace(set.Icon)
- }
+ light := firstNonEmptyValueInternal(set.Light, set.Icon, set.Dark)
+ dark := firstNonEmptyValueInternal(set.Dark, set.Icon, set.Light)
return ResolvedIconSet{
IconLightURL: resolveValueInternal(selectedCatalog, light, "light"),
@@ -92,6 +61,15 @@ func Resolve(catalog string, set IconSet) ResolvedIconSet {
}
}
+func firstNonEmptyValueInternal(values ...string) string {
+ for _, v := range values {
+ if trimmed := strings.TrimSpace(v); trimmed != "" {
+ return trimmed
+ }
+ }
+ return ""
+}
+
func normalizeCatalogInternal(catalog string) string {
switch strings.ToLower(strings.TrimSpace(catalog)) {
case CatalogDashboardIcons:
diff --git a/backend/pkg/utils/iconcatalog/iconcatalog_test.go b/backend/pkg/utils/iconcatalog/iconcatalog_test.go
new file mode 100644
index 000000000..350c35f83
--- /dev/null
+++ b/backend/pkg/utils/iconcatalog/iconcatalog_test.go
@@ -0,0 +1,21 @@
+package iconcatalog
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestFirstNonEmpty_LevelIsolation(t *testing.T) {
+ containerSet := IconSet{Light: "postgres"}
+ projectSet := IconSet{Light: "umami", Dark: "umami"}
+
+ require.Equal(t, containerSet, FirstNonEmpty(containerSet, IconSet{}, projectSet))
+ require.Equal(t, projectSet, FirstNonEmpty(IconSet{}, IconSet{}, projectSet))
+}
+
+func TestResolve_SingleVariantFallsBackWithinLevel(t *testing.T) {
+ resolved := Resolve(CatalogSelfhst, IconSet{Light: "postgres"})
+ require.Equal(t, "https://cdn.jsdelivr.net/gh/selfhst/icons@main/svg/postgres-light.svg", resolved.IconLightURL)
+ require.Equal(t, "https://cdn.jsdelivr.net/gh/selfhst/icons@main/svg/postgres-dark.svg", resolved.IconDarkURL)
+}
diff --git a/backend/pkg/utils/strings.go b/backend/pkg/utils/strings.go
index 71f5e57d6..c145006fe 100644
--- a/backend/pkg/utils/strings.go
+++ b/backend/pkg/utils/strings.go
@@ -4,6 +4,7 @@ import (
"crypto/rand"
"encoding/base64"
"fmt"
+ "reflect"
"strings"
)
@@ -71,6 +72,15 @@ func AsStringMap(value any) (map[string]any, bool) {
}
return res, len(res) > 0
}
+ // Named map types (e.g. compose-go's types.Labels) don't match the cases above.
+ rv := reflect.ValueOf(value)
+ if rv.Kind() == reflect.Map && rv.Type().Key().Kind() == reflect.String {
+ res := make(map[string]any, rv.Len())
+ for iter := rv.MapRange(); iter.Next(); {
+ res[iter.Key().String()] = iter.Value().Interface()
+ }
+ return res, true
+ }
return nil, false
}