Testcontainers-java: Set HOSTNAME_EXTERNAL env variable for localstack test container

Created on 27 Dec 2018  路  9Comments  路  Source: testcontainers/testcontainers-java

Right now localstack container does not override hostname property that leads to issues with aws responses that contains url. All works when container could be reached by localhost (127.0.0.1) but fails when running in docker env with another IP address resolved.

val sqsEndpoint = localstack.getEndpointConfiguration(SQS)
val sqsClient = AmazonSQSAsyncClient.asyncBuilder().withEndpointConfiguration(sqsEndpoint)
                .withCredentials(localstack.defaultCredentialsProvider).build()
val queueUrl = sqsClient.createQueue("aQueue").queueUrl

println(sqsEndpoint.serviceEndpoint)
println(queueUrl)

This would print something like

http://127.0.0.1.nip.io:33161
http://localhost:33161/queue/aQueue

As you can see if service endpoint would be resolved to another IP it would break

Current workaround - extract host/port from serviceEndpoint info and use it in queueUrl, but as localstack can be configured to adjust host, I believe it could be done on testcontainers side

good first issue help wanted resolutiopr-submitted typbug

Most helpful comment

I believe the fix by @CauchyPeano should be merged. Spent half of the day trying to figure out whats wrong.

All 9 comments

I would like to tackle this one

@CauchyPeano Sounds good, so automatically setting HOSTNAME_EXTERNAL to getContainerIpAddress() in the configure method?

@kiview uhm, so far as I've understood I will just have additional property for LocalStackContainer to configure HOSTNAME_EXTERNAL. Then it will be up to person who configures the test to set network alias be same as mentioned hostname. If I am wrong please correct me.

Yes you are right, I was missing the network alias use case and was just thinking about exposing ports on remote docker daemon.

Hi guys. While this approach simplifies configuration, this does not completely fix the original problem - it forces me to explicitly configure external hostname when setting up localstack container.

What I really want - to have localstack container properly reply url-like data automatically when "external" url returned in localstack.getEndpointConfiguration(SQS) does not point to 127.0.0.1. This happens for me when tests are run in docker itself. So if HOSTNAME_EXTERNAL would be set to 127.0.0.1.nip.io (see original example, looks like it's some internal testcontainers machinery url) this would fix the issue.

If problem is still not clear, let me know and I can build sample project that can show the problem.

Hey @zeldigas, thanks for getting back.

I kind of agree with you. Then I would have design question then to localstack core maintainers:
Does testcontainer's modules should use side containers as-is without any side logic OR testcontainers should strive to have maximal convenience for users to setup them (i.e. override default behavior)?

Ping @kiview :)

I believe the fix by @CauchyPeano should be merged. Spent half of the day trying to figure out whats wrong.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oneiros-de picture oneiros-de  路  3Comments

andredasilvapinto picture andredasilvapinto  路  3Comments

ParafeniukMikalaj picture ParafeniukMikalaj  路  3Comments

micheal-swiggs picture micheal-swiggs  路  4Comments

aniketbhatnagar picture aniketbhatnagar  路  3Comments