Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: include files incorrectly identified as its own compose file and labeled as such (#2270)
Kyle Mendella66d6593d4a4
diff --git a/backend/pkg/projects/includes.go b/backend/pkg/projects/includes.goindex fa8a43ad4..6035994ee 100644--- a/backend/pkg/projects/includes.go+++ b/backend/pkg/projects/includes.go@@ -119,6 +119,10 @@ func parseIncludeItemInternal(item any, baseDir string, envMap EnvMap) (IncludeFrelativePath = rel}}+ relativePath = filepath.ToSlash(filepath.Clean(relativePath))+ if relativePath == "." {+ relativePath = filepath.Base(fullPath)+ }return IncludeFile{Path: fullPath,diff --git a/backend/pkg/projects/includes_test.go b/backend/pkg/projects/includes_test.goindex 2e147af19..fe4c4c5a6 100644--- a/backend/pkg/projects/includes_test.go+++ b/backend/pkg/projects/includes_test.go@@ -9,6 +9,36 @@ import (pkgutils "github.com/getarcaneapp/arcane/backend/pkg/utils")+func TestParseIncludes_NormalizesRelativePaths(t *testing.T) {+ t.Parallel()++ projectDir := t.TempDir()+ composePath := filepath.Join(projectDir, "compose.yaml")+ includePath := filepath.Join(projectDir, "includes", "config.yaml")++ requireNoError := func(err error) {+ t.Helper()+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ }++ requireNoError(os.MkdirAll(filepath.Dir(includePath), 0o755))+ requireNoError(os.WriteFile(includePath, []byte("services: {}\n"), 0o600))+ requireNoError(os.WriteFile(composePath, []byte("include:\n - ./includes/config.yaml\n"), 0o600))++ includes, err := ParseIncludes(composePath, nil)+ requireNoError(err)++ if len(includes) != 1 {+ t.Fatalf("expected 1 include, got %d", len(includes))+ }++ if includes[0].RelativePath != "includes/config.yaml" {+ t.Fatalf("unexpected relative path: got %q, want %q", includes[0].RelativePath, "includes/config.yaml")+ }+}+func TestWriteIncludeFilePermissions(t *testing.T) {// Save original permsorigFilePerm := pkgutils.FilePermdiff --git a/backend/pkg/projects/load.go b/backend/pkg/projects/load.goindex f51587484..9d9826d4d 100644--- a/backend/pkg/projects/load.go+++ b/backend/pkg/projects/load.go@@ -8,6 +8,7 @@ import ("os""path/filepath""slices"+ "strings""github.com/compose-spec/compose-go/v2/loader"composetypes "github.com/compose-spec/compose-go/v2/types"@@ -117,6 +118,10 @@ func loadComposeProjectInternal(return nil, fmt.Errorf("load compose project: %w", err)}+ for _, configFile := range cfg.ConfigFiles {+ project.ComposeFiles = append(project.ComposeFiles, configFile.Filename)+ }+project = project.WithoutUnnecessaryResources()// Resolve relative paths for bind mounts, secrets, and configs@@ -129,26 +134,24 @@ func loadComposeProjectInternal(}}- injectServiceConfiguration(project, injectionVars, workdir, composeFile)-- project.ComposeFiles = []string{composeFile}+ injectServiceConfiguration(project, injectionVars)return project, nil}-func applyCustomLabelsInternal(projectName string, serviceName string, workingDirectory string, composeFile string) composetypes.Labels {+func applyCustomLabelsInternal(projectName string, serviceName string, workingDirectory string, composeFiles []string) composetypes.Labels {return composetypes.Labels{api.ProjectLabel: projectName,api.ServiceLabel: serviceName,api.VersionLabel: api.ComposeVersion,api.OneoffLabel: "False",api.WorkingDirLabel: workingDirectory,- api.ConfigFilesLabel: composeFile,+ api.ConfigFilesLabel: strings.Join(composeFiles, ","),}}-func injectServiceConfiguration(project *composetypes.Project, injectionVars EnvMap, workdir, composeFile string) {+func injectServiceConfiguration(project *composetypes.Project, injectionVars EnvMap) {for i, s := range project.Services {- s.CustomLabels = applyCustomLabelsInternal(project.Name, s.Name, workdir, composeFile)+ s.CustomLabels = applyCustomLabelsInternal(project.Name, s.Name, project.WorkingDir, project.ComposeFiles)// Initialize environment if nilif s.Environment == nil {diff --git a/backend/pkg/projects/load_test.go b/backend/pkg/projects/load_test.goindex 5d2fd5359..336e96f52 100644--- a/backend/pkg/projects/load_test.go+++ b/backend/pkg/projects/load_test.go@@ -4,8 +4,10 @@ import ("context""os""path/filepath"+ "strings""testing"+ "github.com/docker/compose/v5/pkg/api""github.com/stretchr/testify/assert""github.com/stretchr/testify/require")@@ -92,3 +94,36 @@ func TestLoadComposeProjectFromDir_EmptyProjectsDirectoryDoesNotCreateParentGlob_, statErr := os.Stat(filepath.Join(projectsRoot, "nested", GlobalEnvFileName))assert.ErrorIs(t, statErr, os.ErrNotExist)}++func TestLoadComposeProject_UsesProjectLevelComposeLabelsForIncludedServices(t *testing.T) {+ t.Parallel()++ projectDir := t.TempDir()+ includePath := filepath.Join(projectDir, "included.compose.yaml")+ composePath := filepath.Join(projectDir, "compose.yaml")++ require.NoError(t, os.WriteFile(includePath, []byte(`services:+ included:+ image: nginx:alpine+`), 0o600))+ require.NoError(t, os.WriteFile(composePath, []byte(`include:+ - included.compose.yaml+services:+ root:+ image: busybox:latest+`), 0o600))++ project, err := LoadComposeProject(context.Background(), composePath, "demo", projectDir, false, nil)+ require.NoError(t, err)+ require.NotNil(t, project)++ rootService := project.Services["root"]+ includedService := project.Services["included"]+ expectedConfigFiles := strings.Join(project.ComposeFiles, ",")++ require.Equal(t, []string{composePath}, project.ComposeFiles)+ require.Equal(t, project.WorkingDir, rootService.CustomLabels[api.WorkingDirLabel])+ require.Equal(t, expectedConfigFiles, rootService.CustomLabels[api.ConfigFilesLabel])+ require.Equal(t, project.WorkingDir, includedService.CustomLabels[api.WorkingDirLabel])+ require.Equal(t, expectedConfigFiles, includedService.CustomLabels[api.ConfigFilesLabel])+}