Issue
I have the following issue.
In order to speed up the integration test pipeline I want to run testcontainers
with Quarkus
with TMPFS
option set. This will force testcontainers to run the DB with a in-memory file system.
This can be easily done according to testcontainers
website like this ...
To pass this option to the container, add TC_TMPFS parameter to the URL as follows: jdbc:tc:postgresql:9.6.8:///databasename?TC_TMPFS=/testtmpfs:rw
Seems like problem solved. This is how it should work with Spring Boot
However, with Quarkus
in their docs it says the following ...
All services based on containers are ran using testcontainers. Even though extra URL properties can be set in your application.properties file, specific testcontainers properties such as TC_INITSCRIPT, TC_INITFUNCTION, TC_DAEMON, TC_TMPFS are not supported.
And my question is:
How can you work around this ? How can I run my testcontainer which will be mounted on TMPFS ?
Solution
You can try to set the TMPFS using a QuarkusTestResourceLifecycleManager
guide.
Quarkus Kotlin example:
class DatabaseTestLifeCycleManager : QuarkusTestResourceLifecycleManager {
private val postgresDockerImage = DockerImageName.parse("postgres:latest")
override fun start(): MutableMap<String, String>? {
val container = startPostgresContainer()
return mutableMapOf(
"quarkus.datasource.username" to container.username,
"quarkus.datasource.password" to container.password,
"quarkus.datasource.jdbc.url" to container.jdbcUrl
)
}
private fun startPostgresContainer(): PostgreSQLContainer<out PostgreSQLContainer<*>> {
val container = PostgreSQLContainer(postgresDockerImage)
.withDatabaseName("dataBaseName")
.withUsername("username")
.withPassword("password")
.withEnv(mapOf("PGDATA" to "/var/lib/postgresql/data"))
.withTmpFs(mapOf("/var/lib/postgresql/data" to "rw"))
container.start()
return container
}
override fun stop() {
// close container
}
}
Answered By - Andreas Adelino
Answer Checked By - David Goodson (JavaFixing Volunteer)