testcontainers-nginx simplifies the creation and management of Nginx containers for testing purposes using the Testcontainers library.
Add the library to the test section in your application's Gemfile:
group :test do
gem 'testcontainers-nginx'
endAnd then execute:
$ bundle installOr install it yourself as:
$ gem install testcontainers-nginxTo use the library, you first need to require it:
require 'testcontainers/nginx'Create a new instance of the Testcontainers::NginxContainer class:
container = Testcontainers::NginxContainer.newThis creates a new container with the default Nginx image and port. You can customize these by passing arguments to the constructor:
container = Testcontainers::NginxContainer.new("nginx:alpine", port: 8080)You can setup filesystem binds to configure the container with custom configuration files or to serve content from a custom path:
container.with_filesystem_binds(["/local/path/custom/conf:/etc/nginx/conf.d:ro"])
container.with_filesystem_binds(["/local/path/custom/content:/usr/share/nginx/html:ro"])Start the container:
container.startStop the container when you're done:
container.stopOnce the container is running, you can obtain the connection details using the following methods:
host = container.host
port = container.first_mapped_portOr, you can generate a full server URL:
server_url = container.server_urlBug 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.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Testcontainers project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.