Skip to content

Commit 096dc34

Browse files
committed
feat: enhance container customization and extend documentation
- Added detailed documentation for container customization processes, including network mode, environment variables, file transfers, ports, and startup options. - Introduced examples for using `withContainerCustomization` and Testcontainers callbacks. - Updated Kotlin integration examples for dynamic container configurations.
1 parent 2ba48a8 commit 096dc34

1 file changed

Lines changed: 40 additions & 4 deletions

File tree

doc/user-guide.adoc

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,15 @@ hdfsWeb = 9870
294294

295295
Typed service options should cover the normal path, but integration-test containers sometimes need image-specific workarounds before the framework has first-class support. Use container customizations as an escape hatch for troubleshooting or temporary overrides.
296296

297+
Container customizations run before the service container starts. Use them for Docker/Testcontainers-level concerns such as network mode, extra ports, environment variables, copied files, host mounts, image-specific startup flags, and temporary workarounds. Use extensions for post-start provisioning such as creating buckets, generating JCEKS files, creating Kafka topics, or producing seed records.
298+
297299
TOML supports environment variables, copied files, host mounts, and extra exposed ports:
298300

299301
[source,toml]
300302
----
303+
[containers.hdfs]
304+
networkMode = "host"
305+
301306
[containers.hdfs.env]
302307
HADOOP_OPTS = "-Dsun.security.krb5.debug=true"
303308
@@ -310,9 +315,6 @@ HADOOP_OPTS = "-Dsun.security.krb5.debug=true"
310315
311316
[containers.hdfs.ports]
312317
"9866" = 9866
313-
314-
[containers.hdfs]
315-
networkMode = "host"
316318
----
317319

318320
File sources must use one of these prefixes:
@@ -333,8 +335,8 @@ Programmatic tests can use the same portable operations:
333335
----
334336
val kit = BigDataTestKit.builder()
335337
.withHdfs()
336-
.withContainerEnv(BigDataService.HDFS, "HADOOP_OPTS", "-Dsun.security.krb5.debug=true")
337338
.withContainerNetworkMode(BigDataService.HDFS, "host")
339+
.withContainerEnv(BigDataService.HDFS, "HADOOP_OPTS", "-Dsun.security.krb5.debug=true")
338340
.withContainerFile(
339341
BigDataService.HDFS,
340342
ContainerFileTransferOptions.content(
@@ -346,6 +348,28 @@ val kit = BigDataTestKit.builder()
346348
.build()
347349
----
348350

351+
The lower-level `withContainerCustomization` method is useful when a test wants to build the customization object dynamically:
352+
353+
[source,kotlin]
354+
----
355+
val customization = ContainerCustomizationOptions(
356+
networkMode = if (useHostNetwork) "host" else null,
357+
environment = mapOf("HADOOP_OPTS" to "-Dsun.security.krb5.debug=true"),
358+
files = listOf(
359+
ContainerFileTransferOptions.content(
360+
"<configuration/>",
361+
"/opt/hadoop/etc/hadoop/extra-site.xml",
362+
),
363+
),
364+
ports = listOf(ContainerPortOptions(containerPort = 9866, hostPort = 9866)),
365+
)
366+
367+
val kit = BigDataTestKit.builder()
368+
.withHdfs()
369+
.withContainerCustomization(BigDataService.HDFS, customization)
370+
.build()
371+
----
372+
349373
For cases that cannot be represented declaratively, use the Testcontainers callback. The callback runs after `bigdata-test` applies its built-in container settings and before the container starts:
350374

351375
[source,kotlin]
@@ -358,6 +382,18 @@ val kit = BigDataTestKit.builder()
358382
.build()
359383
----
360384

385+
The callback receives the actual `GenericContainer<*>`, so users can call Testcontainers APIs directly. This is the most flexible workaround path when `bigdata-test` does not expose a typed option yet. For example, before `networkMode` was first-class, the same host-network workaround could be written as:
386+
387+
[source,kotlin]
388+
----
389+
val kit = BigDataTestKit.builder()
390+
.withHdfs()
391+
.customizeContainer(BigDataService.HDFS) { container ->
392+
container.withNetworkMode("host")
393+
}
394+
.build()
395+
----
396+
361397
Do not use the callback as the normal configuration API for reusable tests. If a setting is stable and generally useful, prefer a typed option or TOML field so it can be documented, data-driven from Gradle tasks, and used from Java.
362398

363399
=== Startup Health Checks

0 commit comments

Comments
 (0)