testcontainers-redpanda 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5265bdbd4c6f552bbd4778fcc5e75315cbfd370a840cb7a2e8bc34b75a57b5af
4
+ data.tar.gz: d3324517a4954ac7d0d03d7caa4077c6dcd0fb08ebc5f1c06f2a0d2b4ae45725
5
+ SHA512:
6
+ metadata.gz: 43d8a17e27c73569ee50980524f7c3df669b418971fad87f1f6bbc4b4937c5be9cb1db2336ba5fbe8e60775c79bf6c33f3a69337e20bc21c55959e2b9b75dc94
7
+ data.tar.gz: 783e4de366113fea14722068a1e2db1f1ba65866ebeddd85db0cb328082545de9d1d122650160e6cb7be4a77dbef1ec5c05cd9f7271f16b279043655c765d18e
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [0.1.0] - 2023-06-10
2
+
3
+ ### Added
4
+
5
+ - Initial release of the Redpanda module
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in testcontainers-redpanda.gemspec
6
+ gemspec
7
+
8
+ # Use the latest version of testcontainers-core from the local path
9
+ gem "testcontainers-core", path: "../core"
data/Gemfile.lock ADDED
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: ../core
3
+ specs:
4
+ testcontainers-core (0.1.3)
5
+ docker-api (~> 2.2)
6
+
7
+ PATH
8
+ remote: .
9
+ specs:
10
+ testcontainers-redpanda (0.1.0)
11
+ testcontainers-core (~> 0.1.3)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ ast (2.4.2)
17
+ docker-api (2.2.0)
18
+ excon (>= 0.47.0)
19
+ multi_json
20
+ excon (0.99.0)
21
+ ffi (1.15.5)
22
+ json (2.6.3)
23
+ language_server-protocol (3.17.0.3)
24
+ lint_roller (1.0.0)
25
+ mini_portile2 (2.8.2)
26
+ minitest (5.18.0)
27
+ minitest-hooks (1.5.0)
28
+ minitest (> 5.3)
29
+ multi_json (1.15.0)
30
+ parallel (1.23.0)
31
+ parser (3.2.2.1)
32
+ ast (~> 2.4.1)
33
+ rainbow (3.1.1)
34
+ rake (13.0.6)
35
+ rdkafka (0.12.0)
36
+ ffi (~> 1.15)
37
+ mini_portile2 (~> 2.6)
38
+ rake (> 12)
39
+ regexp_parser (2.8.0)
40
+ rexml (3.2.5)
41
+ rubocop (1.50.2)
42
+ json (~> 2.3)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.2.0.0)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8, < 3.0)
47
+ rexml (>= 3.2.5, < 4.0)
48
+ rubocop-ast (>= 1.28.0, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 2.4.0, < 3.0)
51
+ rubocop-ast (1.28.1)
52
+ parser (>= 3.2.1.0)
53
+ rubocop-performance (1.16.0)
54
+ rubocop (>= 1.7.0, < 2.0)
55
+ rubocop-ast (>= 0.4.0)
56
+ ruby-progressbar (1.13.0)
57
+ standard (1.28.2)
58
+ language_server-protocol (~> 3.17.0.2)
59
+ lint_roller (~> 1.0)
60
+ rubocop (~> 1.50.2)
61
+ standard-custom (~> 1.0.0)
62
+ standard-performance (~> 1.0.1)
63
+ standard-custom (1.0.0)
64
+ lint_roller (~> 1.0)
65
+ standard-performance (1.0.1)
66
+ lint_roller (~> 1.0)
67
+ rubocop-performance (~> 1.16.0)
68
+ unicode-display_width (2.4.2)
69
+
70
+ PLATFORMS
71
+ arm64-darwin-21
72
+
73
+ DEPENDENCIES
74
+ minitest (~> 5.0)
75
+ minitest-hooks (~> 1.5)
76
+ rake (~> 13.0)
77
+ rdkafka (~> 0.12)
78
+ standard (~> 1.3)
79
+ testcontainers-core!
80
+ testcontainers-redpanda!
81
+
82
+ BUNDLED WITH
83
+ 2.4.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Guillermo Iguaran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # Testcontainers module for Redpanda
2
+
3
+ ## Installation
4
+
5
+ Add the library to the test section in your application's Gemfile:
6
+
7
+ ```ruby
8
+ group :test do
9
+ gem 'testcontainers-redpanda'
10
+ end
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install testcontainers-redpanda
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Creating a Redpanda container
28
+
29
+ Create a new instance of the `Testcontainers::RedpandaContainer` class:
30
+
31
+ ```ruby
32
+ container = Testcontainers::RedpandaContainer.new
33
+ ```
34
+
35
+
36
+ This creates a new container with the default MariaDB image. You can customize it by passing arguments to the constructor:
37
+
38
+ ```ruby
39
+ container = Testcontainers::MariadbContainer.new("vectorized/redpanda")
40
+ ```
41
+
42
+ ### Starting and stopping the container
43
+
44
+ Start the container:
45
+
46
+ ```ruby
47
+ container.start
48
+ ```
49
+
50
+
51
+ Stop the container when you're done:
52
+
53
+ ```ruby
54
+ container.stop
55
+ ```
56
+
57
+ ### Connecting to the Redpanda container
58
+
59
+ Once the container is running, you can obtain the connection details using the following methods:
60
+
61
+ ```ruby
62
+ host = container.host
63
+ port = container.mapped_port(9092)
64
+ ```
65
+
66
+ or
67
+
68
+ ```ruby
69
+ connection_url = container.connection_url
70
+ ```
71
+
72
+
73
+ Use these connection details to connect to the Redpanda container using your preferred Kafka client library.
74
+
75
+
76
+
77
+ ### Example
78
+
79
+ Here's a complete example of how to use testcontainers-redpanda to create a container, connect an consumer and a producer to it, and deliver one message:
80
+
81
+ ```ruby
82
+ require "testcontainers/redpada"
83
+ require "rdkafka"
84
+
85
+ container = Testcontainers::RedpandaContainer.new
86
+ container.start
87
+
88
+ config = {
89
+ "bootstrap.servers": container.connection_url,
90
+ "group.id": "ruby-test"
91
+ }
92
+
93
+ consumer = Rdkafka::Config.new(config).consumer
94
+ consumer.subscribe("ruby-test-topic")
95
+
96
+ producer = Rdkafka::Config.new(config).producer
97
+ producer.produce(payload: "Hello, Redpanda!", topic: "ruby-test-topic").wait
98
+
99
+ message = consumer.each do |msg|
100
+ break msg
101
+ end
102
+
103
+ puts msg.inspect
104
+
105
+ container.stop
106
+ ```
107
+
108
+ ### Using with RSpec
109
+
110
+ You can manage the Redpanda container in the before(:suite) / after(:suite) blocks in your spec_helper.rb:
111
+
112
+ ```ruby
113
+ RSpec.configure do |config|
114
+ # This helps us to have access to the `RSpec.configuration.redpanda_container` without using global variables.
115
+ config.add_setting :redpanda_container, default: nil
116
+
117
+ config.before(:suite) do
118
+ config.redpanda_container = Testcontainers::RedpandaContainer.new.start
119
+ # Use the container connection details in your tests
120
+ end
121
+
122
+ config.after(:suite) do
123
+ config.redpanda_container&.stop
124
+ config.redpanda_container&.remove
125
+ end
126
+ end
127
+ ```
128
+
129
+ ## Contributing
130
+
131
+ Bug reports and pull requests are welcome on GitHub at https://github.com/testcontainers/testcontainers-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/testcontainers/testcontainers-ruby/blob/main/CODE_OF_CONDUCT.md).
132
+
133
+ ## License
134
+
135
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
+
137
+ ## Code of Conduct
138
+
139
+ Everyone interacting in the Testcontainers project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/testcontainers/testcontainers-ruby/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Testcontainers
4
+ module Redpanda
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,87 @@
1
+ require_relative "redpanda/version"
2
+ require "testcontainers"
3
+
4
+ module Testcontainers
5
+ # RedpandaContainer class is used to manage containers that run a Redpanda
6
+ class RedpandaContainer < ::Testcontainers::DockerContainer
7
+ # Default port used by the container
8
+ REDPANDA_DEFAULT_PORT = 9092
9
+
10
+ # Default port used for schema registry
11
+ REDPANDA_DEFAULT_SCHEMA_REGISTRY_PORT = 8081
12
+
13
+ # Default image used by the container
14
+ REDPANDA_DEFAULT_IMAGE = "redpandadata/redpanda:latest"
15
+
16
+ # Default path to the startup script
17
+ STARTUP_SCRIPT_PATH = "/testcontainers.sh"
18
+
19
+ # Initializes a new instance of RedpandaContainer
20
+ #
21
+ # @param image [String] the image to use
22
+ # @param kwargs [Hash] the options to pass to the container. See {DockerContainer#initialize}
23
+ # @return [RedpandaContainer] a new instance of RedpandaContainer
24
+ def initialize(image = REDPANDA_DEFAULT_IMAGE, **kwargs)
25
+ super(image, **kwargs)
26
+ end
27
+
28
+ # Starts the container
29
+ #
30
+ # @return [RedpandaContainer] self
31
+ def start
32
+ with_exposed_ports(REDPANDA_DEFAULT_PORT, REDPANDA_DEFAULT_SCHEMA_REGISTRY_PORT)
33
+ with_entrypoint(%w[/bin/sh])
34
+ with_command(["-c", "while [ ! -f #{STARTUP_SCRIPT_PATH} ]; do sleep 0.1; done; #{STARTUP_SCRIPT_PATH}"])
35
+ super
36
+
37
+ # Copy the startup script to the container
38
+ copy_file_to_container("/tmp" + STARTUP_SCRIPT_PATH, _startup_script)
39
+
40
+ # File is copied with root owner and permissions, so we need to change them
41
+ exec_as_root(%w[chmod 777] + ["/tmp" + STARTUP_SCRIPT_PATH])
42
+ exec_as_root(%w[chown redpanda:redpanda] + ["/tmp" + STARTUP_SCRIPT_PATH])
43
+
44
+ # Copy the startup script to expected location
45
+ exec_as_root(%w[cp] + ["/tmp" + STARTUP_SCRIPT_PATH] + [STARTUP_SCRIPT_PATH])
46
+
47
+ wait_for_logs(/Successfully started Redpanda!/)
48
+ self
49
+ end
50
+
51
+ def port
52
+ REDPANDA_DEFAULT_PORT
53
+ end
54
+
55
+ # Returns the Redpanda connection url (e.g. localhost:9092)
56
+ #
57
+ # @return [String] the Redpanda connection url
58
+ # @raise [ConnectionError] If the connection to the Docker daemon fails.
59
+ # @raise [ContainerNotStartedError] If the container has not been started.
60
+ def connection_url
61
+ "#{host}:#{mapped_port(port)}"
62
+ end
63
+
64
+ def bootstrap_servers
65
+ "PLAINTEXT://#{host}:#{mapped_port(port)}"
66
+ end
67
+
68
+ def schema_registry_address
69
+ "http://#{host}:#{mapped_port(REDPANDA_DEFAULT_SCHEMA_REGISTRY_PORT)}"
70
+ end
71
+
72
+ private
73
+
74
+ def _startup_script
75
+ startup_script = StringIO.new
76
+ startup_script.print("#!/bin/sh\n")
77
+ startup_script.print("/usr/bin/rpk redpanda start --mode dev-container")
78
+ startup_script.print(" --kafka-addr PLAINTEXT://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092")
79
+ startup_script.print(" --advertise-kafka-addr PLAINTEXT://0.0.0.0:29092,OUTSIDE://#{host}:#{mapped_port(port)}")
80
+ startup_script
81
+ end
82
+
83
+ def exec_as_root(cmd, options = {})
84
+ exec(cmd, options.merge({"User" => "root"}))
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testcontainers-redpanda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Guillermo Iguaran
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: testcontainers-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-hooks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: standard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdkafka
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.12'
97
+ description: Testcontainers makes it easy to create and clean up container-based dependencies
98
+ for automated tests.
99
+ email:
100
+ - guilleiguaran@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/testcontainers/redpanda.rb
112
+ - lib/testcontainers/redpanda/version.rb
113
+ homepage: https://github.com/testcontainers/testcontainers-ruby
114
+ licenses:
115
+ - MIT
116
+ metadata:
117
+ homepage_uri: https://github.com/testcontainers/testcontainers-ruby/blob/main/redpanda
118
+ source_code_uri: https://github.com/testcontainers/testcontainers-ruby/blob/main/redpanda
119
+ changelog_uri: https://github.com/testcontainers/testcontainers-ruby/blob/main/redpanda/CHANGELOG.md
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.6.0
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubygems_version: 3.4.1
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: 'Testcontainers for Ruby: Redpanda module'
139
+ test_files: []