Class: Testcontainers::RedpandaContainer
- Inherits:
-
DockerContainer
- Object
- DockerContainer
- Testcontainers::RedpandaContainer
- Defined in:
- lib/testcontainers/redpanda.rb
Overview
RedpandaContainer class is used to manage containers that run a Redpanda
Constant Summary collapse
- REDPANDA_DEFAULT_PORT =
Default port used by the container
9092- REDPANDA_DEFAULT_SCHEMA_REGISTRY_PORT =
Default port used for schema registry
8081- REDPANDA_DEFAULT_IMAGE =
Default image used by the container
"redpandadata/redpanda:latest"- STARTUP_SCRIPT_PATH =
Default path to the startup script
"/testcontainers.sh"
Instance Method Summary collapse
- #bootstrap_servers ⇒ Object
-
#connection_url ⇒ String
Returns the Redpanda connection url (e.g. localhost:9092).
-
#initialize(image = REDPANDA_DEFAULT_IMAGE, **kwargs) ⇒ RedpandaContainer
constructor
Initializes a new instance of RedpandaContainer.
- #port ⇒ Object
- #schema_registry_address ⇒ Object
-
#start ⇒ RedpandaContainer
Starts the container.
Constructor Details
#initialize(image = REDPANDA_DEFAULT_IMAGE, **kwargs) ⇒ RedpandaContainer
Initializes a new instance of RedpandaContainer
24 25 26 |
# File 'lib/testcontainers/redpanda.rb', line 24 def initialize(image = REDPANDA_DEFAULT_IMAGE, **kwargs) super(image, **kwargs) end |
Instance Method Details
#bootstrap_servers ⇒ Object
64 65 66 |
# File 'lib/testcontainers/redpanda.rb', line 64 def bootstrap_servers "PLAINTEXT://#{host}:#{mapped_port(port)}" end |
#connection_url ⇒ String
Returns the Redpanda connection url (e.g. localhost:9092)
60 61 62 |
# File 'lib/testcontainers/redpanda.rb', line 60 def connection_url "#{host}:#{mapped_port(port)}" end |
#port ⇒ Object
51 52 53 |
# File 'lib/testcontainers/redpanda.rb', line 51 def port REDPANDA_DEFAULT_PORT end |
#schema_registry_address ⇒ Object
68 69 70 |
# File 'lib/testcontainers/redpanda.rb', line 68 def schema_registry_address "http://#{host}:#{mapped_port(REDPANDA_DEFAULT_SCHEMA_REGISTRY_PORT)}" end |
#start ⇒ RedpandaContainer
Starts the container
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/testcontainers/redpanda.rb', line 31 def start with_exposed_ports(REDPANDA_DEFAULT_PORT, REDPANDA_DEFAULT_SCHEMA_REGISTRY_PORT) with_entrypoint(%w[/bin/sh]) with_command(["-c", "while [ ! -f #{STARTUP_SCRIPT_PATH} ]; do sleep 0.1; done; #{STARTUP_SCRIPT_PATH}"]) super # Copy the startup script to the container copy_file_to_container("/tmp" + STARTUP_SCRIPT_PATH, _startup_script) # File is copied with root owner and permissions, so we need to change them exec_as_root(%w[chmod 777] + ["/tmp" + STARTUP_SCRIPT_PATH]) exec_as_root(%w[chown redpanda:redpanda] + ["/tmp" + STARTUP_SCRIPT_PATH]) # Copy the startup script to expected location exec_as_root(%w[cp] + ["/tmp" + STARTUP_SCRIPT_PATH] + [STARTUP_SCRIPT_PATH]) wait_for_logs(/Successfully started Redpanda!/) self end |