-
-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(modules): add artemis container #1440
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Apache ActiveMQ Artemis | ||
|
||
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 Artemis. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the Artemis module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/artemis | ||
``` | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating and connecting to an Artemis container](../../modules/artemis/example_test.go) inside_block:ExampleRunContainer | ||
<!--/codeinclude--> | ||
|
||
## Module reference | ||
|
||
The Artemis module exposes one entrypoint function to create the Artemis container, and this function receives two parameters: | ||
|
||
```golang | ||
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) | ||
``` | ||
|
||
- `context.Context`, the Go context. | ||
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
||
### Container Options | ||
|
||
When starting the Artemis container, you can pass options in a variadic way to configure it. | ||
|
||
#### Image | ||
|
||
If you need to set a different Artemis Docker image, you can use `testcontainers.WithImage` with a valid Docker image | ||
for Artemis. E.g. `testcontainers.WithImage("docker.io/apache/activemq-artemis:2.30.0")`. | ||
|
||
#### Wait Strategies | ||
|
||
If you need to set a different wait strategy for Artemis, you can use `testcontainers.WithWaitStrategy` with a valid wait strategy | ||
for Artemis. | ||
|
||
!!!info | ||
The default deadline for the wait strategy is 60 seconds. | ||
|
||
At the same time, it's possible to set a wait strategy and a custom deadline with `testcontainers.WithWaitStrategyAndDeadline`. | ||
|
||
#### Credentials | ||
|
||
If you need to change the default admin credentials (i.e. `artemis:artemis`) use `WithCredentials`. | ||
|
||
```go | ||
container, err := artemis.RunContainer(ctx, artemis.WithCredentials("user", "password")) | ||
``` | ||
|
||
#### Anonymous Login | ||
|
||
If you need to enable anonymous logins (which are disabled by default) use `WithAnonymousLogin`. | ||
|
||
```go | ||
container, err := artemis.RunContainer(ctx, artemis.WithAnonymousLogin()) | ||
``` | ||
|
||
#### Custom Arguments | ||
|
||
If you need to pass custom arguments to the `artemis create` command, use `WithExtraArgs`. | ||
The default is `--http-host 0.0.0.0 --relax-jolokia`. | ||
Setting this value will override the default. | ||
See the documentation on `artemis create` for available options. | ||
|
||
```go | ||
container, err := artemis.RunContainer(ctx, artemis.WithExtraArgs("--http-host 0.0.0.0 --relax-jolokia --queues ArgsTestQueue")) | ||
``` | ||
|
||
#### Docker type modifiers | ||
|
||
If you need an advanced configuration for Artemis, you can leverage the following Docker type modifiers: | ||
|
||
- `testcontainers.WithConfigModifier` | ||
- `testcontainers.WithHostConfigModifier` | ||
- `testcontainers.WithEndpointSettingsModifier` | ||
|
||
Please read the [Create containers: Advanced Settings](../features/creating_container.md#advanced-settings) documentation for more information. | ||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
### Container Methods | ||
|
||
The Artemis container exposes the following methods: | ||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### User | ||
|
||
User returns the administrator username. | ||
|
||
```go | ||
user := container.User() | ||
``` | ||
|
||
#### Password | ||
|
||
Password returns the administrator password. | ||
|
||
```go | ||
password := container.Password() | ||
``` | ||
|
||
#### BrokerEndpoint | ||
|
||
BrokerEndpoint returns the host:port for the combined protocols endpoint. | ||
|
||
```go | ||
host, err := container.BrokerEndpoint(ctx) | ||
``` | ||
|
||
#### ConsoleURL | ||
|
||
ConsoleURL returns the URL for the management console. | ||
|
||
```go | ||
url, err := container.ConsoleURL(ctx) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include ../../commons-test.mk | ||
|
||
.PHONY: test | ||
test: | ||
$(MAKE) test-artemis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package artemis | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/docker/go-connections/nat" | ||
"github.com/testcontainers/testcontainers-go" | ||
"github.com/testcontainers/testcontainers-go/wait" | ||
) | ||
|
||
const ( | ||
defaultBrokerPort = "61616/tcp" | ||
defaultHTTPPort = "8161/tcp" | ||
) | ||
|
||
// Container represents the Artemis container type used in the module. | ||
type Container struct { | ||
testcontainers.Container | ||
user string | ||
password string | ||
} | ||
|
||
// User returns the administrator username. | ||
func (c *Container) User() string { | ||
return c.user | ||
} | ||
|
||
// Password returns the administrator password. | ||
func (c *Container) Password() string { | ||
return c.password | ||
} | ||
|
||
// BrokerEndpoint returns the host:port for the combined protocols endpoint. | ||
// The endpoint accepts CORE, MQTT, AMQP, STOMP, HORNETQ and OPENWIRE protocols. | ||
func (c *Container) BrokerEndpoint(ctx context.Context) (string, error) { | ||
return c.PortEndpoint(ctx, nat.Port(defaultBrokerPort), "") | ||
} | ||
|
||
// ConsoleURL returns the URL for the management console. | ||
func (c *Container) ConsoleURL(ctx context.Context) (string, error) { | ||
host, err := c.PortEndpoint(ctx, nat.Port(defaultHTTPPort), "") | ||
if err != nil { | ||
return "", err | ||
} | ||
return fmt.Sprintf("http://%s:%s@%s/console", c.user, c.password, host), nil | ||
} | ||
|
||
// WithCredentials sets the administrator credentials. The default is artemis:artemis. | ||
func WithCredentials(user, password string) testcontainers.CustomizeRequestOption { | ||
return func(req *testcontainers.GenericContainerRequest) { | ||
req.Env["ARTEMIS_USER"] = user | ||
req.Env["ARTEMIS_PASSWORD"] = password | ||
} | ||
} | ||
|
||
// WithAnonymousLogin enables anonymous logins. | ||
func WithAnonymousLogin() testcontainers.CustomizeRequestOption { | ||
return func(req *testcontainers.GenericContainerRequest) { | ||
req.Env["ANONYMOUS_LOGIN"] = "true" | ||
} | ||
} | ||
|
||
// Additional arguments sent to the `artemis create“ command. | ||
// The default is `--http-host 0.0.0.0 --relax-jolokia`. | ||
// Setting this value will override the default. | ||
// See the documentation on `artemis create` for available options. | ||
func WithExtraArgs(args string) testcontainers.CustomizeRequestOption { | ||
return func(req *testcontainers.GenericContainerRequest) { | ||
req.Env["EXTRA_ARGS"] = args | ||
} | ||
} | ||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// RunContainer creates an instance of the Artemis container type. | ||
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) { | ||
req := testcontainers.GenericContainerRequest{ | ||
ContainerRequest: testcontainers.ContainerRequest{ | ||
Image: "docker.io/apache/activemq-artemis:2.30.0-alpine", | ||
Env: map[string]string{ | ||
"ARTEMIS_USER": "artemis", | ||
"ARTEMIS_PASSWORD": "artemis", | ||
}, | ||
ExposedPorts: []string{defaultBrokerPort, defaultHTTPPort}, | ||
WaitingFor: wait.ForAll( | ||
wait.ForLog("Server is now live"), | ||
wait.ForLog("REST API available"), | ||
), | ||
}, | ||
Started: true, | ||
} | ||
|
||
for _, opt := range opts { | ||
opt.Customize(&req) | ||
} | ||
|
||
container, err := testcontainers.GenericContainer(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
user := req.Env["ARTEMIS_USER"] | ||
password := req.Env["ARTEMIS_PASSWORD"] | ||
|
||
return &Container{Container: container, user: user, password: password}, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not to delay more this PR, I'll update the code snippets, using the codeinclude plugin in a follow-up PR.