I am trying to add a custom spi for keycloak. I would like to use docker to proceed. Here is my dockerfile:
FROM maven:3.8.4-openjdk-17 AS build
WORKDIR /app
COPY . /app/
RUN mvn clean package
FROM quay.io/keycloak/keycloak:23.0.7
COPY --from=build app/target/keycloak-spi-kafka.jar /opt/keycloak/providers
RUN /opt/keycloak/bin/kc.sh build
ENTRYPOINT ["/opt/keycloak/bin/kc.sh", "start-dev"]
Doing that, I am able to find my .jar file, however, when I launch my docker image, I am not able to find my custom spi. I think it should be accessible there:

but that is not the case…
I followed the official documentation on containers in order to construct my Dockerfile
If any of you have advice, that would be highly appreciate.
PS: when I run kc.sh show-config I can see that:
kc.provider.file.keycloak-spi-kafka.jar.last-modified = 1710451764793 (PersistedConfigSource)
which seems to mean that my custom spi is added
PPS: Here is the link to my github repo, if it may help to have the code:
You are missing the meta-inf part which helps keycloak to discover your SPI.
See Server Developer Guide
Alternatively you could use the @AutoService annotation https://www.baeldung.com/google-autoservice for the EventListenerProviderFactory.
2 Likes
Sorry but what am I missing?
In my repo I have the META-INF/services file. I inspired myself from this repo, even if it is a bit old.
I can see three thing I have not understood about this file:
-
What the file has to contain. Following This medium post, I have only write the class’ name, but maybe I misunderstood
-
The file has to be copied within my custom image, in this case I have no idea where it has to be past in?
-
I may have made a typo somewhere, since I am not used to Java class name, I may have made a typo in some class name.
If it is something else, please take some lines in order to briefly explain what I am missing so far
Thank you for your response
my bad, i only looked into the source directory.
It might be due to your repository layout, storing it at the root of the project.
You can check with anything that can open zip archives whether it is actually copied into the final jar file.
Otherwise you might have to put it into the src/main/java and src/main/resources file structure.
1 Like
That’s it, now it is working.
Thank you very much