-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add LocalStack (V1) container for zio 2.0 #41
base: main
Are you sure you want to change the base?
Conversation
I'm going to add documentation if this approach is fine. |
ZLayer.scoped { | ||
for { | ||
localstack <- ZIO.service[LocalStackContainer] | ||
endpoint <- ZIO.attempt(localstack.container.getEndpointOverride(JavaLocalStackContainer.Service.S3)) |
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.
This shows an example of overriding endpoints of LocalStack services.
"com.amazonaws" % "aws-java-sdk-s3" % V.awsV1Version % Provided, | ||
"com.amazonaws" % "aws-java-sdk-sqs" % V.awsV1Version % Provided, |
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.
That's the way testcontainers-scala
provides these dependencies. I decided to stick to their approach.
@@ -12,6 +12,8 @@ object V { | |||
val zioKafkaVersion = "0.17.1" | |||
val zio2KafkaVersion = "2.0.0" | |||
val zioHttpVersion = "0.0.4" | |||
val zioAwsVersion = "5.20.17.1" |
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.
I believe this is the latest version of zio-aws
that uses ZIO 2.0.9
. Usage of more recent versions causes NoClassDefFoundError
. It should be updated after the ZIO version is bumped up.
Fixing the compilation error... |
Hi, I have implemented something similar and opted to directly integrate it with zio-aws. The interesting/useful thing is on how to get the actual AWS config as it turns out that you don't need to have service-specific endpoints, therefore you don't need to pass the Service enum value in the TestContainer API to get an endpoint and instead get a layer to be reused by all services, which is great if you have code using multiple services. You just provide the layer 😃 Even though may not want to depend on zio-aws, it would be great to expose the endpoint directly to simplify the usage, as most users will think they need to pass the Service enum to get the endpoint. val awsConfig: ZLayer[Any, Throwable, CommonAwsConfig] = ZLayer.scoped {
for {
localstack <- makeContainer(LocalStackV2Container.Def(
tag = "2.0.2",
// Services are loaded lazily in latest localstack so need to be specific.
services = Service.values()
))
hostIpAddress <- ZIO.attempt(InetAddress.getByName(localstack.host).getHostAddress)
// All services are found in the same port in latest locastack, so no service-specific mapping needed
port <- ZIO.attempt(localstack.mappedPort(4566))
uri <- ZIO.attempt(new URI(s"http://${hostIpAddress}:${port}"))
} yield CommonAwsConfig(
region = Some(Region.EU_WEST_1),
endpointOverride = Some(uri),
credentialsProvider = localstack.staticCredentialsProvider,
commonClientConfig = None
)
} Hope it helps ! TLDR: Updates to Localstack make the API container API from testcontainers outdated, as you don't need to either specify which services you need, nor get service-specific ports. So the Dropping the |
This PR adds LocalStack container V1 for ZIO 2.0 only.
I also opened another PR intestcontainers-scala
to allowdockerImageName
overrides, and not onlytag
: testcontainers/testcontainers-scala#246. I think it would be good to wait until thetestcontainers-scala
PR is merged and make changes to this one accordingly.Update:
testcontainers-scala
is bumped up to0.40.15