Skip to content

Commit 2cef411

Browse files
authored
loader: path resolution consistency (#425)
Move the project working directory absolute path resolution to `ResolveRelativePaths` and remove redundant local volume (a rarely used way of creating bind mounts) absolute path resolution from the normalization method. Signed-off-by: Milas Bowman <[email protected]>
1 parent a3837e2 commit 2cef411

File tree

4 files changed

+7
-19
lines changed

4 files changed

+7
-19
lines changed

loader/merge_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ func loadTestProject(configDetails types.ConfigDetails) (*types.Project, error)
233233
return Load(configDetails, func(options *Options) {
234234
options.SkipNormalization = true
235235
options.SkipConsistencyCheck = true
236+
options.ResolvePaths = false
236237
})
237238
}
238239

loader/normalize.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package loader
1818

1919
import (
2020
"fmt"
21-
"path/filepath"
2221
"strings"
2322

2423
"github.com/compose-spec/compose-go/errdefs"
@@ -29,13 +28,6 @@ import (
2928

3029
// Normalize compose project by moving deprecated attributes to their canonical position and injecting implicit defaults
3130
func Normalize(project *types.Project) error {
32-
// TODO(milas): this really belongs in ResolveRelativePaths
33-
absWorkingDir, err := filepath.Abs(project.WorkingDir)
34-
if err != nil {
35-
return err
36-
}
37-
project.WorkingDir = absWorkingDir
38-
3931
if project.Networks == nil {
4032
project.Networks = make(map[string]types.NetworkConfig)
4133
}
@@ -134,14 +126,6 @@ func Normalize(project *types.Project) error {
134126
project.Services[i] = s
135127
}
136128

137-
for name, config := range project.Volumes {
138-
if config.Driver == "local" && config.DriverOpts["o"] == "bind" {
139-
// This is actually a bind mount
140-
config.DriverOpts["device"] = absPath(project.WorkingDir, config.DriverOpts["device"])
141-
project.Volumes[name] = config
142-
}
143-
}
144-
145129
setNameFromKey(project)
146130

147131
return nil

loader/normalize_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package loader
1818

1919
import (
2020
"os"
21-
"path/filepath"
2221
"testing"
2322

2423
"github.com/compose-spec/compose-go/types"
@@ -103,7 +102,6 @@ func TestNormalizeVolumes(t *testing.T) {
103102
},
104103
}
105104

106-
absCwd, _ := filepath.Abs(".")
107105
expected := types.Project{
108106
Name: "myProject",
109107
Networks: types.Networks{"default": {Name: "myProject_default"}},
@@ -117,7 +115,6 @@ func TestNormalizeVolumes(t *testing.T) {
117115
Name: "CustomName",
118116
},
119117
},
120-
WorkingDir: absCwd,
121118
}
122119
err := Normalize(&project)
123120
assert.NilError(t, err)

loader/paths.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ import (
2626

2727
// ResolveRelativePaths resolves relative paths based on project WorkingDirectory
2828
func ResolveRelativePaths(project *types.Project) error {
29+
absWorkingDir, err := filepath.Abs(project.WorkingDir)
30+
if err != nil {
31+
return err
32+
}
33+
project.WorkingDir = absWorkingDir
34+
2935
absComposeFiles, err := absComposeFiles(project.ComposeFiles)
3036
if err != nil {
3137
return err

0 commit comments

Comments
 (0)