mirror of
https://github.com/docker/compose.git
synced 2025-07-25 22:54:54 +02:00
Merge pull request #9849 from laurazard/fix-volumesfrom-overwriting
Keep `depends_on` condition when service has `volumes_from`
This commit is contained in:
commit
2977f4c897
@ -125,7 +125,8 @@ func prepareVolumes(p *types.Project) error {
|
|||||||
p.Services[i].DependsOn = make(types.DependsOnConfig, len(dependServices))
|
p.Services[i].DependsOn = make(types.DependsOnConfig, len(dependServices))
|
||||||
}
|
}
|
||||||
for _, service := range p.Services {
|
for _, service := range p.Services {
|
||||||
if utils.StringContains(dependServices, service.Name) {
|
if utils.StringContains(dependServices, service.Name) &&
|
||||||
|
p.Services[i].DependsOn[service.Name].Condition == "" {
|
||||||
p.Services[i].DependsOn[service.Name] = types.ServiceDependency{
|
p.Services[i].DependsOn[service.Name] = types.ServiceDependency{
|
||||||
Condition: types.ServiceConditionStarted,
|
Condition: types.ServiceConditionStarted,
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,46 @@ func TestPrepareNetworkLabels(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrepareVolumes(t *testing.T) {
|
||||||
|
t.Run("adds dependency condition if service depends on volume from another service", func(t *testing.T) {
|
||||||
|
project := composetypes.Project{
|
||||||
|
Name: "myProject",
|
||||||
|
Services: []composetypes.ServiceConfig{
|
||||||
|
{
|
||||||
|
Name: "aService",
|
||||||
|
VolumesFrom: []string{"anotherService"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "anotherService",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := prepareVolumes(&project)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, project.Services[0].DependsOn["anotherService"].Condition, composetypes.ServiceConditionStarted)
|
||||||
|
})
|
||||||
|
t.Run("doesn't overwrite existing dependency condition", func(t *testing.T) {
|
||||||
|
project := composetypes.Project{
|
||||||
|
Name: "myProject",
|
||||||
|
Services: []composetypes.ServiceConfig{
|
||||||
|
{
|
||||||
|
Name: "aService",
|
||||||
|
VolumesFrom: []string{"anotherService"},
|
||||||
|
DependsOn: map[string]composetypes.ServiceDependency{
|
||||||
|
"anotherService": {Condition: composetypes.ServiceConditionHealthy},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "anotherService",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := prepareVolumes(&project)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, project.Services[0].DependsOn["anotherService"].Condition, composetypes.ServiceConditionHealthy)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuildContainerMountOptions(t *testing.T) {
|
func TestBuildContainerMountOptions(t *testing.T) {
|
||||||
project := composetypes.Project{
|
project := composetypes.Project{
|
||||||
Name: "myProject",
|
Name: "myProject",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user