Skip to content

Commit 97822e0

Browse files
authored
Merge pull request #195 from compose-spec/build-dockerfile-relativepath
2 parents 280b0dc + 704b2c4 commit 97822e0

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

loader/normalize.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func normalize(project *types.Project, resolvePaths bool) error {
4141
}
4242
project.ComposeFiles = absComposeFiles
4343

44+
if project.Networks == nil {
45+
project.Networks = make(map[string]types.NetworkConfig)
46+
}
47+
4448
// If not declared explicitly, Compose model involves an implicit "default" network
4549
if _, ok := project.Networks["default"]; !ok {
4650
project.Networks["default"] = types.NetworkConfig{}
@@ -74,7 +78,6 @@ func normalize(project *types.Project, resolvePaths bool) error {
7478
if _, err := os.Stat(localContext); err == nil {
7579
if resolvePaths {
7680
s.Build.Context = localContext
77-
s.Build.Dockerfile = absPath(localContext, s.Build.Dockerfile)
7881
}
7982
} else {
8083
// might be a remote http/git context. Unfortunately supported "remote" syntax is highly ambiguous

loader/normalize_test.go

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

1919
import (
20+
"fmt"
2021
"os"
2122
"path/filepath"
2223
"testing"
@@ -87,6 +88,41 @@ networks:
8788
assert.DeepEqual(t, expected, string(marshal))
8889
}
8990

91+
func TestNormalizeResolvePathsBuildContextPaths(t *testing.T) {
92+
wd, _ := os.Getwd()
93+
project := types.Project{
94+
Name: "myProject",
95+
WorkingDir: wd,
96+
Services: []types.ServiceConfig{
97+
{
98+
Name: "foo",
99+
Build: &types.BuildConfig{
100+
Context: "./testdata",
101+
Dockerfile: "Dockerfile-sample",
102+
},
103+
Scale: 1,
104+
},
105+
},
106+
}
107+
108+
expected := fmt.Sprintf(`services:
109+
foo:
110+
build:
111+
context: %s
112+
dockerfile: Dockerfile-sample
113+
networks:
114+
default: null
115+
networks:
116+
default:
117+
name: myProject_default
118+
`, filepath.Join(wd, "testdata"))
119+
err := normalize(&project, true)
120+
assert.NilError(t, err)
121+
marshal, err := yaml.Marshal(project)
122+
assert.NilError(t, err)
123+
assert.DeepEqual(t, expected, string(marshal))
124+
}
125+
90126
func TestNormalizeAbsolutePaths(t *testing.T) {
91127
project := types.Project{
92128
Name: "myProject",

0 commit comments

Comments
 (0)