Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loader: restore implicit default of . for build context #423

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}