Skip to content

Commit 736df56

Browse files
authored
Merge pull request #423 from milas/restore-default-context-behavior
loader: restore implicit default of `.` for build context
2 parents 169d13b + 4719844 commit 736df56

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

loader/loader.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
261261
Extensions: model.Extensions,
262262
}
263263

264+
if !opts.SkipNormalization {
265+
err = Normalize(project)
266+
if err != nil {
267+
return nil, err
268+
}
269+
}
270+
264271
if opts.ResolvePaths {
265272
err = ResolveRelativePaths(project)
266273
if err != nil {
@@ -277,13 +284,6 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
277284
}
278285
}
279286

280-
if !opts.SkipNormalization {
281-
err = Normalize(project)
282-
if err != nil {
283-
return nil, err
284-
}
285-
}
286-
287287
if !opts.SkipConsistencyCheck {
288288
err = checkConsistency(project)
289289
if err != nil {

loader/loader_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,8 @@ func TestLoadWithExtends(t *testing.T) {
19281928

19291929
extendsDir := filepath.Join("testdata", "subdir")
19301930

1931-
expectedEnvFilePath := filepath.Join(extendsDir, "extra.env")
1931+
expectedEnvFilePath, err := filepath.Abs(filepath.Join(extendsDir, "extra.env"))
1932+
assert.NilError(t, err)
19321933

19331934
expServices := types.Services{
19341935
{

loader/normalize.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
// Normalize compose project by moving deprecated attributes to their canonical position and injecting implicit defaults
3131
func Normalize(project *types.Project) error {
32+
// TODO(milas): this really belongs in ResolveRelativePaths
3233
absWorkingDir, err := filepath.Abs(project.WorkingDir)
3334
if err != nil {
3435
return err
@@ -44,8 +45,7 @@ func Normalize(project *types.Project) error {
4445
project.Networks["default"] = types.NetworkConfig{}
4546
}
4647

47-
err = relocateExternalName(project)
48-
if err != nil {
48+
if err := relocateExternalName(project); err != nil {
4949
return err
5050
}
5151

@@ -65,6 +65,9 @@ func Normalize(project *types.Project) error {
6565
}
6666

6767
if s.Build != nil {
68+
if s.Build.Context == "" {
69+
s.Build.Context = "."
70+
}
6871
if s.Build.Dockerfile == "" && s.Build.DockerfileInline == "" {
6972
s.Build.Dockerfile = "Dockerfile"
7073
}

loader/normalize_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,17 @@ func TestNormalizeImplicitDependencies(t *testing.T) {
218218
assert.NilError(t, err)
219219
assert.DeepEqual(t, expected, project.Services[0].DependsOn)
220220
}
221+
222+
func TestImplicitContextPath(t *testing.T) {
223+
project := &types.Project{
224+
Name: "myProject",
225+
Services: types.Services{
226+
types.ServiceConfig{
227+
Name: "test",
228+
Build: &types.BuildConfig{},
229+
},
230+
},
231+
}
232+
assert.NilError(t, Normalize(project))
233+
assert.Equal(t, ".", project.Services[0].Build.Context)
234+
}

0 commit comments

Comments
 (0)