Skip to content

Commit

Permalink
table with exposed ports printed after composeUp finish
Browse files Browse the repository at this point in the history
Fixes #186
  • Loading branch information
augi committed Feb 14, 2020
1 parent 305cbd2 commit cfb6dcf
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ComposeUp extends DefaultTask {
logger.lifecycle('Cached services infos loaded while \'stopContainers\' is set to \'false\'.')
wasReconnected = true
startCapturing()
printExposedPorts()
return
}
}
Expand Down Expand Up @@ -81,6 +82,7 @@ class ComposeUp extends DefaultTask {
if (settings.waitForTcpPorts) {
waitForOpenTcpPorts(servicesInfos.values())
}
printExposedPorts()
if (!settings.stopContainers) {
settings.serviceInfoCache.set(servicesInfos, getStateForCache())
} else {
Expand All @@ -94,6 +96,29 @@ class ComposeUp extends DefaultTask {
}
}

protected void printExposedPorts() {
if (!servicesInfos.values().any { si -> si.tcpPorts.any() }) {
return
}
int nameMaxLength = Math.max('Name'.length(), servicesInfos.values().collect { it.containerInfos.values().collect { it.instanceName.length() } }.flatten().max())
int containerPortMaxLenght = 'Container Port'.length()
int mappingMaxLength = Math.max('Mapping'.length(), servicesInfos.values().collect { it.containerInfos.values().collect { ci -> ci.tcpPorts.collect { p -> "${ci.host}:${p.value}".length() } } }.flatten().max())
logger.lifecycle('+-' + '-'.multiply(nameMaxLength) + '-+-' + '-'.multiply(containerPortMaxLenght) + '-+-' + '-'.multiply(mappingMaxLength) + '-+')
logger.lifecycle('| Name' + ' '.multiply(nameMaxLength - 'Name'.length()) + ' | Container Port' + ' '.multiply(containerPortMaxLenght - 'Container Port'.length()) + ' | Mapping' + ' '.multiply(mappingMaxLength - 'Mapping'.length()) + ' |')
logger.lifecycle('+-' + '-'.multiply(nameMaxLength) + '-+-' + '-'.multiply(containerPortMaxLenght) + '-+-' + '-'.multiply(mappingMaxLength) + '-+')
servicesInfos.values().forEach { si ->
if (si.containerInfos.values().any { it.tcpPorts.any() }) {
si.containerInfos.values().forEach { ci ->
ci.tcpPorts.entrySet().forEach { p ->
String mapping = "${ci.host}:${p.value}".toString()
logger.lifecycle('| ' + ci.instanceName + ' '.multiply(nameMaxLength - ci.instanceName.length()) + ' | ' + p.key + ' '.multiply(containerPortMaxLenght - p.key.toString().length()) + ' | ' + mapping + ' '.multiply(mappingMaxLength - mapping.length()) + ' |')
}
}
logger.lifecycle('+-' + '-'.multiply(nameMaxLength) + '-+-' + '-'.multiply(containerPortMaxLenght) + '-+-' + '-'.multiply(mappingMaxLength) + '-+')
}
}
}

protected void startCapturing() {
if (settings.captureContainersOutput) {
settings.composeExecutor.captureContainersOutput(logger.&lifecycle)
Expand Down

0 comments on commit cfb6dcf

Please sign in to comment.