Skip to content
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
18 changes: 18 additions & 0 deletions loader/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ func checkConsistency(project *types.Project) error { //nolint:gocyclo
}
}
}

mounts := map[string]string{}
for i, tmpfs := range s.Tmpfs {
loc := fmt.Sprintf("services.%s.tmpfs[%d]", s.Name, i)
path, _, _ := strings.Cut(tmpfs, ":")
if p, ok := mounts[path]; ok {
return fmt.Errorf("%s: target %s already mounted as %s", loc, path, p)
}
mounts[path] = loc
}
for i, volume := range s.Volumes {
loc := fmt.Sprintf("services.%s.volumes[%d]", s.Name, i)
if p, ok := mounts[volume.Target]; ok {
return fmt.Errorf("%s: target %s already mounted as %s", loc, volume.Target, p)
}
mounts[volume.Target] = loc
}

}

for name, secret := range project.Secrets {
Expand Down
29 changes: 29 additions & 0 deletions loader/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,32 @@ func TestValidateWatch(t *testing.T) {
assert.ErrorContains(t, err, "depends on undefined service")
})
}

func TestValidateMountConflict(t *testing.T) {
project := &types.Project{
Services: types.Services{
"myservice": {
Name: "myservice",
Image: "scratch",
Tmpfs: []string{
"/foo",
"/conflict:size=64m",
},
Volumes: []types.ServiceVolumeConfig{
{
Type: "bind",
Target: "/bar",
Source: ".",
},
{
Type: "bind",
Target: "/conflict",
Source: ".",
},
},
},
},
}
err := checkConsistency(project)
assert.Error(t, err, "services.myservice.volumes[1]: target /conflict already mounted as services.myservice.tmpfs[1]")
}