Skip to content

Commit

Permalink
Merge pull request #15 from userlerueda/fix-depends-on
Browse files Browse the repository at this point in the history
Fix depends_on not working for Long Syntax
  • Loading branch information
apocas authored Feb 28, 2022
2 parents 87fb986 + 7fa75a8 commit 0a2e154
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ module.exports = {
while (order.length !== serviceNames.length) {
for (var serviceName of serviceNames) {
if (order.indexOf(serviceName) === -1) {
insertService(serviceName, recipe.services[serviceName].depends_on || [], order);
let depends_on = recipe.services[serviceName].depends_on;
if (typeof depends_on === "object" && !Array.isArray(depends_on)) {
// if we are using Long Syntax https://github.com/compose-spec/compose-spec/blob/master/spec.md#long-syntax-1
// we will need to get keys from object and use them as dependencies
depends_on = Object.keys(depends_on)
}
insertService(serviceName, depends_on || [], order);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions test/assets/depends.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ services:
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress

wordpress6:
depends_on:
db:
condition: service_started
wordpress2:
condition: service_started
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress

db:
image: mysql:5.7
volumes:
Expand Down
1 change: 1 addition & 0 deletions test/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('tools', function () {
'db',
'wordpress1',
'wordpress2',
'wordpress6',
'wordpress4',
'wordpress5'
]);
Expand Down

0 comments on commit 0a2e154

Please sign in to comment.