@@ -209,6 +209,9 @@ abstract class ComposeUp extends DefaultTask {
209209 }
210210 }
211211
212+ private static final VOLATILE_STATE_KEYS = [' RunningFor' ]
213+ private static final UNSTABLE_ARRAY_STATE_KEYS = [' Mounts' , ' Ports' , ' Networks' , ' Labels' , ' Publishers' ]
214+
212215 @Internal
213216 protected def getStateForCache () {
214217 String processesAsString = composeExecutor. get(). execute(' ps' , ' --format' , ' json' )
@@ -224,8 +227,8 @@ abstract class ComposeUp extends DefaultTask {
224227 List<Object > transformed = processes. collect {
225228 // Status field contains something like "Up 8 seconds", so we have to strip the duration.
226229 if (it. containsKey(' Status' ) && it.Status . startsWith(' Up ' )) it.Status = ' Up'
227- it . remove( ' RunningFor ' ) // It also contains a duration information.
228- it . remove( ' Labels ' ) // The order of labels is not stable.
230+ VOLATILE_STATE_KEYS . each { key -> it . remove(key) }
231+ UNSTABLE_ARRAY_STATE_KEYS . each { key -> it[key] = parseAndSortStateArray(it[key]) }
229232 it
230233 }
231234 processesState = transformed. join(' \t ' )
@@ -235,6 +238,18 @@ abstract class ComposeUp extends DefaultTask {
235238 processesState + composeExecutor. get(). execute(' config' ) + startedServices. get(). join(' ,' )
236239 }
237240
241+ protected Object parseAndSortStateArray (Object list ) {
242+ if (list instanceof List ) {
243+ // Already provided as a List, no pre-parsing needed
244+ return list. sort { (first , second ) -> first. toString() <=> second. toString() }
245+ } else if (list instanceof String && list. contains(" ," )) {
246+ // Not already a list, but a comma separated string
247+ return list. split(' ,' ). collect { it. trim() }. sort()
248+ } else {
249+ return list
250+ }
251+ }
252+
238253 protected Iterable<ServiceInfo > loadServicesInfo (Iterable<String > servicesNames ) {
239254 // this code is little bit complicated - the aim is to execute `docker inspect` just once (for all the containers)
240255 Map<String , Iterable<String > > serviceToContainersIds = composeExecutor. get(). getContainerIds(servicesNames)
0 commit comments