Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Compose 2.21.0 returns newline-separated JSONs instead of single JSON array #422

Merged
merged 9 commits into from
Sep 11, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,18 @@ abstract class ComposeUp extends DefaultTask {
String processesAsString = composeExecutor.get().execute('ps', '--format', 'json')
String processesState = processesAsString
try {
// Status field contains something like "Up 8 seconds", so we have to strip the duration.
Object[] processes = new JsonSlurper().parseText(processesAsString)
// Since Docker Compose 2.21.0, the output is not one JSON array but newline-separated JSONs.
Map<String, Object>[] processes
if (processesAsString.startsWith('[')) {
processes = new JsonSlurper().parseText(processesAsString)
} else {
processes = processesAsString.split('\\R').collect { new JsonSlurper().parseText(it) }
}
List<Object> transformed = processes.collect {
if (it.Status.startsWith('Up ')) it.Status = 'Up'
// Status field contains something like "Up 8 seconds", so we have to strip the duration.
if (it.containsKey('Status') && it.Status.startsWith('Up ')) it.Status = 'Up'
it.remove('RunningFor') // It also contains a duration information.
it.remove('Labels') // The order of labels is not stable.
it
}
processesState = transformed.join('\t')
Expand Down