gradle-dcompose-plugin
gradle-dcompose-plugin copied to clipboard
Intermittent "Container id not available for service database - has it been started?"
Intermittent "Container id not available for service database - has it been started?" Gradle: 7.1.1 dcompose: 0.17.2
"database" service configuration:
configure<DcomposeExtension> {
System.getenv("BUILD_NAME")
?.let { DcomposeUtils.sha1Hash(it).substring(0, 8) }
?.run {
namePrefix = "${namePrefix}_$this"
}
networks.clear()
services.register("database") {
image = "postgres:11-alpine"
env = listOf(
"POSTGRES_USER=Test",
"POSTGRES_PASSWORD=Test",
"POSTGRES_DB=Test"
)
portBindings = listOf("5432")
networkMode = "bridge"
waitForHealthcheck = true
healthcheckInterval = 500
healthcheckTimeout = 3500
healthcheckRetries = 10
healthcheckStartPeriod = 10000
healthcheckTest = listOf("CMD-SHELL", "pg_isready -U \$POSTGRES_USER -d \$POSTGRES_DB || exit 1")
}
tasks.named<Test>("testI") {
dependsOn("startDatabaseContainer")
doFirst {
systemProperty("DB_HOST", service("database").dockerHost)
systemProperty(
"DB_PORT", service("database")
.findHostPort(mapOf("hostIp" to "0.0.0.0"), 5432)
)
}
finalizedBy("removeDatabaseContainer")
}
}
Not really sure, what the problem is here... the only thing that seems weird to me is:
You are defining the task testI
inside the DcomposeExtension
block... I'm not really sure, if that might have any side-effects...
The error message itself seems like the task graph is not being executed in the expected order. Could you add some more console log output, where I can see a) the execution order of the tasks and b) which task threw this error?
The testI
is declared elsewhere, in DcomposeExtension
I'm just configuring it with systemProperty
s and adding the dependencies.
The failure looks like this:
> Task :myProject:mySubprojectA:stopDatabaseContainer
> Task :myProject:mySubprojectA:removeDatabaseContainer
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':myProject:mySubprojectB:startDatabaseContainer'.
> Container id not available for service database - has it been started?
So execution order seems to be fine. Additionally, sometimes failure doesn't happen at all, sometimes it happens in a random subprojeсt. Also, upgraded gradle to 7.2, made no difference.