From b3bc2337ae29fa13f5c9f4c470ec8f49a794507f Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Tue, 20 Sep 2022 17:08:12 +0100 Subject: [PATCH] Allow to change Keycloak start command and show its logs --- .../keycloak/DevServicesConfig.java | 14 ++++++++++++++ .../keycloak/KeycloakDevServicesProcessor.java | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfig.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfig.java index c6a052ad3b0cd..08f34baaf2e6f 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfig.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfig.java @@ -89,6 +89,20 @@ public class DevServicesConfig { @ConfigItem public Optional javaOpts; + /** + * Show Keycloak log messages with a "Keycloak:" prefix. + */ + @ConfigItem(defaultValue = "false") + public boolean showLogs; + + /** + * Keycloak start command. + * Use this property to experiment with Keycloak start options, see {@link https://www.keycloak.org/server/all-config}. + * Note it will be ignored when loading legacy Keycloak WildFly images. + */ + @ConfigItem + public Optional startCommand; + /** * The Keycloak realm name. * This property will be used to create the realm if the realm file pointed to by the 'realm-path' property does not exist, diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java index 817a1a5b20697..5a11fad2a485c 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java @@ -334,7 +334,9 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild capturedDevServicesConfiguration.realmPath, capturedDevServicesConfiguration.serviceName, capturedDevServicesConfiguration.shared, - capturedDevServicesConfiguration.javaOpts); + capturedDevServicesConfiguration.javaOpts, + capturedDevServicesConfiguration.startCommand, + capturedDevServicesConfiguration.showLogs); timeout.ifPresent(oidcContainer::withStartupTimeout); oidcContainer.start(); @@ -383,10 +385,12 @@ private static class QuarkusOidcContainer extends GenericContainer startCommand; + private final boolean showLogs; public QuarkusOidcContainer(DockerImageName dockerImageName, OptionalInt fixedExposedPort, boolean useSharedNetwork, Optional realmPath, String containerLabelValue, - boolean sharedContainer, Optional javaOpts) { + boolean sharedContainer, Optional javaOpts, Optional startCommand, boolean showLogs) { super(dockerImageName); this.useSharedNetwork = useSharedNetwork; @@ -404,6 +408,8 @@ public QuarkusOidcContainer(DockerImageName dockerImageName, OptionalInt fixedEx } this.fixedExposedPort = fixedExposedPort; + this.startCommand = startCommand; + this.showLogs = showLogs; } @Override @@ -436,7 +442,7 @@ protected void configure() { if (keycloakX) { addEnv(KEYCLOAK_QUARKUS_ADMIN_PROP, KEYCLOAK_ADMIN_USER); addEnv(KEYCLOAK_QUARKUS_ADMIN_PASSWORD_PROP, KEYCLOAK_ADMIN_PASSWORD); - withCommand(KEYCLOAK_QUARKUS_START_CMD + withCommand(startCommand.orElse(KEYCLOAK_QUARKUS_START_CMD) + (useSharedNetwork ? " --hostname-port=" + fixedExposedPort.getAsInt() : "")); } else { addEnv(KEYCLOAK_WILDFLY_USER_PROP, KEYCLOAK_ADMIN_USER); @@ -469,6 +475,12 @@ protected void configure() { addEnv(KEYCLOAK_WILDFLY_IMPORT_PROP, KEYCLOAK_DOCKER_REALM_PATH); } + if (showLogs) { + super.withLogConsumer(t -> { + LOG.info("Keycloak: " + t.getUtf8String()); + }); + } + LOG.infof("Using %s powered Keycloak distribution", keycloakX ? "Quarkus" : "WildFly"); super.setWaitStrategy(Wait.forLogMessage(".*Keycloak.*started.*", 1)); }