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

KeycloakContainer and Keycloak service refactoring, Keycloak image bump and resulting OCP fixes #986

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
@@ -1,5 +1,8 @@
package io.quarkus.qe;

import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM;
import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM_BASE_PATH;
import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM_FILE;
import static org.hamcrest.Matchers.equalTo;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -12,14 +15,12 @@

public abstract class BaseSecurityResourceIT {

static final String REALM_BASE_PATH = "realms";
static final String REALM_DEFAULT = "test-realm";
static final String CLIENT_ID_DEFAULT = "test-application-client";
static final String CLIENT_SECRET_DEFAULT = "test-application-client-secret";
static final String NORMAL_USER = "test-normal-user";

@KeycloakContainer(command = { "start-dev --import-realm" })
static KeycloakService keycloak = new KeycloakService("/keycloak-realm.json", REALM_DEFAULT, REALM_BASE_PATH);
@KeycloakContainer(command = { "start-dev", "--import-realm" })
static KeycloakService keycloak = new KeycloakService(DEFAULT_REALM_FILE, DEFAULT_REALM, DEFAULT_REALM_BASE_PATH);

private AuthzClient authzClient;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.quarkus.qe;

import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM;
import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM_BASE_PATH;
import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM_FILE;

import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.KeycloakService;
Expand All @@ -11,12 +15,12 @@
@OpenShiftScenario
public class OpenShiftUsingCustomTemplateResourceIT {

private static final String REALM_DEFAULT = "test-realm";
private static final String CLIENT_ID_DEFAULT = "test-application-client";
private static final String CLIENT_SECRET_DEFAULT = "test-application-client-secret";

@Container(image = "quay.io/keycloak/keycloak:22.0.1", expectedLog = "started", port = 8080)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't here be also newer Keycloak?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea why there is hardcoded image instead of @KeycloakContainer used, but I suppose we can do it in a separate PR? I'm happy to change annotation, but I'd like to make release and fix TS.

Also @gtroitsk have some ticket on getting rid of hardcoded images, maybe he can take care of it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok no problem with this. Make sense to leave it the task with removing hardcoded images.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; @gtroitsk please create PR (ideally with others if there are such hardcoded images) and link it with this one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it after finish with TS related stuff

static final KeycloakService customkeycloak = new KeycloakService("/keycloak-realm.json", REALM_DEFAULT);
static final KeycloakService customkeycloak = new KeycloakService(DEFAULT_REALM_FILE, DEFAULT_REALM,
DEFAULT_REALM_BASE_PATH);

@QuarkusApplication
static final RestService app = new RestService()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static java.util.regex.Pattern.quote;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -119,10 +121,11 @@ protected String replaceDeploymentContent(String content) {
content = content.replaceAll(quote(customServiceName), model.getContext().getOwner().getName());
}

String args = Arrays.stream(model.getCommand()).map(cmd -> "\"" + cmd + "\"").collect(Collectors.joining(", "));
return content.replaceAll(quote("${IMAGE}"), model.getImage())
.replaceAll(quote("${SERVICE_NAME}"), model.getContext().getName())
.replaceAll(quote("${INTERNAL_PORT}"), "" + model.getPort())
.replaceAll(quote("${ARGS}"), String.join(" ", model.getCommand()));
.replaceAll(quote("${ARGS}"), args);
}

private void applyDeployment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

public class KeycloakService extends BaseService<KeycloakService> {

public static final String DEFAULT_REALM_BASE_PATH = "/realms";
public static final String DEFAULT_REALM = "test-realm";
public static final String DEFAULT_REALM_FILE = "/keycloak-realm.json";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for adding these in one place.

private static final String REALM_DEST_PATH = "/opt/keycloak/data/import";
private static final String USER = "admin";
private static final String PASSWORD = "admin";
Expand All @@ -33,16 +36,6 @@ public KeycloakService(String realmFile, String realmName, String realmBasePath)
withProperty("KEYCLOAK_REALM_IMPORT", "resource_with_destination::" + REALM_DEST_PATH + "|" + realmFile);
}

/**
* Legacy constructor used by previous versions of Keycloak 18.
*/
@Deprecated
public KeycloakService(String realmFile, String realmName) {
this(realmName);
withProperty("KEYCLOAK_IMPORT", "resource::" + realmFile);
withProperty("KEYCLOAK_REALM_IMPORT", "resource_with_destination::" + REALM_DEST_PATH + "|" + realmFile);
}

public KeycloakService(String realmName) {
this.realm = realmName;
withProperty("KEYCLOAK_ADMIN", USER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface KeycloakContainer {
String image() default "quay.io/keycloak/keycloak:22.0.1";
String image() default "quay.io/keycloak/keycloak:23.0";

int port() default 8080;

String expectedLog() default "started";
String expectedLog() default "started in";

String[] command() default {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.quarkus.test.bootstrap.ManagedResource;
import io.quarkus.test.bootstrap.ServiceContext;
import io.quarkus.test.services.KeycloakContainer;
import io.quarkus.test.utils.PropertiesUtils;

public class KeycloakContainerManagedResourceBuilder extends ContainerManagedResourceBuilder {

Expand Down Expand Up @@ -46,9 +47,9 @@ protected String getExpectedLog() {
@Override
public void init(Annotation annotation) {
rsvoboda marked this conversation as resolved.
Show resolved Hide resolved
KeycloakContainer metadata = (KeycloakContainer) annotation;
this.image = metadata.image();
this.image = PropertiesUtils.resolveProperty(metadata.image());
this.restPort = metadata.port();
this.expectedLog = metadata.expectedLog();
this.expectedLog = PropertiesUtils.resolveProperty(metadata.expectedLog());
this.command = metadata.command();
}

Expand Down