Using Crate JDBC in Dockerfile for Keycloak

Hello everyone,
I want to use CrateDB for my Keycloak server that is running as a Docker Container. Using the Postgres Driver that Keycloak offers, I get some problems with SQL statements that are not supported by Crate (ROLLBACK amongst others). So I figured I can try using the Crate JDBC standalone driver instead.
In my dockerfile, I am downloading the jar and then adding the path to the Classpath. Then I am using the Crate URL and login which work for example in Spring Boot. My Dockerfile is attached below. However when running the container, I get the Exception

java.lang.ClassNotFoundException: io.crate.client.jdbc.CrateDriver

I am not sure where there problem is here. I can see that the jar is correctly downloaded into the drivers folder. Is the drivers name ( io.crate.client.jdbc.CrateDriver) correct or do I need to provide a whole path? Or is there any problem that prohibits using Keycloak and Crate together at all?

Dockerfile:

> 
> FROM quay.io/keycloak/keycloak:latest as builder
> 
> # Configure a database vendor
> ENV KC_DB=postgres
> 
> WORKDIR /opt/keycloak
> 
> RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore
> RUN /opt/keycloak/bin/kc.sh build
> 
> FROM quay.io/keycloak/keycloak:latest
> COPY --from=builder /opt/keycloak/ /opt/keycloak/
> 
> ADD --chown=keycloak:keycloak https://repo1.maven.org/maven2/io/crate/crate-jdbc-standalone/2.7.0/crate-jdbc-standalone-2.7.0.jar /drivers/
> 
> ENV CLASSPATH=/drivers/crate-jdbc-standalone-2.7.0.jar
> 
> ENV KC_DB=postgres
> ENV KC_DB_URL=jdbc:postgresql://<ip_address>:5432/doc
> ENV KC_DB_USERNAME=user
> ENV KC_DB_PASSWORD=password
> ENV KC_DB_DRIVER=io.crate.client.jdbc.CrateDriver
> ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]

Hi,
io.crate.client.jdbc.CrateDriver is the correct class name for the CrateDB JDBC driver.
I do not have experience with Keycloak, but maybe instead of trying to set the class path you could find the directory where the other drivers are and place the jar there?

Another option is that I see Keycloak has some settings with intriguing names for which I could not find any documentation: transaction-xa-enabled / KC_DB_TX_TYPE
Maybe disabling these it could work against CrateDB with the standard PostgreSQL driver?

1 Like

Thank you for your response!

I tried it with the directory in which I found the postgres Driver:

ADD --chown=keycloak:keycloak https://repo1.maven.org/maven2/io/crate/crate-jdbc-standalone/2.7.0/crate-jdbc-standalone-2.7.0.jar /opt/keycloak/lib/lib/main/
ENV CLASSPATH=/opt/keycloak/lib/lib/main/crate-jdbc-standalone-2.7.0.jar
...
ENV KC_DB_DRIVER=io.crate.client.jdbc.CrateDriver

I still get the same exception.

I tried running the docker container without specifiying a custom driver in the dockerfile and using this command:

docker run -p 8443:8443 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -e KC_DB_TX_TYPE=disabled cratecloak --verbose start-dev --transaction-xa-enabled=false

but I still get the problem
PSQLException: ERROR: line 1:1: mismatched input 'ROLLBACK'