Skip to content

Modern Docker Management, Designed for Everyone

fix: add missing arcane labels for auto updater (#2079)

Kyle Mendelld98d67ca8307
diff --git a/.github/workflows/build-next-images.yml b/.github/workflows/build-next-images.yml
index 0fccb30f6..127068dc8 100644
--- a/.github/workflows/build-next-images.yml
+++ b/.github/workflows/build-next-images.yml
@@ -143,6 +143,7 @@ jobs:
org.opencontainers.image.ref.name=arcane-agent
org.opencontainers.image.title=Arcane Agent
org.opencontainers.image.description=Arcane Agent
+ com.getarcaneapp.arcane=true
com.getarcaneapp.arcane.agent=true
- name: Build and push agent image
diff --git a/.github/workflows/build-pr-images.yml b/.github/workflows/build-pr-images.yml
index f12d9a115..01a16766e 100644
--- a/.github/workflows/build-pr-images.yml
+++ b/.github/workflows/build-pr-images.yml
@@ -62,6 +62,7 @@ jobs:
org.opencontainers.image.ref.name=arcane
org.opencontainers.image.title=Arcane
org.opencontainers.image.description=Modern Docker Management, Made for Everyone
+ com.getarcaneapp.arcane=true
- name: Agent image metadata
id: agent-meta
@@ -81,6 +82,8 @@ jobs:
org.opencontainers.image.ref.name=arcane-agent
org.opencontainers.image.title=Arcane Agent
org.opencontainers.image.description=Arcane Agent
+ com.getarcaneapp.arcane=true
+ com.getarcaneapp.arcane.agent=true
- name: Build and push manager image
uses: depot/build-push-action@v1
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 2a2e0e719..f3f474eb4 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -85,6 +85,7 @@ jobs:
org.opencontainers.image.ref.name=arcane
org.opencontainers.image.title=Arcane
org.opencontainers.image.description=Modern Docker Management, Made for Everyone
+ com.getarcaneapp.arcane=true
- name: Build and push manager image
id: manager-build
@@ -123,6 +124,8 @@ jobs:
org.opencontainers.image.ref.name=arcane-agent
org.opencontainers.image.title=Arcane Agent
org.opencontainers.image.description=Arcane Agent
+ com.getarcaneapp.arcane=true
+ com.getarcaneapp.arcane.agent=true
- name: Build and push agent image
id: agent-build
diff --git a/backend/cli/upgrade/upgrade.go b/backend/cli/upgrade/upgrade.go
index 37eef6b44..42decbaee 100644
--- a/backend/cli/upgrade/upgrade.go
+++ b/backend/cli/upgrade/upgrade.go
@@ -7,9 +7,9 @@ import (
"strings"
"time"
- "github.com/getarcaneapp/arcane/backend/internal/utils/arcaneupdater"
"github.com/getarcaneapp/arcane/backend/internal/utils/docker"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane"
+ libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/updater"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/client"
@@ -53,7 +53,7 @@ func runUpgrade(cmd *cobra.Command, args []string) error {
// This prevents interruption when stopping the target container
ctx := context.Background()
- logFile, err := arcaneupdater.SetupMessageOnlyLogFile("/app/data", "arcane-upgrade", slog.LevelInfo)
+ logFile, err := libupdater.SetupMessageOnlyLogFile("/app/data", "arcane-upgrade", slog.LevelInfo)
if err != nil {
slog.Warn("Failed to setup file logging", "error", err)
} else if logFile != nil {
@@ -151,7 +151,7 @@ func findArcaneContainer(ctx context.Context, dockerClient *client.Client) (cont
}
// New label: com.getarcaneapp.arcane=true
- if arcaneupdater.IsArcaneContainer(labels) {
+ if libupdater.IsArcaneContainer(labels) {
slog.Info("Found Arcane container by label", "id", c.ID[:12], "image", c.Image, "names", c.Names)
return inspect, nil
}
diff --git a/backend/internal/services/system_service.go b/backend/internal/services/system_service.go
index 53c2373fe..4532ab3a1 100644
--- a/backend/internal/services/system_service.go
+++ b/backend/internal/services/system_service.go
@@ -10,8 +10,8 @@ import (
"github.com/getarcaneapp/arcane/backend/internal/database"
"github.com/getarcaneapp/arcane/backend/internal/models"
- "github.com/getarcaneapp/arcane/backend/internal/utils/arcaneupdater"
"github.com/getarcaneapp/arcane/backend/internal/utils/converter"
+ libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/updater"
containertypes "github.com/getarcaneapp/arcane/types/container"
"github.com/getarcaneapp/arcane/types/system"
"github.com/goccy/go-yaml"
@@ -257,7 +257,7 @@ func (s *SystemService) StopAllContainers(ctx context.Context) (*containertypes.
return s.performBatchContainerAction(ctx, containers, "stop",
func(c container.Summary) bool {
// Skip Arcane container
- return !arcaneupdater.IsArcaneContainer(c.Labels)
+ return !libupdater.IsArcaneContainer(c.Labels)
},
func(ctx context.Context, id string) error {
return s.containerService.StopContainer(ctx, id, systemUser)
diff --git a/backend/internal/services/system_upgrade_service.go b/backend/internal/services/system_upgrade_service.go
index f1372e26c..22ca47862 100644
--- a/backend/internal/services/system_upgrade_service.go
+++ b/backend/internal/services/system_upgrade_service.go
@@ -14,6 +14,7 @@ import (
dockerutils "github.com/getarcaneapp/arcane/backend/internal/utils/docker"
"github.com/getarcaneapp/arcane/backend/internal/utils/timeouts"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane"
+ libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/updater"
containertypes "github.com/moby/moby/api/types/container"
mounttypes "github.com/moby/moby/api/types/mount"
"github.com/moby/moby/client"
@@ -95,10 +96,8 @@ func (s *SystemUpgradeService) TriggerUpgradeViaCLI(ctx context.Context, user mo
// Determine binary path based on container type (agent vs main)
binaryPath := "/app/arcane"
- if currentContainer.Config != nil && currentContainer.Config.Labels != nil {
- if _, isAgent := currentContainer.Config.Labels["com.getarcaneapp.arcane.agent"]; isAgent {
- binaryPath = "/app/arcane-agent"
- }
+ if currentContainer.Config != nil {
+ binaryPath = determineUpgradeBinaryPathInternal(currentContainer.Config.Labels)
}
// Log upgrade event
@@ -211,6 +210,14 @@ func (s *SystemUpgradeService) TriggerUpgradeViaCLI(ctx context.Context, user mo
return nil
}
+func determineUpgradeBinaryPathInternal(labels map[string]string) string {
+ if libupdater.IsArcaneAgentContainer(labels) {
+ return "/app/arcane-agent"
+ }
+
+ return "/app/arcane"
+}
+
// getCurrentContainerID detects if we're running in Docker and returns container ID
func (s *SystemUpgradeService) getCurrentContainerID() (string, error) {
id, err := dockerutils.GetCurrentContainerID()
diff --git a/backend/internal/services/system_upgrade_service_test.go b/backend/internal/services/system_upgrade_service_test.go
index 0f35d0b02..92d97fd11 100644
--- a/backend/internal/services/system_upgrade_service_test.go
+++ b/backend/internal/services/system_upgrade_service_test.go
@@ -3,6 +3,7 @@ package services
import (
"testing"
+ libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/updater"
"github.com/stretchr/testify/require"
)
@@ -150,3 +151,36 @@ func TestSystemUpgradeService_AtomicOperations(t *testing.T) {
require.False(t, old)
require.True(t, s.upgrading.Load())
}
+
+func TestDetermineUpgradeBinaryPath(t *testing.T) {
+ tests := []struct {
+ name string
+ labels map[string]string
+ want string
+ }{
+ {
+ name: "agent container uses agent binary",
+ labels: map[string]string{
+ libupdater.LabelArcaneAgent: "true",
+ },
+ want: "/app/arcane-agent",
+ },
+ {
+ name: "main container uses main binary",
+ labels: map[string]string{
+ libupdater.LabelArcane: "true",
+ },
+ want: "/app/arcane",
+ },
+ {
+ name: "no labels defaults to main binary",
+ want: "/app/arcane",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ require.Equal(t, tt.want, determineUpgradeBinaryPathInternal(tt.labels))
+ })
+ }
+}
diff --git a/backend/internal/services/updater_service.go b/backend/internal/services/updater_service.go
index 647829574..450ddbce9 100644
--- a/backend/internal/services/updater_service.go
+++ b/backend/internal/services/updater_service.go
@@ -19,9 +19,9 @@ import (
"github.com/getarcaneapp/arcane/backend/internal/database"
"github.com/getarcaneapp/arcane/backend/internal/models"
- "github.com/getarcaneapp/arcane/backend/internal/utils/arcaneupdater"
arcRegistry "github.com/getarcaneapp/arcane/backend/internal/utils/registry"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane"
+ libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/updater"
projectspkg "github.com/getarcaneapp/arcane/backend/pkg/projects"
"github.com/getarcaneapp/arcane/types/updater"
)
@@ -38,13 +38,17 @@ type UpdaterService struct {
eventService *EventService
imageService *ImageService
notificationService *NotificationService
- upgradeService *SystemUpgradeService
+ upgradeService selfUpgradeService
statusMu sync.RWMutex
updatingContainers map[string]bool
updatingProjects map[string]bool
}
+type selfUpgradeService interface {
+ TriggerUpgradeViaCLI(ctx context.Context, user models.User) error
+}
+
// NewUpdaterService constructs an UpdaterService with the dependencies needed
// to plan, execute, and record container and project updates.
func NewUpdaterService(
@@ -57,7 +61,7 @@ func NewUpdaterService(
events *EventService,
imageSvc *ImageService,
notifications *NotificationService,
- upgrade *SystemUpgradeService,
+ upgrade selfUpgradeService,
) *UpdaterService {
return &UpdaterService{
db: db,
@@ -158,7 +162,7 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*update
if err != nil {
return nil, fmt.Errorf("docker connect: %w", err)
}
- digestChecker := arcaneupdater.NewDigestChecker(dcli, s.registryService)
+ digestChecker := libupdater.NewDigestChecker(dcli, s.registryService)
// track all old image IDs we saw for pulled updates so we can prune them after restart
oldIDSet := map[string]struct{}{}
@@ -438,7 +442,7 @@ func (s *UpdaterService) UpdateSingleContainer(ctx context.Context, containerID
labels = inspectBefore.Config.Labels
}
- isArcaneContainer := arcaneupdater.IsArcaneContainer(labels)
+ isArcaneContainer := libupdater.IsArcaneContainer(labels)
slog.InfoContext(ctx, "UpdateSingleContainer: inspected container",
"containerID", containerID,
"imageID", inspectBefore.Image,
@@ -450,7 +454,7 @@ func (s *UpdaterService) UpdateSingleContainer(ctx context.Context, containerID
endProjectStatus := s.beginProjectUpdateInternal(composeProjectNameFromLabelsInternal(labels))
defer endProjectStatus()
- if arcaneupdater.IsUpdateDisabled(labels) {
+ if libupdater.IsUpdateDisabled(labels) {
slog.InfoContext(ctx, "UpdateSingleContainer: updates disabled by label", "containerID", containerID)
out.Items = append(out.Items, updater.ResourceResult{
ResourceID: targetContainer.ID,
@@ -526,7 +530,7 @@ func (s *UpdaterService) UpdateSingleContainer(ctx context.Context, containerID
// Compare with pulled image to avoid unnecessary restart.
// digestResolver is intentionally nil: CompareWithPulled only inspects local
// images and does not need remote registry access.
- checker := arcaneupdater.NewDigestChecker(dcli, nil)
+ checker := libupdater.NewDigestChecker(dcli, nil)
changed, cmpErr := checker.CompareWithPulled(ctx, inspectBefore.Image, normalizedRef)
slog.InfoContext(ctx, "UpdateSingleContainer: digest comparison",
"containerID", containerID,
@@ -560,16 +564,14 @@ func (s *UpdaterService) UpdateSingleContainer(ctx context.Context, containerID
containerLabels = inspect.Config.Labels
}
- if arcaneupdater.IsArcaneContainer(containerLabels) && s.upgradeService != nil {
- slog.InfoContext(ctx, "UpdateSingleContainer: detected Arcane self-update, using CLI upgrade method", "containerID", containerID)
-
- if err := s.upgradeService.TriggerUpgradeViaCLI(ctx, systemUser); err != nil {
+ if libupdater.IsArcaneContainer(containerLabels) {
+ if err := s.triggerSelfUpdateViaCLIInternal(ctx, "UpdateSingleContainer", containerID, containerName, containerLabels); err != nil {
out.Items = append(out.Items, updater.ResourceResult{
ResourceID: targetContainer.ID,
ResourceType: "container",
ResourceName: containerName,
Status: "failed",
- Error: fmt.Sprintf("CLI upgrade failed: %v", err),
+ Error: err.Error(),
})
out.Failed++
out.Duration = time.Since(start).String()
@@ -707,7 +709,7 @@ func (s *UpdaterService) updateContainer(ctx context.Context, cnt container.Summ
name := s.getContainerName(cnt)
labels := inspect.Config.Labels
- isArcane := arcaneupdater.IsArcaneContainer(labels)
+ isArcane := libupdater.IsArcaneContainer(labels)
// Arcane containers should always use CLI upgrade, not inline update
// This method should not be called for Arcane containers
@@ -721,7 +723,7 @@ func (s *UpdaterService) updateContainer(ctx context.Context, cnt container.Summ
originalName := inspect.Name
// Get custom stop signal if configured
- stopSignal := arcaneupdater.GetStopSignal(labels)
+ stopSignal := libupdater.GetStopSignal(labels)
stopOpts := client.ContainerStopOptions{}
if stopSignal != "" {
stopOpts.Signal = stopSignal
@@ -904,7 +906,7 @@ func (s *UpdaterService) collectUsedImagesFromContainersInternal(ctx context.Con
list := listResult.Items
slog.DebugContext(ctx, "collectUsedImagesFromContainersInternal: container list fetched", "count", len(list))
for _, c := range list {
- if arcaneupdater.IsUpdateDisabled(c.Labels) {
+ if libupdater.IsUpdateDisabled(c.Labels) {
slog.DebugContext(ctx, "collectUsedImagesFromContainersInternal: container opted out by labels", "containerId", c.ID)
continue
}
@@ -921,7 +923,7 @@ func (s *UpdaterService) collectUsedImagesFromContainersInternal(ctx context.Con
continue
}
inspect := inspectResult.Container
- if inspect.Config != nil && arcaneupdater.IsUpdateDisabled(inspect.Config.Labels) {
+ if inspect.Config != nil && libupdater.IsUpdateDisabled(inspect.Config.Labels) {
slog.DebugContext(ctx, "collectUsedImagesFromContainersInternal: container inspect labels opted out", "containerId", c.ID)
continue
}
@@ -1033,7 +1035,7 @@ func (s *UpdaterService) collectUsedImagesFromComposeContainersInternal(composeC
if _, isActive := activeProjectNames[projectName]; !isActive {
continue
}
- if arcaneupdater.IsUpdateDisabled(c.Labels) {
+ if libupdater.IsUpdateDisabled(c.Labels) {
continue
}
@@ -1133,7 +1135,7 @@ func (s *UpdaterService) resolveLocalImageIDsForRef(ctx context.Context, ref str
}
// digestResolver is intentionally nil: GetImageIDsForRef only inspects local images.
- checker := arcaneupdater.NewDigestChecker(dcli, nil)
+ checker := libupdater.NewDigestChecker(dcli, nil)
ids, err := checker.GetImageIDsForRef(ctx, ref)
if err != nil {
return nil, err
@@ -1182,7 +1184,7 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldID
plansByName := map[string]*restartPlan{}
markedForRestart := map[string]bool{}
- containersWithDeps := make([]arcaneupdater.ContainerWithDeps, 0, len(list))
+ containersWithDeps := make([]libupdater.ContainerWithDeps, 0, len(list))
// Cache resolved IDs for newRefs to avoid repeated API calls
targetImageIDs := map[string][]string{}
@@ -1203,7 +1205,7 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldID
}
// Skip containers with opt-out label
- if arcaneupdater.IsUpdateDisabled(c.Labels) {
+ if libupdater.IsUpdateDisabled(c.Labels) {
continue
}
@@ -1213,7 +1215,7 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldID
}
name := s.getContainerName(c)
- containersWithDeps = append(containersWithDeps, arcaneupdater.ContainerWithDeps{
+ containersWithDeps = append(containersWithDeps, libupdater.ContainerWithDeps{
Container: c,
Name: name,
})
@@ -1253,7 +1255,7 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldID
continue
}
inspect := inspectResult.Container
- containersWithDeps[i] = arcaneupdater.ExtractContainerDeps(ctx, dcli, cwd.Container, inspect)
+ containersWithDeps[i] = libupdater.ExtractContainerDeps(ctx, dcli, cwd.Container, inspect)
if p, ok := plansByName[containersWithDeps[i].Name]; ok {
inspectCopy := inspect
@@ -1264,7 +1266,7 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldID
// Propagate implicit restarts: if a dependency is restarting, restart dependents too.
for {
- added := arcaneupdater.UpdateImplicitRestart(containersWithDeps, markedForRestart)
+ added := libupdater.UpdateImplicitRestart(containersWithDeps, markedForRestart)
if len(added) == 0 {
break
}
@@ -1285,14 +1287,14 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldID
}
// Build the set of containers that will be restarted and sort them by dependency order.
- candidates := make([]arcaneupdater.ContainerWithDeps, 0, len(containersWithDeps))
+ candidates := make([]libupdater.ContainerWithDeps, 0, len(containersWithDeps))
for _, cd := range containersWithDeps {
if markedForRestart[cd.Name] {
candidates = append(candidates, cd)
}
}
- sorter := arcaneupdater.NewContainerSorter(candidates)
+ sorter := libupdater.NewContainerSorter(candidates)
sorted, sortErr := sorter.Sort()
_, _ = sorter.SortReverse() // keep method used; reverse order may be useful for future stop-first flows
if sortErr != nil {
@@ -1354,14 +1356,11 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldID
endProjectStatus := s.beginProjectUpdateInternal(composeProjectNameFromLabelsInternal(labels))
defer endProjectStatus()
- // Check if this is Arcane self-update - use CLI upgrade instead
- if arcaneupdater.IsArcaneContainer(labels) && s.upgradeService != nil {
- slog.InfoContext(ctx, "restartContainersUsingOldIDs: detected Arcane self-update, using CLI upgrade method", "containerId", p.cnt.ID, "container", name)
-
- if err := s.upgradeService.TriggerUpgradeViaCLI(ctx, systemUser); err != nil {
+ // Arcane self-updates must go through the detached CLI upgrader.
+ if libupdater.IsArcaneContainer(labels) {
+ if err := s.triggerSelfUpdateViaCLIInternal(ctx, "restartContainersUsingOldIDs", p.cnt.ID, name, labels); err != nil {
res.Status = "failed"
- res.Error = fmt.Sprintf("CLI upgrade failed: %v", err)
- slog.WarnContext(ctx, "restartContainersUsingOldIDs: CLI upgrade failed", "containerId", p.cnt.ID, "err", err)
+ res.Error = err.Error()
} else {
res.Status = "updated"
res.UpdateAvailable = true
@@ -1392,6 +1391,44 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldID
return results, nil
}
+func (s *UpdaterService) triggerSelfUpdateViaCLIInternal(ctx context.Context, source, containerID, containerName string, labels map[string]string) error {
+ if !libupdater.IsArcaneContainer(labels) {
+ return fmt.Errorf("%s: container is not an Arcane self-update target", source)
+ }
+
+ instanceType := "server"
+ if libupdater.IsArcaneAgentContainer(labels) {
+ instanceType = "agent"
+ }
+
+ if s.upgradeService == nil {
+ err := fmt.Errorf("%s self-update requires CLI upgrade service", instanceType)
+ slog.ErrorContext(ctx, source+": missing CLI upgrade service for Arcane self-update",
+ "containerId", containerID,
+ "container", containerName,
+ "instanceType", instanceType,
+ "err", err)
+ return err
+ }
+
+ slog.InfoContext(ctx, source+": detected Arcane self-update, using CLI upgrade method",
+ "containerId", containerID,
+ "container", containerName,
+ "instanceType", instanceType)
+
+ if err := s.upgradeService.TriggerUpgradeViaCLI(ctx, systemUser); err != nil {
+ wrappedErr := fmt.Errorf("CLI upgrade failed: %w", err)
+ slog.WarnContext(ctx, source+": CLI upgrade failed",
+ "containerId", containerID,
+ "container", containerName,
+ "instanceType", instanceType,
+ "err", err)
+ return wrappedErr
+ }
+
+ return nil
+}
+
func (s *UpdaterService) beginContainerUpdateInternal(containerID string) func() {
containerID = strings.TrimSpace(containerID)
if containerID == "" {
diff --git a/backend/internal/services/updater_service_test.go b/backend/internal/services/updater_service_test.go
index 97b411cb9..c14840594 100644
--- a/backend/internal/services/updater_service_test.go
+++ b/backend/internal/services/updater_service_test.go
@@ -18,7 +18,7 @@ import (
"gorm.io/gorm"
"github.com/getarcaneapp/arcane/backend/internal/models"
- "github.com/getarcaneapp/arcane/backend/internal/utils/arcaneupdater"
+ libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/updater"
)
// mockSystemUpgradeService is a simple mock implementation for testing
@@ -54,7 +54,7 @@ func TestUpdaterService_ArcaneLabel_TriggersCLIUpgrade(t *testing.T) {
}
// Verify that IsArcaneContainer correctly identifies the label
- isArcane := arcaneupdater.IsArcaneContainer(labels)
+ isArcane := libupdater.IsArcaneContainer(labels)
assert.True(t, isArcane, "IsArcaneContainer should return true for Arcane label")
// Simulate the logic from restartContainersUsingOldIDs:
@@ -67,6 +67,23 @@ func TestUpdaterService_ArcaneLabel_TriggersCLIUpgrade(t *testing.T) {
assert.True(t, mockUpgrade.triggerCalled, "TriggerUpgradeViaCLI should have been called for Arcane container")
}
+func TestUpdaterService_ArcaneAgentLabel_TriggersCLIUpgrade(t *testing.T) {
+ ctx := context.Background()
+ mockUpgrade := &mockSystemUpgradeService{}
+ service := &UpdaterService{upgradeService: mockUpgrade}
+
+ labels := map[string]string{
+ libupdater.LabelArcaneAgent: "true",
+ }
+
+ err := service.triggerSelfUpdateViaCLIInternal(ctx, "test", "container-1", "arcane-agent", labels)
+
+ require.NoError(t, err)
+ assert.True(t, mockUpgrade.triggerCalled, "TriggerUpgradeViaCLI should have been called for Arcane agent container")
+ assert.NotNil(t, mockUpgrade.capturedUser)
+ assert.Equal(t, systemUser.ID, mockUpgrade.capturedUser.ID)
+}
+
// TestUpdaterService_NonArcaneLabel_DoesNotTriggerCLI verifies that containers without
// the Arcane label do not trigger CLI upgrade
func TestUpdaterService_NonArcaneLabel_DoesNotTriggerCLI(t *testing.T) {
@@ -81,7 +98,7 @@ func TestUpdaterService_NonArcaneLabel_DoesNotTriggerCLI(t *testing.T) {
}
// Verify that IsArcaneContainer returns false
- isArcane := arcaneupdater.IsArcaneContainer(labels)
+ isArcane := libupdater.IsArcaneContainer(labels)
assert.False(t, isArcane, "IsArcaneContainer should return false for non-Arcane container")
// Simulate the logic from restartContainersUsingOldIDs
@@ -93,6 +110,22 @@ func TestUpdaterService_NonArcaneLabel_DoesNotTriggerCLI(t *testing.T) {
assert.False(t, mockUpgrade.triggerCalled, "TriggerUpgradeViaCLI should not have been called for non-Arcane container")
}
+func TestUpdaterService_TriggerSelfUpdateViaCLI_NonArcaneContainer(t *testing.T) {
+ ctx := context.Background()
+ mockUpgrade := &mockSystemUpgradeService{}
+ service := &UpdaterService{upgradeService: mockUpgrade}
+
+ labels := map[string]string{
+ "some.other.label": "true",
+ }
+
+ err := service.triggerSelfUpdateViaCLIInternal(ctx, "test", "container-1", "not-arcane", labels)
+
+ require.Error(t, err)
+ assert.Contains(t, err.Error(), "container is not an Arcane self-update target")
+ assert.False(t, mockUpgrade.triggerCalled, "non-Arcane containers must not trigger the CLI upgrade path")
+}
+
// TestUpdaterService_ArcaneLabelWithError_PropagatesError verifies that CLI upgrade errors
// are properly propagated
func TestUpdaterService_ArcaneLabelWithError_PropagatesError(t *testing.T) {
@@ -108,7 +141,7 @@ func TestUpdaterService_ArcaneLabelWithError_PropagatesError(t *testing.T) {
"com.getarcaneapp.arcane": "true",
}
- isArcane := arcaneupdater.IsArcaneContainer(labels)
+ isArcane := libupdater.IsArcaneContainer(labels)
assert.True(t, isArcane, "Should detect Arcane container")
// Call the upgrade method
@@ -126,19 +159,31 @@ func TestUpdaterService_ArcaneLabelWithError_PropagatesError(t *testing.T) {
// TestUpdaterService_NilUpgradeService_GracefulHandling verifies graceful handling
// when upgrade service is nil
func TestUpdaterService_NilUpgradeService_GracefulHandling(t *testing.T) {
- var mockUpgrade *mockSystemUpgradeService = nil
+ ctx := context.Background()
+ service := &UpdaterService{}
labels := map[string]string{
- "com.getarcaneapp.arcane": "true",
+ libupdater.LabelArcane: "true",
}
- isArcane := arcaneupdater.IsArcaneContainer(labels)
- assert.True(t, isArcane, "Should detect Arcane container")
+ err := service.triggerSelfUpdateViaCLIInternal(ctx, "test", "container-1", "arcane", labels)
- // When upgradeService is nil, ensure we don't attempt to call it.
- assert.Nil(t, mockUpgrade, "Upgrade service should be nil; should not attempt to call it")
+ require.Error(t, err)
+ assert.Contains(t, err.Error(), "server self-update requires CLI upgrade service")
+}
+
+func TestUpdaterService_ArcaneAgentLabel_MissingUpgradeServiceReturnsError(t *testing.T) {
+ ctx := context.Background()
+ service := &UpdaterService{}
+
+ labels := map[string]string{
+ libupdater.LabelArcaneAgent: "true",
+ }
- // Test passes if no panic occurs
+ err := service.triggerSelfUpdateViaCLIInternal(ctx, "test", "container-1", "arcane-agent", labels)
+
+ require.Error(t, err)
+ assert.Contains(t, err.Error(), "agent self-update requires CLI upgrade service")
}
// TestUpdaterService_ArcaneLabelVariations tests various label formats
@@ -189,7 +234,7 @@ func TestUpdaterService_ArcaneLabelVariations(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- isArcane := arcaneupdater.IsArcaneContainer(tt.labels)
+ isArcane := libupdater.IsArcaneContainer(tt.labels)
assert.Equal(t, tt.expectedArcane, isArcane, tt.description)
})
}
@@ -205,7 +250,7 @@ func TestUpdaterService_CLICalledWithSystemUser(t *testing.T) {
"com.getarcaneapp.arcane": "true",
}
- isArcane := arcaneupdater.IsArcaneContainer(labels)
+ isArcane := libupdater.IsArcaneContainer(labels)
assert.True(t, isArcane)
if isArcane {
@@ -229,7 +274,7 @@ func TestUpdaterService_UpgradeServiceNotNilCheck(t *testing.T) {
// Test with non-nil upgrade service
mockUpgrade := &mockSystemUpgradeService{}
- isArcane := arcaneupdater.IsArcaneContainer(labels)
+ isArcane := libupdater.IsArcaneContainer(labels)
// This is the actual logic from restartContainersUsingOldIDs
if isArcane {
@@ -545,7 +590,7 @@ func TestCollectUsedImagesFromComposeContainersInternal(t *testing.T) {
Image: "redis:7",
Labels: map[string]string{
"com.docker.compose.project": "myapp",
- arcaneupdater.LabelUpdater: "false",
+ libupdater.LabelUpdater: "false",
},
},
{
diff --git a/backend/internal/services/version_service.go b/backend/internal/services/version_service.go
index ed0a11cbd..84c44499a 100644
--- a/backend/internal/services/version_service.go
+++ b/backend/internal/services/version_service.go
@@ -12,10 +12,10 @@ import (
"github.com/getarcaneapp/arcane/backend/buildables"
"github.com/getarcaneapp/arcane/backend/internal/config"
- "github.com/getarcaneapp/arcane/backend/internal/utils/arcaneupdater"
"github.com/getarcaneapp/arcane/backend/internal/utils/cache"
"github.com/getarcaneapp/arcane/backend/internal/utils/docker"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane"
+ libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/updater"
"github.com/getarcaneapp/arcane/types/version"
containertypes "github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
@@ -331,7 +331,7 @@ func (s *VersionService) detectContainerID(ctx context.Context, dockerClient *cl
// findArcaneContainerByLabel searches for the Arcane container using labels
func (s *VersionService) findArcaneContainerByLabel(ctx context.Context, dockerClient *client.Client) string {
f := make(client.Filters)
- f = f.Add("label", arcaneupdater.LabelArcane+"=true")
+ f = f.Add("label", libupdater.LabelArcane+"=true")
list, err := dockerClient.ContainerList(ctx, client.ContainerListOptions{All: true, Filters: f})
if err != nil {
slog.Debug("findArcaneContainerByLabel: failed to list containers", "error", err)
diff --git a/backend/internal/services/vulnerability_service.go b/backend/internal/services/vulnerability_service.go
index 0ad296d28..7d2039fe0 100644
--- a/backend/internal/services/vulnerability_service.go
+++ b/backend/internal/services/vulnerability_service.go
@@ -22,11 +22,11 @@ import (
cerrdefs "github.com/containerd/errdefs"
"github.com/getarcaneapp/arcane/backend/internal/database"
"github.com/getarcaneapp/arcane/backend/internal/models"
- "github.com/getarcaneapp/arcane/backend/internal/utils/arcaneupdater"
dockerutils "github.com/getarcaneapp/arcane/backend/internal/utils/docker"
"github.com/getarcaneapp/arcane/backend/internal/utils/pagination"
"github.com/getarcaneapp/arcane/backend/internal/utils/timeouts"
"github.com/getarcaneapp/arcane/backend/pkg/libarcane"
+ libupdater "github.com/getarcaneapp/arcane/backend/pkg/libarcane/updater"
"github.com/getarcaneapp/arcane/backend/pkg/utils/stdcopy"
"github.com/getarcaneapp/arcane/types/vulnerability"
containertypes "github.com/moby/moby/api/types/container"
@@ -1739,7 +1739,7 @@ func findArcaneContainerByLabelInternal(ctx context.Context, dockerClient *clien
}
filters := make(client.Filters)
- filters = filters.Add("label", arcaneupdater.LabelArcane+"=true")
+ filters = filters.Add("label", libupdater.LabelArcane+"=true")
containerList, err := dockerClient.ContainerList(ctx, client.ContainerListOptions{
All: true,
diff --git a/backend/internal/utils/arcaneupdater/digest.go b/backend/pkg/libarcane/updater/digest.go
similarity index 99%
rename from backend/internal/utils/arcaneupdater/digest.go
rename to backend/pkg/libarcane/updater/digest.go
index b132f574a..720f04365 100644
--- a/backend/internal/utils/arcaneupdater/digest.go
+++ b/backend/pkg/libarcane/updater/digest.go
@@ -1,4 +1,4 @@
-package arcaneupdater
+package updater
import (
"context"
diff --git a/backend/internal/utils/arcaneupdater/digest_test.go b/backend/pkg/libarcane/updater/digest_test.go
similarity index 98%
rename from backend/internal/utils/arcaneupdater/digest_test.go
rename to backend/pkg/libarcane/updater/digest_test.go
index 5c077cece..7e8eba444 100644
--- a/backend/internal/utils/arcaneupdater/digest_test.go
+++ b/backend/pkg/libarcane/updater/digest_test.go
@@ -1,4 +1,4 @@
-package arcaneupdater
+package updater
import (
"testing"
diff --git a/backend/internal/utils/arcaneupdater/labels.go b/backend/pkg/libarcane/updater/labels.go
similarity index 58%
rename from backend/internal/utils/arcaneupdater/labels.go
rename to backend/pkg/libarcane/updater/labels.go
index 7a8c1d7ef..726b811cb 100644
--- a/backend/internal/utils/arcaneupdater/labels.go
+++ b/backend/pkg/libarcane/updater/labels.go
@@ -1,11 +1,12 @@
-package arcaneupdater
+package updater
import "strings"
const (
// Core labels
- LabelArcane = "com.getarcaneapp.arcane" // Identifies the Arcane container itself
- LabelUpdater = "com.getarcaneapp.arcane.updater" // Enable/disable updates (true/false)
+ LabelArcane = "com.getarcaneapp.arcane" // Identifies the Arcane container itself
+ LabelArcaneAgent = "com.getarcaneapp.arcane.agent" // Identifies an Arcane agent container
+ LabelUpdater = "com.getarcaneapp.arcane.updater" // Enable/disable updates (true/false)
// Dependency labels
LabelDependsOn = "com.getarcaneapp.arcane.depends-on" // Comma-separated list of container names this depends on
@@ -14,18 +15,12 @@ const (
// IsArcaneContainer checks if the container is the Arcane application itself
func IsArcaneContainer(labels map[string]string) bool {
- if labels == nil {
- return false
- }
- for k, v := range labels {
- if strings.EqualFold(k, LabelArcane) {
- switch strings.TrimSpace(strings.ToLower(v)) {
- case "true", "1", "yes", "on":
- return true
- }
- }
- }
- return false
+ return hasTruthyLabelInternal(labels, LabelArcane) || IsArcaneAgentContainer(labels)
+}
+
+// IsArcaneAgentContainer checks if the container is an Arcane agent container.
+func IsArcaneAgentContainer(labels map[string]string) bool {
+ return hasTruthyLabelInternal(labels, LabelArcaneAgent)
}
// IsUpdateDisabled returns true if the special label is present and evaluates to false.
@@ -59,3 +54,26 @@ func GetStopSignal(labels map[string]string) string {
}
return ""
}
+
+func hasTruthyLabelInternal(labels map[string]string, target string) bool {
+ if labels == nil {
+ return false
+ }
+
+ for k, v := range labels {
+ if strings.EqualFold(k, target) && isTruthyLabelValueInternal(v) {
+ return true
+ }
+ }
+
+ return false
+}
+
+func isTruthyLabelValueInternal(v string) bool {
+ switch strings.TrimSpace(strings.ToLower(v)) {
+ case "true", "1", "yes", "on":
+ return true
+ default:
+ return false
+ }
+}
diff --git a/backend/internal/utils/arcaneupdater/labels_test.go b/backend/pkg/libarcane/updater/labels_test.go
similarity index 77%
rename from backend/internal/utils/arcaneupdater/labels_test.go
rename to backend/pkg/libarcane/updater/labels_test.go
index 6dfbe2d9a..3129197e5 100644
--- a/backend/internal/utils/arcaneupdater/labels_test.go
+++ b/backend/pkg/libarcane/updater/labels_test.go
@@ -1,4 +1,4 @@
-package arcaneupdater
+package updater
import (
"testing"
@@ -60,6 +60,21 @@ func TestIsArcaneContainer(t *testing.T) {
labels: map[string]string{"COM.GETARCANEAPP.ARCANE": "true"},
want: true,
},
+ {
+ name: "agent label true",
+ labels: map[string]string{LabelArcaneAgent: "true"},
+ want: true,
+ },
+ {
+ name: "agent label with whitespace",
+ labels: map[string]string{LabelArcaneAgent: " yes "},
+ want: true,
+ },
+ {
+ name: "agent label false",
+ labels: map[string]string{LabelArcaneAgent: "false"},
+ want: false,
+ },
}
for _, tt := range tests {
@@ -71,6 +86,48 @@ func TestIsArcaneContainer(t *testing.T) {
}
}
+func TestIsArcaneAgentContainer(t *testing.T) {
+ tests := []struct {
+ name string
+ labels map[string]string
+ want bool
+ }{
+ {
+ name: "nil labels",
+ labels: nil,
+ want: false,
+ },
+ {
+ name: "agent label true",
+ labels: map[string]string{LabelArcaneAgent: "true"},
+ want: true,
+ },
+ {
+ name: "agent label case insensitive key",
+ labels: map[string]string{"COM.GETARCANEAPP.ARCANE.AGENT": "on"},
+ want: true,
+ },
+ {
+ name: "core arcane label only",
+ labels: map[string]string{LabelArcane: "true"},
+ want: false,
+ },
+ {
+ name: "agent label false",
+ labels: map[string]string{LabelArcaneAgent: "off"},
+ want: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := IsArcaneAgentContainer(tt.labels); got != tt.want {
+ t.Errorf("IsArcaneAgentContainer() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
func TestIsUpdateDisabled(t *testing.T) {
tests := []struct {
name string
diff --git a/backend/internal/utils/arcaneupdater/logfile.go b/backend/pkg/libarcane/updater/logfile.go
similarity index 99%
rename from backend/internal/utils/arcaneupdater/logfile.go
rename to backend/pkg/libarcane/updater/logfile.go
index 31e3ab470..edb1f7049 100644
--- a/backend/internal/utils/arcaneupdater/logfile.go
+++ b/backend/pkg/libarcane/updater/logfile.go
@@ -1,4 +1,4 @@
-package arcaneupdater
+package updater
import (
"context"
diff --git a/backend/internal/utils/arcaneupdater/logfile_test.go b/backend/pkg/libarcane/updater/logfile_test.go
similarity index 99%
rename from backend/internal/utils/arcaneupdater/logfile_test.go
rename to backend/pkg/libarcane/updater/logfile_test.go
index a1039de8f..8b70ebcaf 100644
--- a/backend/internal/utils/arcaneupdater/logfile_test.go
+++ b/backend/pkg/libarcane/updater/logfile_test.go
@@ -1,4 +1,4 @@
-package arcaneupdater
+package updater
import (
"bytes"
diff --git a/backend/internal/utils/arcaneupdater/sorter.go b/backend/pkg/libarcane/updater/sorter.go
similarity index 99%
rename from backend/internal/utils/arcaneupdater/sorter.go
rename to backend/pkg/libarcane/updater/sorter.go
index cb19f34be..3faa16776 100644
--- a/backend/internal/utils/arcaneupdater/sorter.go
+++ b/backend/pkg/libarcane/updater/sorter.go
@@ -1,4 +1,4 @@
-package arcaneupdater
+package updater
import (
"context"
diff --git a/backend/internal/utils/arcaneupdater/sorter_test.go b/backend/pkg/libarcane/updater/sorter_test.go
similarity index 99%
rename from backend/internal/utils/arcaneupdater/sorter_test.go
rename to backend/pkg/libarcane/updater/sorter_test.go
index 068865b23..f98609345 100644
--- a/backend/internal/utils/arcaneupdater/sorter_test.go
+++ b/backend/pkg/libarcane/updater/sorter_test.go
@@ -1,4 +1,4 @@
-package arcaneupdater
+package updater
import (
"testing"