izumi
izumi copied to clipboard
Kafka with in-docker and out-of-docker listening interfaces
We found this useful for our e2e tests: while our application is running in a docker container and interacting with kafka using its inside interface, our e2e test run outside of docker and interact with kafka using its outside interface.
If you think this could be useful to supply as a part of distage-framework-docker
, I could prepare a PR to modify the existing kafka configuration.
The implementation is basically this:
object KafkaTwofaceDocker extends ContainerDef {
val insidePort: DockerPort = DockerPort.DynamicTCP("dynamic_kafka_port_inside")
val outsidePort: DockerPort = DockerPort.DynamicTCP("dynamic_kafka_port_outside")
private[this] def portVars: String = Seq(
s"""KAFKA_LISTENERS=INSIDE://:$$${insidePort.toEnvVariable},OUTSIDE://:$$${outsidePort.toEnvVariable}""",
s"""KAFKA_ADVERTISED_LISTENERS=INSIDE://:$$${insidePort.toEnvVariable},OUTSIDE://127.0.0.1:$$${outsidePort.toEnvVariable}""",
"""KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE""",
"""KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT""",
).map(defn => s"export $defn").mkString("; ")
override def config: Config = {
Config(
image = "wurstmeister/kafka:2.12-2.4.1",
ports = Seq(insidePort, outsidePort),
entrypoint = Seq("sh", "-c", s"$portVars ; start-kafka.sh"),
)
}
}