diff --git a/README.md b/README.md index 310203d..d48e648 100644 --- a/README.md +++ b/README.md @@ -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' diff --git a/src/main/groovy/com/avast/gradle/dockercompose/ComposeSettings.groovy b/src/main/groovy/com/avast/gradle/dockercompose/ComposeSettings.groovy index 5bfa920..9664400 100644 --- a/src/main/groovy/com/avast/gradle/dockercompose/ComposeSettings.groovy +++ b/src/main/groovy/com/avast/gradle/dockercompose/ComposeSettings.groovy @@ -36,6 +36,7 @@ class ComposeSettings { boolean buildBeforeUp = true boolean buildBeforePull = true + boolean waitForTcpPorts = true List tcpPortsToIgnoreWhenWaiting = [] Duration waitAfterTcpProbeFailure = Duration.ofSeconds(1) @@ -43,6 +44,8 @@ class ComposeSettings { Duration waitForTcpPortsDisconnectionProbeTimeout = Duration.ofMillis(1000) Duration waitAfterHealthyStateProbeFailure = Duration.ofSeconds(5) Duration waitForHealthyStateTimeout = Duration.ofMinutes(15) + boolean checkContainersRunning = true + List useComposeFiles = [] boolean captureContainersOutput = false @@ -116,6 +119,7 @@ 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 @@ -123,6 +127,7 @@ class ComposeSettings { r.waitForTcpPortsDisconnectionProbeTimeout = this.waitForTcpPortsDisconnectionProbeTimeout r.waitAfterHealthyStateProbeFailure = this.waitAfterHealthyStateProbeFailure r.waitForHealthyStateTimeout = this.waitForHealthyStateTimeout + r.checkContainersRunning = this.checkContainersRunning r.captureContainersOutput = this.captureContainersOutput 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 d70de22..b2b75aa 100644 --- a/src/main/groovy/com/avast/gradle/dockercompose/tasks/ComposeUp.groovy +++ b/src/main/groovy/com/avast/gradle/dockercompose/tasks/ComposeUp.groovy @@ -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)}") } @@ -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)}") + } } } }