quarkiverse / quarkus-amazon-services

Quarkus Amazon Services extensions
Apache License 2.0
41 stars 49 forks source link

Is there a way to change the repository for quarkus.aws.devservices.localstack #684

Closed tmdonalds closed 1 year ago

tmdonalds commented 1 year ago

We are trying to modify the localstack image that is being used but we are running into the dockerhub pull rate limits. Looking at the documentation I don't see a way to modify the localstack registry. Is there a way to do this? Please advise. Thanks.

quarkus.aws.devservices.localstack.image-name

xPTM1219 commented 1 year ago

Also, if we try to use the pro version or the AWS image it throws an error. For example this line in the application.properties: quarkus.aws.devservices.localstack.image-name=public.ecr.aws/localstack/localstack-pro:latest

Throws:

Caused by: java.lang.IllegalStateException: Failed to verify that image 'public.ecr.aws/localstack/localstack-pro:latest' is a compatible substitute for 'localstack/localstack'. This generally means that you are trying to use an image that Testcontainers has not been designed to use. If this is deliberate, and if you are confident that the image is compatible, you should declare compatibility in code using the `asCompatibleSubstituteFor` method. For example:
   DockerImageName myImage = DockerImageName.parse("public.ecr.aws/localstack/localstack-pro:latest").asCompatibleSubstituteFor("localstack/localstack");
and then use `myImage` instead.
        at org.testcontainers.utility.DockerImageName.assertCompatibleWith(DockerImageName.java:270)
        at org.testcontainers.containers.localstack.LocalStackContainer.<init>(LocalStackContainer.java:93)

I also tried to use public.ecr.aws/localstack/localstack:latest, just because maybe the pro version doesn't work with test containers and it throws the same error.

scrocquesel commented 1 year ago

For the substitution of the registry, you should be able to use one of the testcontainers solution to prefix the image name automatically.

For eg. in src/test/resources/testcontainers.properties

hub.image.name.prefix=public.ecr.aws/

For the change of image name, that's weird, we explicitly set the user provided image name as a compatible substitute for localstack/localstack and I can't reproduced your issue. Do you have a small repro ?

As a side note, I haven't a pro licence but you should be able to provide the licence key with the following config. Let me know if it works.

quarkus.aws.devservices.localstack.container-properties."LOCALSTACK_API_KEY"=<you key>
xPTM1219 commented 1 year ago

Hi scrocquesel, thanks for the response. Our repo is quite big. Here are some notes.

Changing the repo

When the src/test/resources/testcontainers.properties file is used it gets the repo changed using the following:

tinyimage.container.image=public.ecr.aws/docker/library/alpine\:latest
sshd.container.image=public.ecr.aws/senzing/sshd\:1.4.6
ryuk.container.image=public.ecr.aws/s4w6t4b6/testcontainers/ryuk\:0.4.0
localstack.container.image=public.ecr.aws/localstack/localstack\:2.0.2

Additionally, is possible to change the repo image on ~/.testcontainers.properties file. The only problem is that the change is local for each user.

Changing image name

The image settings inside application.properties is still giving the error as the post above when using the pro version, unless I use the regular image like this: quarkus.aws.devservices.localstack.image-name=localstack/localstack:2.0.2.

API key

I was not able to set the API key by using quarkus.aws.devservices.localstack.container-properties."LOCALSTACK_API_KEY"=<you key>, it gives this error:

Caused by: java.lang.ExceptionInInitializerError at io.quarkus.runner.ApplicationImpl.<clinit>(Unknown Source)
Caused by: java.util.NoSuchElementException: SRCFG00011: Could not expand value LOCALSTACK_API_KEY in property quarkus.aws.devservices.localstack.container-properties."LOCALSTACK_API_KEY"

How it was possible to set the API key was by using quarkus.aws.devservices.localstack.container-properties.env.vars.localstack-api-key=${LOCALSTACK_API_KEY} in application.properties instead. Also, I tried to set it in testcontainers.properties using localstack.container-properties."LOCALSTACK_API_KEY"=${LOCALSTACK_API_KEY} but it doesn't seem to get the value set.

Pro version

