Skip to content

Commit

Permalink
feat: checkContainersRunning option added Closes avast#223
Browse files Browse the repository at this point in the history
  • Loading branch information
augi committed Apr 8, 2020
1 parent 57ebef2 commit 6182bad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ dockerCompose {
waitForTcpPortsTimeout = Duration.ofMinutes(15) // how long to wait until all exposed TCP become open; default is 15 minutes
tcpPortsToIgnoreWhenWaiting = [1234] // list of TCP ports what will be ignored when waiting for exposed TCP ports opening; default: empty list
waitForHealthyStateTimeout = Duration.ofMinutes(15) // how long to wait until a container becomes healthy; default is 15 minutes
boolean checkContainersRunning = true // turns on/off checking if container is running (during waiting for open TCP port and healthy state); default is true
captureContainersOutput = false // if true, prints output of all containers to Gradle output - very useful for debugging; default is false
captureContainersOutputToFile = '/path/to/logFile' // sends output of all containers to a log file
captureContainersOutputToFiles = '/path/to/directory' // sends output of all services to a dedicated log file in the directory specified, e.g. 'web.log' for service named 'log'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ class ComposeSettings {

boolean buildBeforeUp = true
boolean buildBeforePull = true

boolean waitForTcpPorts = true
List<Integer> tcpPortsToIgnoreWhenWaiting = []
Duration waitAfterTcpProbeFailure = Duration.ofSeconds(1)
Duration waitForTcpPortsTimeout = Duration.ofMinutes(15)
Duration waitForTcpPortsDisconnectionProbeTimeout = Duration.ofMillis(1000)
Duration waitAfterHealthyStateProbeFailure = Duration.ofSeconds(5)
Duration waitForHealthyStateTimeout = Duration.ofMinutes(15)
boolean checkContainersRunning = true

List<String> useComposeFiles = []

boolean captureContainersOutput = false
Expand Down Expand Up @@ -116,13 +119,15 @@ class ComposeSettings {
def r = new ComposeSettings(project, name)
r.buildBeforeUp = this.buildBeforeUp
r.buildBeforePull = this.buildBeforePull

r.waitForTcpPorts = this.waitForTcpPorts
r.tcpPortsToIgnoreWhenWaiting = new ArrayList<>(this.tcpPortsToIgnoreWhenWaiting)
r.waitAfterTcpProbeFailure = this.waitAfterTcpProbeFailure
r.waitForTcpPortsTimeout = this.waitForTcpPortsTimeout
r.waitForTcpPortsDisconnectionProbeTimeout = this.waitForTcpPortsDisconnectionProbeTimeout
r.waitAfterHealthyStateProbeFailure = this.waitAfterHealthyStateProbeFailure
r.waitForHealthyStateTimeout = this.waitForHealthyStateTimeout
r.checkContainersRunning = this.checkContainersRunning

r.captureContainersOutput = this.captureContainersOutput

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class ComposeUp extends DefaultTask {
logger.debug("Service ${instanceName} or this version of Docker doesn't support healthchecks")
break
}
if (settings.checkContainersRunning && !"running".equalsIgnoreCase(inspectionState.Status)) {
throw new RuntimeException("Container ${containerInfo.containerId} of service ${instanceName} is not running. Logs:${System.lineSeparator()}${settings.dockerExecutor.getContainerLogs(containerInfo.containerId)}")
}
if (start.plus(settings.waitForHealthyStateTimeout) < Instant.now()) {
throw new RuntimeException("Container ${containerInfo.containerId} of service ${instanceName} is still reported as '${healthStatus}'. Logs:${System.lineSeparator()}${settings.dockerExecutor.getContainerLogs(containerInfo.containerId)}")
}
Expand Down Expand Up @@ -235,6 +238,10 @@ class ComposeUp extends DefaultTask {
}
logger.lifecycle("Waiting for TCP socket on ${containerInfo.host}:${forwardedPort} of service '${instanceName}' (${e.message})")
sleep(settings.waitAfterTcpProbeFailure.toMillis())
def inspection = settings.dockerExecutor.getInspection(containerInfo.containerId)
if (settings.checkContainersRunning && !"running".equalsIgnoreCase(inspection.State.Status)) {
throw new RuntimeException("Container ${containerInfo.containerId} of service ${instanceName} is not running. Logs:${System.lineSeparator()}${settings.dockerExecutor.getContainerLogs(containerInfo.containerId)}")
}
}
}
}
Expand Down

0 comments on commit 6182bad

Please sign in to comment.