Developer experience for extensions

137 views
Skip to first unread message

Zed Spencer-Milnes

unread,
Feb 19, 2024, 11:14:43 AM2/19/24
to Keycloak Dev
Hi all,

I was trying to tighten up my own developer experience for Keycloak extensions (and later theming) but hit some roadblocks, so I wanted to share and also see what others are doing.

In an ideal world, I was looking for something equivalent to the Quarkus "dev" mode, where it integrates nicely into IDE tooling (debug session) and/or build tools like gradle etc.

I have been attempting to write a Gradle plugin for Keycloak extension development but am hitting my head against how the Quarkus deployments work.

In an ideal world, I would have a task that fairly transparently creates a Keycloak deployment and, copies the output of my build (and required libs) into the providers directory and starts the keycloak in dev mode. It should hook into the IDE integrations gradle run and debugging plumbing etc

I can see my classpath is resolving sensibly, but I can't get the Quarkus app to boot/re-augment/etc.. I've tried booting into KeycloakMain,QuarkusEntryPoint and IDELauncher to no avail (errors relate to not finding the required runtime dat files the quarkus build process find, and unable to launch in "IDE" mode as assumptions about path locations are broken as Keycloak extensions aren't the main quarkus entrypoint.

Is this too deep a rabbit hole? I thought it would be somewhat easier to boot just off the downloaded dependencies. What are other people doing?

in progress code is here https://github.com/GingerGeek/keycloak-extension-experiments/ (plugin is in buildSrc - no extension being built in this repo) (edited) 

I went through most of the projects on https://www.keycloak.org/extensions.html and came across the following projects which had done some work on having an easier test flow:
I'm unsure if I'm missing something obvious (hence why I'd like to know what others are doing) but I would be quite happy to partake/contribute in community effort if there's interest in looking into DX for extension!


Best regards,
Zed

Thomas Darimont

unread,
Feb 19, 2024, 12:56:37 PM2/19/24
to Keycloak Dev
Hello Zed,

Quarkus Dev Mode or a Keycloak Quarkus Server based on a Spring boot like Starters or an imaginary "Quarkus Keycloak Extension" is a is a long-cherished developer dream.
A few years ago, I experimented with something similar, but haven't looked at it for a while.

In the meantime you can use the `org.keycloak.Keycloak` class from the keycloak-junit5 module. 

With it you can start an embedded Keycloak Quarkus Server similar to the Undertow Keycloak server from the testutils module.

I'm currently using the Junit5 Keycloak server for local Keycloak development and bug fixing:

```

Module: keycloak-junit5
Class: org.keycloak.Keycloak

CLI options:
--verbose
start-dev
--features=preview
--cache=local
--http-enabled=true
--http-port=8081
--http-relative-path=auth
--db=dev-file
--db-url="jdbc:h2:file:../keycloak-data/data/keycloak_24snapshot_masterX1;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=VALUE"
--log-level=info,org.keycloak.services:debug
```

Cheers,
Thomas

Zed Spencer-Milnes

unread,
Feb 20, 2024, 7:10:02 PM2/20/24
to Keycloak Dev
Hi Thomas,

Appreciate your time and response here.

Do you use this whilst you're developing Keycloak itself or whilst developing extensions?

I attempted to use the Junit class directly but it still didn't play ball ("io.quarkus.bootstrap.resolver.AppModelResolverException: org.keycloak:keycloak-quarkus-server:null is missing version and is not found among the dependency constraints").

Yes on the embedded concept, it's interesting: is the proposal that an extension developer would effectively create a "standard" Quarkus project, include a Keycloak extension which runs Keycloak in-app (and then deployment would look much more a standard quarkus app than the current Keycloak method)? I guess the downside of this via building providers/plugins is it would be more complex to have "multiple" extensions and some of the helpful args Keycloak currently adds to JVM start would be lost.

I think sticking to the "build-a-plugin" concept initially makes the most sense for me (ie build process spits out something to put in the providers folder of your deployment)

Looking into the mechanics of the Keycloak class in JUnit5 it looks like there is a customisation of the Quarkus bootstrap process. I will try and see if I can adopt something similar to create a module that can bootstrap without some of the assumptions Quarkus makes but looking through the Quarkus code it seems quite involved... should be fun!

Will let you know how I get on 

Best regards,
Zed

Reply all
Reply to author
Forward
0 new messages