It was possible to download the Localstack pro version but it failed to boot because the API key is missing, this is expected because the container doesn't have the environment variable set. At the moment I haven't found the way to set any variable for testcontainers while booting up. Unless that testcontainers doesn't support the pro version.

How to setup

  1. Create a file src/test/testcontainers.properties
  2. Add the following:
    tinyimage.container.image=public.ecr.aws/docker/library/alpine\:latest
    sshd.container.image=public.ecr.aws/senzing/sshd\:1.4.6
    ryuk.container.image=public.ecr.aws/s4w6t4b6/testcontainers/ryuk\:0.4.0
    localstack.container.image=public.ecr.aws/localstack/localstack\:2.0.2
  3. Add this to application.properties if applies: quarkus.aws.devservices.localstack.container-properties.env.vars.localstack-api-key=${LOCALSTACK_API_KEY}

Thanks for your support

scrocquesel commented 1 year ago

I have pushed a simple repro at https://github.com/scrocquesel/amazon-s3-testlocalstack-pro/blob/master/src/main/resources/application.properties

export LOCALSTACK_API_KEY=mykey
./mvnw test

It starts the container and fails as expected to boot. Container log shows

The API key you provided in the `LOCALSTACK_API_KEY` environment variable '"myk..."(5)' could not be activated against our licensing server. Server message: Unable to verify API key.

This is using extension version 2.0.1, but it works the same with 1.x.

xPTM1219 commented 1 year ago

I tried your test repository with our API key and it didn't worked.

Also, using the pro image is still failing with the following error,

[error]: Build step io.quarkus.amazon.common.deployment.DevServicesLocalStackProcessor#startLocalStackDevService threw an exception: java.lang.RuntimeException: java.lang.IllegalStateException: Failed to verify that image 'localstack/localstack-pro:2.1.1' is a compatible substitute for 'localstack/localstack'. This generally means that you are trying to use an image that Testcontainers has not been designed to use. If this is deliberate, and if you are confident that the image is compatible, you should declare compatibility in code using the `asCompatibleSubstituteFor` method. For example:
   DockerImageName myImage = DockerImageName.parse("localstack/localstack-pro:2.1.1").asCompatibleSubstituteFor("localstack/localstack");
and then use `myImage` instead.

And the the line quarkus.aws.devservices.localstack.container-properties."LOCALSTACK_API_KEY"=${LOCALSTACK_API_KEY} throws an error, the key has to be explicitly written:

Caused by: java.util.NoSuchElementException: SRCFG00011: Could not expand value LOCALSTACK_API_KEY in property quarkus.aws.devservices.localstack.container-properties."LOCALSTACK_API_KEY"

The regular image is still works.

scrocquesel commented 1 year ago

I tried your test repository with our API key and it didn't worked.

Also, using the pro image is still failing with the following error,

[error]: Build step io.quarkus.amazon.common.deployment.DevServicesLocalStackProcessor#startLocalStackDevService threw an exception: java.lang.RuntimeException: java.lang.IllegalStateException: Failed to verify that image 'localstack/localstack-pro:2.1.1' is a compatible substitute for 'localstack/localstack'. This generally means that you are trying to use an image that Testcontainers has not been designed to use. If this is deliberate, and if you are confident that the image is compatible, you should declare compatibility in code using the `asCompatibleSubstituteFor` method. For example:
   DockerImageName myImage = DockerImageName.parse("localstack/localstack-pro:2.1.1").asCompatibleSubstituteFor("localstack/localstack");
and then use `myImage` instead.

And the the line quarkus.aws.devservices.localstack.container-properties."LOCALSTACK_API_KEY"=${LOCALSTACK_API_KEY} throws an error, the key has to be explicitly written:

Caused by: java.util.NoSuchElementException: SRCFG00011: Could not expand value LOCALSTACK_API_KEY in property quarkus.aws.devservices.localstack.container-properties."LOCALSTACK_API_KEY"

The regular image is still works.

I guess you have something wrong in your environment. I run a CI/CD and it works. See https://github.com/scrocquesel/amazon-s3-testlocalstack-pro/actions/runs/4903028460/jobs/8755226610#step:4:2364

Maybe try to clear you maven repository cache.