From 5758310532b8a8e1303a24bc534fa8aeb0f75eb2 Mon Sep 17 00:00:00 2001 From: Max Pfeiffer Date: Thu, 21 Mar 2024 09:45:58 +0100 Subject: [PATCH] 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 https://github.com/testcontainers/testcontainers-python/issues/451 fixes https://github.com/testcontainers/testcontainers-python/issues/483 ![Screenshot 2024-03-15 at 12 42 29](https://github.com/testcontainers/testcontainers-python/assets/13573675/f82b9372-a94e-45c8-a47b-7ddb4c1c6a57) --- .../keycloak/testcontainers/keycloak/__init__.py | 16 ++++++++-------- modules/keycloak/tests/test_keycloak.py | 9 +++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/modules/keycloak/testcontainers/keycloak/__init__.py b/modules/keycloak/testcontainers/keycloak/__init__.py index 2e8f7738..ff7a64c2 100644 --- a/modules/keycloak/testcontainers/keycloak/__init__.py +++ b/modules/keycloak/testcontainers/keycloak/__init__.py @@ -36,20 +36,21 @@ class KeycloakContainer(DockerContainer): def __init__( self, - image="jboss/keycloak:latest", + image="quay.io/keycloak/keycloak:latest", username: Optional[str] = None, password: Optional[str] = None, port: int = 8080, ) -> None: super().__init__(image=image) - self.username = username or os.environ.get("KEYCLOAK_USER", "test") - self.password = password or os.environ.get("KEYCLOAK_PASSWORD", "test") + self.username = username or os.environ.get("KEYCLOAK_ADMIN", "test") + self.password = password or os.environ.get("KEYCLOAK_ADMIN_PASSWORD", "test") self.port = port self.with_exposed_ports(self.port) def _configure(self) -> None: - self.with_env("KEYCLOAK_USER", self.username) - self.with_env("KEYCLOAK_PASSWORD", self.password) + self.with_env("KEYCLOAK_ADMIN", self.username) + self.with_env("KEYCLOAK_ADMIN_PASSWORD", self.password) + self.with_command("start-dev") def get_url(self) -> str: host = self.get_container_host_ip() @@ -58,8 +59,7 @@ def get_url(self) -> str: @wait_container_is_ready(requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout) def _connect(self) -> None: - url = self.get_url() - response = requests.get(f"{url}/auth", timeout=1) + response = requests.get(self.get_url(), timeout=1) response.raise_for_status() def start(self) -> "KeycloakContainer": @@ -70,7 +70,7 @@ def start(self) -> "KeycloakContainer": def get_client(self, **kwargs) -> KeycloakAdmin: default_kwargs = { - "server_url": f"{self.get_url()}/auth/", + "server_url": self.get_url(), "username": self.username, "password": self.password, "realm_name": "master", diff --git a/modules/keycloak/tests/test_keycloak.py b/modules/keycloak/tests/test_keycloak.py index 70eff57c..f6d29a4e 100644 --- a/modules/keycloak/tests/test_keycloak.py +++ b/modules/keycloak/tests/test_keycloak.py @@ -1,9 +1,6 @@ -import pytest - from testcontainers.keycloak import KeycloakContainer -@pytest.mark.parametrize("version", ["16.1.1"]) -def test_docker_run_keycloak(version: str): - with KeycloakContainer(f"jboss/keycloak:{version}") as kc: - kc.get_client().users_count() +def test_docker_run_keycloak(): + with KeycloakContainer("quay.io/keycloak/keycloak:24.0.1") as keycloak_admin: + keycloak_admin.get_client().users_count()