Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 4b808e5

Browse files
committed
include volume_from as a source for implicit dependencies
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 9c615dc commit 4b808e5

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

pkg/compose/create.go

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ func (s *composeService) create(ctx context.Context, project *types.Project, opt
101101
}
102102
}
103103

104-
prepareServicesDependsOn(project)
104+
err = prepareServicesDependsOn(project)
105+
if err != nil {
106+
return err
107+
}
105108

106109
return newConvergence(options.Services, observedState, s).apply(ctx, project, options)
107110
}
@@ -138,28 +141,55 @@ func prepareNetworks(project *types.Project) {
138141
}
139142
}
140143

141-
func prepareServicesDependsOn(p *types.Project) {
142-
outLoop:
143-
for i := range p.Services {
144-
networkDependency := getDependentServiceFromMode(p.Services[i].NetworkMode)
145-
ipcDependency := getDependentServiceFromMode(p.Services[i].Ipc)
146-
pidDependency := getDependentServiceFromMode(p.Services[i].Pid)
144+
func prepareServicesDependsOn(p *types.Project) error {
145+
for i, service := range p.Services {
146+
var dependencies []string
147+
networkDependency := getDependentServiceFromMode(service.NetworkMode)
148+
if networkDependency != "" {
149+
dependencies = append(dependencies, networkDependency)
150+
}
147151

148-
if networkDependency == "" && ipcDependency == "" && pidDependency == "" {
152+
ipcDependency := getDependentServiceFromMode(service.Ipc)
153+
if ipcDependency != "" {
154+
dependencies = append(dependencies, ipcDependency)
155+
}
156+
157+
pidDependency := getDependentServiceFromMode(service.Pid)
158+
if pidDependency != "" {
159+
dependencies = append(dependencies, pidDependency)
160+
}
161+
162+
for _, vol := range service.VolumesFrom {
163+
spec := strings.Split(vol, ":")
164+
if len(spec) == 0 {
165+
continue
166+
}
167+
if spec[0] == "container" {
168+
continue
169+
}
170+
dependencies = append(dependencies, spec[0])
171+
}
172+
173+
if len(dependencies) == 0 {
149174
continue
150175
}
151-
if p.Services[i].DependsOn == nil {
152-
p.Services[i].DependsOn = make(types.DependsOnConfig)
176+
if service.DependsOn == nil {
177+
service.DependsOn = make(types.DependsOnConfig)
153178
}
154-
for _, service := range p.Services {
155-
if service.Name == networkDependency || service.Name == ipcDependency || service.Name == pidDependency {
156-
p.Services[i].DependsOn[service.Name] = types.ServiceDependency{
179+
deps, err := p.GetServices(dependencies...)
180+
if err != nil {
181+
return err
182+
}
183+
for _, d := range deps {
184+
if _, ok := service.DependsOn[d.Name]; !ok {
185+
service.DependsOn[d.Name] = types.ServiceDependency{
157186
Condition: types.ServiceConditionStarted,
158187
}
159-
continue outLoop
160188
}
161189
}
190+
p.Services[i] = service
162191
}
192+
return nil
163193
}
164194

165195
func (s *composeService) ensureNetworks(ctx context.Context, networks types.Networks) error {

0 commit comments

Comments
 (0)