Skip to content

Commit

Permalink
Merge pull request quarkusio#28101 from sberyozkin/keycloak_devservic…
Browse files Browse the repository at this point in the history
…es_startup_cmd

Allow to change Keycloak start command and show its logs
  • Loading branch information
sberyozkin authored Sep 20, 2022
2 parents 0441f23 + b3bc233 commit 35f3c39
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ public class DevServicesConfig {
@ConfigItem
public Optional<String> 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<String> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -383,10 +385,12 @@ private static class QuarkusOidcContainer extends GenericContainer<QuarkusOidcCo
private String hostName;
private final boolean keycloakX;
private RealmRepresentation realmRep;
private final Optional<String> startCommand;
private final boolean showLogs;

public QuarkusOidcContainer(DockerImageName dockerImageName, OptionalInt fixedExposedPort, boolean useSharedNetwork,
Optional<String> realmPath, String containerLabelValue,
boolean sharedContainer, Optional<String> javaOpts) {
boolean sharedContainer, Optional<String> javaOpts, Optional<String> startCommand, boolean showLogs) {
super(dockerImageName);

this.useSharedNetwork = useSharedNetwork;
Expand All @@ -404,6 +408,8 @@ public QuarkusOidcContainer(DockerImageName dockerImageName, OptionalInt fixedEx
}

this.fixedExposedPort = fixedExposedPort;
this.startCommand = startCommand;
this.showLogs = showLogs;
}

@Override
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 35f3c39

Please sign in to comment.