Issue
I am using Testcontainers' (Localstack Module)[https://www.testcontainers.org/modules/localstack/] for advanced integration testing with Spring Boot, replacing the AmazonS3 client with the one from Localstack. I have set up my integration test roughly as follows (only relevant parts):
// FurnitureDetailsControllerIT.kt
@Testcontainers
@SpringBootTest
@ExtendWith(SpringExtension::class)
@AutoConfigureMockMvc
@DirtiesContext
class FurnitureDetailsControllerIT {
@Autowired
private val amazonS3: AmazonS3? = null
companion object {
@Container
var localStack: LocalStackContainer =
LocalStackContainer(DockerImageName.parse("localstack/localstack:latest")).withServices(LocalStackContainer.Service.S3)
@JvmStatic
@DynamicPropertySource
fun properties(registry: DynamicPropertyRegistry) {
registry.add("cloud.aws.s3.endpoint") { localStack.getEndpointOverride(LocalStackContainer.Service.S3) }
registry.add("cloud.aws.credentials.access-key") { localStack.accessKey }
registry.add("cloud.aws.credentials.secret-key") { localStack.secretKey }
}
}
(...)
}
Everything runs fine when running the integration test locally (from my IDE or command line using Maven), meaning I can see the localstack container spinning up in the logs:
13:54:16.360 [main] INFO 🐳 [remote-docker.artifactory.mycompany.com/localstack/localstack:0.13.0] - Container remote-docker.artifactory.mycompany.com/localstack/localstack:0.13.0 started in PT4.6099665S
However, when running on Jenkins, the build fails because of an error message.
2022-09-28 14:27:19.971 INFO 1185 --- [ main] ?.a.s.com/localstack/localstack:latest] : Container remote-docker.artifactory.mycompany.com/localstack/localstack:latest is starting: ec383bda85f2636c3bef3f6b3938ac169636e4542244e3067b5184b6b03a6e35
2022-09-28 14:28:20.612 ERROR 1185 --- [ main] ?.a.s.com/localstack/localstack:latest] : Could not start container
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '.*Ready\.
I guess it has to do with the temporary directory needed by Localstack. When running on my Windows machine I have to manually click on "Share It" before the test resumes:
I suppose since the test is failing on Jenkins (because I cannot click on "Share It" there) starting the container will eventually time out and the test will fail.
I read that you can configure the directory using the TMPDIR
environment variable as described in https://docs.localstack.cloud/localstack/configuration/. But using that variable is deprecated. What is the best way to set the temp directory to Jenkins working directory without having to explicitly conset to sharing that directory?
Note: I am already using Testcontainers' MongoBD module successfully, which starts a dockerized MongoDB instance. That works flawlessly, so I am not sure if it's an issue with Testcontainers or Localstack.
Solution
Turns out it was an issue with the company proxy after all. For some reason, LocalStack needs to download dependencies at runtime:
From https://docs.localstack.cloud/localstack/configuration/:
OUTBOUND_HTTP_PROXY: HTTP Proxy used for downloads of runtime dependencies and connections outside LocalStack itself
Since our Jenkins is behind a corporate proxy, I had to set the following environment variables: SKIP_SSL_CERT_DOWNLOAD
, OUTBOUND_HTTP_PROXY
, OUTBOUND_HTTPS_PROXY
. On top of that I had to hardcode the version to 1.1.0
instead of using the latest
tag.
So my code now looks like this:
LocalStackContainer(DockerImageName.parse("localstack/localstack:1.1.0"))
.withServices(LocalStackContainer.Service.S3)
.withEnv("SKIP_SSL_CERT_DOWNLOAD", "true")
.withEnv("OUTBOUND_HTTP_PROXY", "http://{proxy}:{port}")
.withEnv("OUTBOUND_HTTPS_PROXY", "http://{proxy}:{port}")
.apply { start() }
Answered By - tiefenauer
Answer Checked By - Gilberto Lyons (JavaFixing Admin)