Skip to content

Commit

Permalink
feat: add RabbitMQ support (#1618)
Browse files Browse the repository at this point in the history
* chore: add rabbitmq scaffolding

* feat: add functional option for admin password

* fix: update postgres docs

* chore: add default ports and URL methods

* feat: support for SSL

* feat: support for Enabling plugins

* fix: update text in template

* chore: add multiple withXXX

* chore: convert plugins into an Executable

* chore: simplify

* docs: better docs

* chore: remove test file, as everything is a testable example

* chore: run mod tidy

* chore: expose type for simplicity

* chore: support for updating the default admin user

* chore: store admin credentials in the container

* chore: support for passing custom configs

* chore: move big example to a test

* fix: added by mistake

* chore: add an example on how to connect using the AMQP protocol

* fix: lint

* chore: use a common WithStartupCommand option instead

We do not want to be specific, but generic

* chore: move WithStartupCommand to the core

* chore: move types to the test package

* docs: reorder docs

* docs: include startup methods in module docs

* docs: include example for SSL config (erlang format)

* feat: support for rendering our own Erlang config

* chore: run mod tidy

* chore: remove with config methods

We are gonig to build our own config

* chore: build the config in the properties format

* chore: document the test structs

* docs: include common options

* docs: document the render template

* docs: remove outdated blocks

* docs: remove outdated blocks

* fix: use fixed paths for certs in the container

* fix: proper log message

* chore: move test helpers to test file

* chore: do not mix examples and tests

* fix: lint
  • Loading branch information
mdelapenya authored Sep 21, 2023
1 parent 292cdd8 commit a285e86
Show file tree
Hide file tree
Showing 19 changed files with 1,540 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ updates:
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/rabbitmq
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/redis
schedule:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
matrix:
go-version: [1.20.x, 1.x]
platform: [ubuntu-latest, macos-latest]
module: [artemis, clickhouse, compose, couchbase, elasticsearch, k3s, kafka, localstack, mariadb, mongodb, mysql, nats, neo4j, postgres, pulsar, redis, redpanda, vault]
module: [artemis, clickhouse, compose, couchbase, elasticsearch, k3s, kafka, localstack, mariadb, mongodb, mysql, nats, neo4j, postgres, pulsar, rabbitmq, redis, redpanda, vault]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
ryuk-disabled: false

sonarcloud:
if: ${{ always() && github.ref_name == 'main' && github.repository_owner == 'testcontainers' }}
if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' }}
needs: test-examples
runs-on: ubuntu-latest
steps:
Expand All @@ -154,4 +154,3 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

4 changes: 4 additions & 0 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
"name": "module / pulsar",
"path": "../modules/pulsar"
},
{
"name": "module / rabbitmq",
"path": "../modules/rabbitmq"
},
{
"name": "module / redis",
"path": "../modules/redis"
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ for Postgres. E.g. `testcontainers.WithImage("docker.io/postgres:9.6")`.

#### Initial Database

If you need to set a different database, and its credentials, you can use the `WithDatabase(db string)` option.
If you need to set a different database, and its credentials, you can use the `WithDatabase(db string)`, `WithUsername(user string)` and `WithPassword(pwd string)` options.

#### Init Scripts

Expand Down
131 changes: 131 additions & 0 deletions docs/modules/rabbitmq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# RabbitMQ

Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

## Introduction

The Testcontainers module for RabbitMQ.

## Adding this module to your project dependencies

Please run the following command to add the RabbitMQ module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/rabbitmq
```

## Usage example

<!--codeinclude-->
[Creating a RabbitMQ container](../../modules/rabbitmq/examples_test.go) inside_block:runRabbitMQContainer
<!--/codeinclude-->

## Module reference

The RabbitMQ module exposes one entrypoint function to create the RabbitMQ container, and this function receives two parameters:

```golang
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RabbitMQContainer, error)
```

- `context.Context`, the Go context.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the RabbitMQ container, you can pass options in a variadic way to configure it. All these options will be automatically rendered into the RabbitMQ's custom configuration file, located at `/etc/rabbitmq/rabbitmq-custom.conf`.

#### Image

If you need to set a different RabbitMQ Docker image, you can use `testcontainers.WithImage` with a valid Docker image
for RabbitMQ. E.g. `testcontainers.WithImage("rabbitmq:3.7.25-management-alpine")`.

!!!warning
From [https://hub.docker.com/_/rabbitmq](https://hub.docker.com/_/rabbitmq): "As of RabbitMQ 3.9, all of the docker-specific variables listed below are deprecated and no longer used. Please use a configuration file instead; visit [rabbitmq.com/configure](https://rabbitmq.com/configure) to learn more about the configuration file. For a starting point, the 3.8 images will print out the config file it generated from supplied environment variables."

- RABBITMQ_DEFAULT_PASS_FILE
- RABBITMQ_DEFAULT_USER_FILE
- RABBITMQ_MANAGEMENT_SSL_CACERTFILE
- RABBITMQ_MANAGEMENT_SSL_CERTFILE
- RABBITMQ_MANAGEMENT_SSL_DEPTH
- RABBITMQ_MANAGEMENT_SSL_FAIL_IF_NO_PEER_CERT
- RABBITMQ_MANAGEMENT_SSL_KEYFILE
- RABBITMQ_MANAGEMENT_SSL_VERIFY
- RABBITMQ_SSL_CACERTFILE
- RABBITMQ_SSL_CERTFILE
- RABBITMQ_SSL_DEPTH
- RABBITMQ_SSL_FAIL_IF_NO_PEER_CERT
- RABBITMQ_SSL_KEYFILE
- RABBITMQ_SSL_VERIFY
- RABBITMQ_VM_MEMORY_HIGH_WATERMARK

{% include "../features/common_functional_options.md" %}

#### Startup Commands for RabbitMQ

The RabbitMQ module includes several test implementations of the `testcontainers.Executable` interface: Binding, Exchange, OperatorPolicy, Parameter, Permission, Plugin, Policy, Queue, User, VirtualHost and VirtualHostLimit. You could use them as reference to understand how the startup commands are generated, but please consider this test implementation could not be complete for your use case.

You could use this feature to run a custom script, or to run a command that is not supported by the module. RabbitMQ examples of this could be:

- Enable plugins
- Add virtual hosts and virtual hosts limits
- Add exchanges
- Add queues
- Add bindings
- Add policies
- Add operator policies
- Add parameters
- Add permissions
- Add users

Please refer to the RabbitMQ documentation to build your own commands.

<!--codeinclude-->
[Add Virtual Hosts](../../modules/rabbitmq/rabbitmq_test.go) inside_block:addVirtualHosts
[Add Exchanges](../../modules/rabbitmq/rabbitmq_test.go) inside_block:addExchanges
[Add Queues](../../modules/rabbitmq/rabbitmq_test.go) inside_block:addQueues
[Add Bindings](../../modules/rabbitmq/rabbitmq_test.go) inside_block:addBindings
[Add Policies](../../modules/rabbitmq/rabbitmq_test.go) inside_block:addPolicies
[Add Permissions](../../modules/rabbitmq/rabbitmq_test.go) inside_block:addPermissions
[Add Users](../../modules/rabbitmq/rabbitmq_test.go) inside_block:addUsers
[Enabling Plugins](../../modules/rabbitmq/rabbitmq_test.go) inside_block:enablePlugins
<!--/codeinclude-->

#### Default Admin

If you need to set the username and/or password for the admin user, you can use the `WithAdminUsername(username string)` and `WithAdminPassword(pwd string)` options.

!!!info
By default, the admin username is `guest` and the password is `guest`.

#### SSL settings

In the case you need to enable SSL, you can use the `WithSSL(settings SSLSettings)` option. This option will enable SSL with the passed settings:

<!--codeinclude-->
[Enabling SSL](../../modules/rabbitmq/examples_test.go) inside_block:enableSSL
<!--/codeinclude-->

You'll find a log entry similar to this one in the container logs:
```
2023-09-13 13:05:10.213 [info] <0.548.0> started TLS (SSL) listener on [::]:5671
```
### Container Methods
The RabbitMQ container exposes the following methods:
#### AMQP URLs
The RabbitMQ container exposes two methods to retrieve the AMQP URLs in order to connect to the RabbitMQ instance using AMQP clients:
- `AmqpURL()`, returns the AMQP URL.
- `AmqpsURL()`, returns the AMQPS URL.
#### HTTP management URLs
The RabbitMQ container exposes two methods to retrieve the HTTP URLs for management:
- `HttpURL()`, returns the management URL over HTTP.
- `HttpsURL()`, returns the management URL over HTTPS.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ nav:
- modules/neo4j.md
- modules/postgres.md
- modules/pulsar.md
- modules/rabbitmq.md
- modules/redis.md
- modules/redpanda.md
- modules/vault.md
Expand Down
2 changes: 1 addition & 1 deletion modulegen/_template/examples_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Example{{ $entrypoint }}() {
panic(err)
}

// Clean up the container after
// Clean up the container
defer func() {
if err := {{ $lower }}Container.Terminate(ctx); err != nil {
panic(err)
Expand Down
5 changes: 5 additions & 0 deletions modules/rabbitmq/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-rabbitmq
Loading

0 comments on commit a285e86

Please sign in to comment.