diff --git a/src/main/groovy/com/avast/gradle/dockercompose/ComposeExecutor.groovy b/src/main/groovy/com/avast/gradle/dockercompose/ComposeExecutor.groovy index 79ceec8..5fcd552 100644 --- a/src/main/groovy/com/avast/gradle/dockercompose/ComposeExecutor.groovy +++ b/src/main/groovy/com/avast/gradle/dockercompose/ComposeExecutor.groovy @@ -130,15 +130,20 @@ abstract class ComposeExecutor implements BuildService, AutoCloseabl cachedVersion = VersionNumber.parse(rawVersion.startsWith('v') ? rawVersion.substring(1) : rawVersion) } - Iterable getContainerIds(String serviceName) { + Map> getContainerIds(List serviceNames) { // `docker-compose ps -q serviceName` returns an exit code of 1 when the service // doesn't exist. To guard against this, check the service list first. def services = execute('ps', '--services').readLines() - if (services.contains(serviceName)) { - return execute('ps', '-q', serviceName).readLines() + def result = [:] + for (String serviceName: serviceNames) { + if (services.contains(serviceName)) { + def containerIds = execute('ps', '-q', serviceName).readLines() + result[serviceName] = containerIds + } else { + result[serviceName] = [] + } } - - return [] + return result } private Set> threadsToInterruptOnClose = ConcurrentHashMap.newKeySet() diff --git a/src/main/groovy/com/avast/gradle/dockercompose/tasks/ComposeUp.groovy b/src/main/groovy/com/avast/gradle/dockercompose/tasks/ComposeUp.groovy index aaefedb..c57dfaa 100644 --- a/src/main/groovy/com/avast/gradle/dockercompose/tasks/ComposeUp.groovy +++ b/src/main/groovy/com/avast/gradle/dockercompose/tasks/ComposeUp.groovy @@ -215,7 +215,7 @@ abstract class ComposeUp extends DefaultTask { protected Iterable loadServicesInfo(Iterable servicesNames) { // this code is little bit complicated - the aim is to execute `docker inspect` just once (for all the containers) - Map> serviceToContainersIds = servicesNames.collectEntries { [(it) : composeExecutor.get().getContainerIds(it)] } + Map> serviceToContainersIds = composeExecutor.get().getContainerIds(servicesNames) Map> inspections = dockerExecutor.getInspections(*serviceToContainersIds.values().flatten().unique()) serviceToContainersIds.collect { pair -> new ServiceInfo(name: pair.key, containerInfos: pair.value.collect { createContainerInfo(inspections.get(it), pair.key) }.collectEntries { [(it.instanceName): it] } ) } }