@@ -101,7 +101,10 @@ func (s *composeService) create(ctx context.Context, project *types.Project, opt
101
101
}
102
102
}
103
103
104
- prepareServicesDependsOn (project )
104
+ err = prepareServicesDependsOn (project )
105
+ if err != nil {
106
+ return err
107
+ }
105
108
106
109
return newConvergence (options .Services , observedState , s ).apply (ctx , project , options )
107
110
}
@@ -138,28 +141,55 @@ func prepareNetworks(project *types.Project) {
138
141
}
139
142
}
140
143
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
+ }
147
151
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 {
149
174
continue
150
175
}
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 )
153
178
}
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 {
157
186
Condition : types .ServiceConditionStarted ,
158
187
}
159
- continue outLoop
160
188
}
161
189
}
190
+ p .Services [i ] = service
162
191
}
192
+ return nil
163
193
}
164
194
165
195
func (s * composeService ) ensureNetworks (ctx context.Context , networks types.Networks ) error {
0 commit comments