gradle-dcompose-plugin icon indicating copy to clipboard operation
gradle-dcompose-plugin copied to clipboard

Intermittent "Container id not available for service database - has it been started?"

Open AlexCzar opened this issue 3 years ago • 2 comments

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")
	}
}

AlexCzar avatar Sep 01 '21 14:09 AlexCzar

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?

chrisgahlert avatar Sep 01 '21 14:09 chrisgahlert

The testI is declared elsewhere, in DcomposeExtension I'm just configuring it with systemPropertys 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.

AlexCzar avatar Sep 30 '21 15:09 AlexCzar