Skip to content

Commit

Permalink
fix(keycloak): tests on aarch64, use image from [jboss -> quay], chan…
Browse files Browse the repository at this point in the history
…ge 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)
  • Loading branch information
max-pfeiffer committed Mar 21, 2024
1 parent b10d916 commit 5758310
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
16 changes: 8 additions & 8 deletions modules/keycloak/testcontainers/keycloak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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":
Expand All @@ -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",
Expand Down
9 changes: 3 additions & 6 deletions modules/keycloak/tests/test_keycloak.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 5758310

Please sign in to comment.