Skip to content

Commit

Permalink
Merge pull request #423 from milas/restore-default-context-behavior
Browse files Browse the repository at this point in the history
loader: restore implicit default of `.` for build context
  • Loading branch information
laurazard authored Jun 29, 2023
2 parents 169d13b + 4719844 commit 736df56
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
14 changes: 7 additions & 7 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
Extensions: model.Extensions,
}

if !opts.SkipNormalization {
err = Normalize(project)
if err != nil {
return nil, err
}
}

if opts.ResolvePaths {
err = ResolveRelativePaths(project)
if err != nil {
Expand All @@ -277,13 +284,6 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
}
}

if !opts.SkipNormalization {
err = Normalize(project)
if err != nil {
return nil, err
}
}

if !opts.SkipConsistencyCheck {
err = checkConsistency(project)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,8 @@ func TestLoadWithExtends(t *testing.T) {

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

expectedEnvFilePath := filepath.Join(extendsDir, "extra.env")
expectedEnvFilePath, err := filepath.Abs(filepath.Join(extendsDir, "extra.env"))
assert.NilError(t, err)

expServices := types.Services{
{
Expand Down
7 changes: 5 additions & 2 deletions loader/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

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

err = relocateExternalName(project)
if err != nil {
if err := relocateExternalName(project); err != nil {
return err
}

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

if s.Build != nil {
if s.Build.Context == "" {
s.Build.Context = "."
}
if s.Build.Dockerfile == "" && s.Build.DockerfileInline == "" {
s.Build.Dockerfile = "Dockerfile"
}
Expand Down
14 changes: 14 additions & 0 deletions loader/normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,17 @@ func TestNormalizeImplicitDependencies(t *testing.T) {
assert.NilError(t, err)
assert.DeepEqual(t, expected, project.Services[0].DependsOn)
}

func TestImplicitContextPath(t *testing.T) {
project := &types.Project{
Name: "myProject",
Services: types.Services{
types.ServiceConfig{
Name: "test",
Build: &types.BuildConfig{},
},
},
}
assert.NilError(t, Normalize(project))
assert.Equal(t, ".", project.Services[0].Build.Context)
}

0 comments on commit 736df56

Please sign in to comment.