Skip to content

Commit 5758310

Browse files
authored
fix(keycloak): tests on aarch64, use image from [jboss -> quay], change supported version [16+ -> 18+] (#480)
- jboss/keycloak is discontinued, adapting the official Docker image: https://quay.io/repository/keycloak/keycloak - switched to the latest image version with ARM support fixes #451 fixes #483 ![Screenshot 2024-03-15 at 12 42 29](https://github.com/testcontainers/testcontainers-python/assets/13573675/f82b9372-a94e-45c8-a47b-7ddb4c1c6a57)
1 parent b10d916 commit 5758310

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

modules/keycloak/testcontainers/keycloak/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,21 @@ class KeycloakContainer(DockerContainer):
3636

3737
def __init__(
3838
self,
39-
image="jboss/keycloak:latest",
39+
image="quay.io/keycloak/keycloak:latest",
4040
username: Optional[str] = None,
4141
password: Optional[str] = None,
4242
port: int = 8080,
4343
) -> None:
4444
super().__init__(image=image)
45-
self.username = username or os.environ.get("KEYCLOAK_USER", "test")
46-
self.password = password or os.environ.get("KEYCLOAK_PASSWORD", "test")
45+
self.username = username or os.environ.get("KEYCLOAK_ADMIN", "test")
46+
self.password = password or os.environ.get("KEYCLOAK_ADMIN_PASSWORD", "test")
4747
self.port = port
4848
self.with_exposed_ports(self.port)
4949

5050
def _configure(self) -> None:
51-
self.with_env("KEYCLOAK_USER", self.username)
52-
self.with_env("KEYCLOAK_PASSWORD", self.password)
51+
self.with_env("KEYCLOAK_ADMIN", self.username)
52+
self.with_env("KEYCLOAK_ADMIN_PASSWORD", self.password)
53+
self.with_command("start-dev")
5354

5455
def get_url(self) -> str:
5556
host = self.get_container_host_ip()
@@ -58,8 +59,7 @@ def get_url(self) -> str:
5859

5960
@wait_container_is_ready(requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout)
6061
def _connect(self) -> None:
61-
url = self.get_url()
62-
response = requests.get(f"{url}/auth", timeout=1)
62+
response = requests.get(self.get_url(), timeout=1)
6363
response.raise_for_status()
6464

6565
def start(self) -> "KeycloakContainer":
@@ -70,7 +70,7 @@ def start(self) -> "KeycloakContainer":
7070

7171
def get_client(self, **kwargs) -> KeycloakAdmin:
7272
default_kwargs = {
73-
"server_url": f"{self.get_url()}/auth/",
73+
"server_url": self.get_url(),
7474
"username": self.username,
7575
"password": self.password,
7676
"realm_name": "master",
+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import pytest
2-
31
from testcontainers.keycloak import KeycloakContainer
42

53

6-
@pytest.mark.parametrize("version", ["16.1.1"])
7-
def test_docker_run_keycloak(version: str):
8-
with KeycloakContainer(f"jboss/keycloak:{version}") as kc:
9-
kc.get_client().users_count()
4+
def test_docker_run_keycloak():
5+
with KeycloakContainer("quay.io/keycloak/keycloak:24.0.1") as keycloak_admin:
6+
keycloak_admin.get_client().users_count()

0 commit comments

Comments
 (0)