Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to change Keycloak start command and show its logs #28101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
gastaldi marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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