dasniko / testcontainers-keycloak

A Testcontainer implementation for Keycloak IAM & SSO.
Apache License 2.0
328 stars 51 forks source link

DB_ADDR: unbound variable #15

Closed lmsurpre closed 3 years ago

lmsurpre commented 3 years ago

I grabbed the latest from master, loaded it into eclipse, and tried to execute KeycloakContainerTest.java but the container failed to start.

I thought it had worked for me the first time, but I have no idea why it would suddenly stop working, and so I'm guessing that I had just missed the log output that said it failed.

14:00:50.987 [main] INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
14:00:51.814 [main] INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
14:00:51.815 [main] INFO  org.testcontainers.DockerClientFactory - Docker host IP address is localhost
14:00:51.870 [main] INFO  org.testcontainers.DockerClientFactory - Connected to docker: 
  Server Version: 19.03.13
  API Version: 1.40
  Operating System: Docker Desktop
  Total Memory: 7962 MB
14:00:51.875 [main] INFO  org.testcontainers.utility.ImageNameSubstitutor - Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
14:00:52.915 [main] INFO  org.testcontainers.DockerClientFactory - Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
14:00:52.915 [main] INFO  org.testcontainers.DockerClientFactory - Checking the system...
14:00:52.916 [main] INFO  org.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
14:00:53.064 [main] INFO  org.testcontainers.DockerClientFactory - ✔︎ Docker environment should have more than 2GB free disk space
14:00:53.424 [main] INFO  🐳 [quay.io/keycloak/keycloak:12.0.1] - Creating container for image: quay.io/keycloak/keycloak:12.0.1
14:00:53.558 [main] INFO  🐳 [quay.io/keycloak/keycloak:12.0.1] - Starting container with ID: 6d5668aa062ba6c8bb4fb6df85fad14149e750c75fd76c9ffd0f0eaf29a49602
14:00:54.016 [main] INFO  🐳 [quay.io/keycloak/keycloak:12.0.1] - Container quay.io/keycloak/keycloak:12.0.1 is starting: 6d5668aa062ba6c8bb4fb6df85fad14149e750c75fd76c9ffd0f0eaf29a49602
14:00:54.037 [main] INFO  org.testcontainers.containers.wait.strategy.HttpWaitStrategy - /dazzling_williamson: Waiting for 120 seconds for URL: http://localhost:32840/auth
14:02:54.063 [main] ERROR 🐳 [quay.io/keycloak/keycloak:12.0.1] - Could not start container
java.lang.IllegalStateException: Container exited with code 1
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:469)
    at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:325)
    at org.testcontainers.containers.GenericContainer$$Lambda$160/0x0000000000000000.call(Unknown Source)
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:323)
    at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:311)
    at dasniko.testcontainers.keycloak.KeycloakContainerTest.shouldStartKeycloak(KeycloakContainerTest.java:21)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
14:02:54.108 [main] ERROR 🐳 [quay.io/keycloak/keycloak:12.0.1] - Log output from the failed container:
Added 'admin' to '/opt/jboss/keycloak/standalone/configuration/keycloak-add-user.json', restart server to load user

/opt/jboss/tools/docker-entrypoint.sh: line 165: DB_ADDR: unbound variable
lmsurpre commented 3 years ago

I checked the docker-entrypoint.sh and it should only get to this line if DB_VENDOR is set to "postgres". I looked all over and I cannot understand what could be setting that. I ended up working around the issue by dropping this line into KeycloakContainer.configure:

withEnv("DB_VENDOR", "H2");

With that, its now working for me.

dasniko commented 3 years ago

This seems to be a configuration issue with your local/used environment, not with the Keycloak Testcontainer itself.

See also here, perhaps there's an approach which may help you: https://keycloak.discourse.group/t/db-addr-unbound-variable-error/2077

lmsurpre commented 3 years ago

Thanks @dasniko. I still have no clue why Keycloak thinks it should use Postgres (I double-checked that I have no related env vars in my session), but as I mentioned above I was able to override that by explicitly setting DB_VENDOR to H2. I agree thats not an issue with this project, so let's mark this one closed.

lmsurpre commented 3 years ago

Figured out the cause of my issue and posted it at https://keycloak.discourse.group/t/db-addr-unbound-variable-error/2077/12

The keycloak db type detection algorithm seems a bit brittle, so it might be a good idea to recommend folks to set DB_VENDOR explicitly.

dasniko commented 3 years ago

Good hint, @lmsurpre Will think about setting this as a default. Thank you!