Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: testcontainers/testcontainers-python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: testcontainers-v4.5.0
Choose a base ref
...
head repository: testcontainers/testcontainers-python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: testcontainers-v4.5.1
Choose a head ref
  • 5 commits
  • 7 files changed
  • 6 contributors

Commits on May 27, 2024

  1. chore: add .gitattributes file for shell scripts (#581)

    Just a .gitattributes file to checkout .sh files with LF line ending for
    people coming from Windows world.
    
    ---------
    
    Co-authored-by: David Ankin <daveankin@gmail.com>
    saikotek and alexanderankin authored May 27, 2024

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    8fe2d6d View commit details
  2. chore(core): Adds integration testing to the private registry auth fe…

    …ature (DOCKER_AUTH_CONFIG) (#582)
    
    Follow up on #566 - Testing using the registry module
    Tranquility2 authored May 27, 2024

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    78b6f0e View commit details
  3. fix(keycloak): realm import (#584)

    With the option to import keycloak realms, introduced with #565,
    the[_configure()](https://github.com/testcontainers/testcontainers-python/blob/78b6f0ecb15e8cba687eb4588c5ce19ca32208bc/modules/keycloak/testcontainers/keycloak/__init__.py#L57)
    method is called twice. Once it is called in the
    [start()](https://github.com/testcontainers/testcontainers-python/blob/78b6f0ecb15e8cba687eb4588c5ce19ca32208bc/modules/keycloak/testcontainers/keycloak/__init__.py#L83)
    method of keycloak itself and then it is called a second time in the
    [start()](https://github.com/testcontainers/testcontainers-python/blob/78b6f0ecb15e8cba687eb4588c5ce19ca32208bc/core/testcontainers/core/container.py#L90)
    method of DockerContainer. This wasn't an issue so far. But if a realm
    shall be imported (self.has_realm_import in keycloak is True), then
    every time the string " --import-realm" is added to the start command in
    the _configure() method. The keycloak container won't start if
    "--import-realm" is specified multiple times.
    This is probably the easiest solution to solve the issue. If wished, I
    can also work on a more robust solution, e.g. by storing the start
    command in a list and checking that "--import-realm" is only added once.
    
    Co-authored-by: Sebastian Scholz <sebastian.scholz@cemocom.de>
    sebassz and Sebastian Scholz authored May 27, 2024
    Copy the full SHA
    111bd09 View commit details

Commits on May 31, 2024

  1. fix(k3s): add configuration parameter for disabling cgroup mount to a…

    …void "unable to apply cgroup configuration" (#592)
    
    relates to #591
    alexanderankin authored May 31, 2024
    Copy the full SHA
    8917772 View commit details
  2. chore(main): release testcontainers 4.5.1 (#586)

    🤖 I have created a release *beep* *boop*
    ---
    
    
    ##
    [4.5.1](testcontainers-v4.5.0...testcontainers-v4.5.1)
    (2024-05-31)
    
    
    ### Bug Fixes
    
    * **k3s:** add configuration parameter for disabling cgroup mount to
    avoid "unable to apply cgroup configuration"
    ([#592](#592))
    ([8917772](8917772))
    * **keycloak:** realm import
    ([#584](#584))
    ([111bd09](111bd09))
    
    ---
    This PR was generated with [Release
    Please](https://github.com/googleapis/release-please). See
    [documentation](https://github.com/googleapis/release-please#release-please).
    
    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    github-actions[bot] authored May 31, 2024
    Copy the full SHA
    a95af7d View commit details
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Shell scripts
*.sh text eol=lf
2 changes: 1 addition & 1 deletion .github/.release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "4.5.0"
".": "4.5.1"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [4.5.1](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.5.0...testcontainers-v4.5.1) (2024-05-31)


### Bug Fixes

* **k3s:** add configuration parameter for disabling cgroup mount to avoid "unable to apply cgroup configuration" ([#592](https://github.com/testcontainers/testcontainers-python/issues/592)) ([8917772](https://github.com/testcontainers/testcontainers-python/commit/8917772d8c90d26086af3b9606657c95928e2b9d))
* **keycloak:** realm import ([#584](https://github.com/testcontainers/testcontainers-python/issues/584)) ([111bd09](https://github.com/testcontainers/testcontainers-python/commit/111bd094428b83233d7eca693d94e10b34ee8ae8))

## [4.5.0](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.4.1...testcontainers-v4.5.0) (2024-05-25)


83 changes: 83 additions & 0 deletions core/tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""Integration test using login to a private registry.
Note: Using the testcontainers-python library to test the Docker registry.
This could be considered a bad practice as it is not recommended to use the same library to test itself.
However, it is a very good use case for DockerRegistryContainer and allows us to test it thoroughly.
"""

import json
import os
import base64
import pytest

from docker.errors import NotFound

from testcontainers.core.config import testcontainers_config
from testcontainers.core.container import DockerContainer
from testcontainers.core.docker_client import DockerClient
from testcontainers.core.waiting_utils import wait_container_is_ready

from testcontainers.registry import DockerRegistryContainer


def test_missing_on_private_registry(monkeypatch):
username = "user"
password = "pass"
image = "hello-world"
tag = "test"

with DockerRegistryContainer(username=username, password=password) as registry:
registry_url = registry.get_registry()

# prepare auth config
creds: bytes = base64.b64encode(f"{username}:{password}".encode("utf-8"))
config = {"auths": {f"{registry_url}": {"auth": creds.decode("utf-8")}}}
monkeypatch.setattr(testcontainers_config, name="docker_auth_config", value=json.dumps(config))
assert testcontainers_config.docker_auth_config, "docker_auth_config not set"

with pytest.raises(NotFound):
# Test a container with image from private registry
with DockerContainer(f"{registry_url}/{image}:{tag}") as test_container:
wait_container_is_ready(test_container)


@pytest.mark.parametrize(
"image,tag,username,password",
[
("nginx", "test", "user", "pass"),
("hello-world", "latest", "new_user", "new_pass"),
("alpine", "3.12", None, None),
],
)
def test_with_private_registry(image, tag, username, password, monkeypatch):
client = DockerClient().client

with DockerRegistryContainer(username=username, password=password) as registry:
registry_url = registry.get_registry()

# prepare image
_image = client.images.pull(image)
assert _image.tag(repository=f"{registry_url}/{image}", tag=tag), "Image not tagged"

# login to private registry
client.login(registry=registry_url, username=username, password=password)

# push image to private registry
client.images.push(f"{registry_url}/{image}")

# clear local image so we will pull from private registry
client.images.remove(f"{registry_url}/{image}:{tag}")

# prepare auth config
creds: bytes = base64.b64encode(f"{username}:{password}".encode("utf-8"))
config = {"auths": {f"{registry_url}": {"auth": creds.decode("utf-8")}}}
monkeypatch.setattr(testcontainers_config, name="docker_auth_config", value=json.dumps(config))
assert testcontainers_config.docker_auth_config, "docker_auth_config not set"

# Test a container with image from private registry
with DockerContainer(f"{registry_url}/{image}:{tag}") as test_container:
wait_container_is_ready(test_container)

# cleanup
client.images.remove(f"{registry_url}/{image}:{tag}")
client.close()
9 changes: 7 additions & 2 deletions modules/k3s/testcontainers/k3s/__init__.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import logging

from testcontainers.core.config import testcontainers_config
from testcontainers.core.container import DockerContainer
from testcontainers.core.waiting_utils import wait_for_logs
@@ -37,13 +39,16 @@ class K3SContainer(DockerContainer):
KUBE_SECURE_PORT = 6443
RANCHER_WEBHOOK_PORT = 8443

def __init__(self, image="rancher/k3s:latest", **kwargs) -> None:
def __init__(self, image="rancher/k3s:latest", enable_cgroup_mount=True, **kwargs) -> None:
super().__init__(image, **kwargs)
self.with_exposed_ports(self.KUBE_SECURE_PORT, self.RANCHER_WEBHOOK_PORT)
self.with_env("K3S_URL", f"https://{self.get_container_host_ip()}:{self.KUBE_SECURE_PORT}")
self.with_command("server --disable traefik --tls-san=" + self.get_container_host_ip())
self.with_kwargs(privileged=True, tmpfs={"/run": "", "/var/run": ""})
self.with_volume_mapping("/sys/fs/cgroup", "/sys/fs/cgroup", "rw")
if enable_cgroup_mount:
self.with_volume_mapping("/sys/fs/cgroup", "/sys/fs/cgroup", "rw")
else:
logging.warning("'enable_cgroup_mount' is experimental, see testcontainers/testcontainers-python#591)")

def _connect(self) -> None:
wait_for_logs(self, predicate="Node controller sync successful", timeout=testcontainers_config.timeout)
1 change: 0 additions & 1 deletion modules/keycloak/testcontainers/keycloak/__init__.py
Original file line number Diff line number Diff line change
@@ -80,7 +80,6 @@ def _readiness_probe(self) -> None:
wait_for_logs(self, "Added user .* to realm .*")

def start(self) -> "KeycloakContainer":
self._configure()
super().start()
self._readiness_probe()
return self
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "testcontainers"
version = "4.5.0" # auto-incremented by release-please
version = "4.5.1" # auto-incremented by release-please
description = "Python library for throwaway instances of anything that can run in a Docker container"
authors = ["Sergey Pirogov <automationremarks@gmail.com>"]
maintainers = [