diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index edbec345..b00b79b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,11 @@ jobs: matrix: os: ["ubuntu-latest"] python-version: ["3.11"] + include: + - os: "macos-latest" + python-version: "3.11" + - os: "windows-latest" + python-version: "3.11" env: OS: ${{ matrix.os }} @@ -29,6 +34,15 @@ jobs: - name: Acquire sources uses: actions/checkout@v4 + - name: Set up Docker + uses: docker-practice/actions-setup-docker@master + timeout-minutes: 12 + + - name: Probe Docker + run: | + docker version + docker run --rm hello-world + - name: Set up Python uses: actions/setup-python@v4 with: diff --git a/cratedb_toolkit/testing/testcontainers/cratedb.py b/cratedb_toolkit/testing/testcontainers/cratedb.py index 7ee6f46a..bb826882 100644 --- a/cratedb_toolkit/testing/testcontainers/cratedb.py +++ b/cratedb_toolkit/testing/testcontainers/cratedb.py @@ -15,6 +15,7 @@ from typing import Optional from testcontainers.core.config import MAX_TRIES +from testcontainers.core.docker_client import DockerClient from testcontainers.core.generic import DbContainer from testcontainers.core.waiting_utils import wait_for_logs @@ -85,6 +86,12 @@ def _configure(self) -> None: self.with_env("CRATEDB_PASSWORD", self.CRATEDB_PASSWORD) self.with_env("CRATEDB_DB", self.CRATEDB_DB) + """ + if "CI" in os.environ: + docker_host = get_docker_host() + self.with_env("DOCKER_HOST", docker_host).with_env("DOCKER_CERT_PATH", "").with_env("DOCKER_TLS_VERIFY", "") + """ + def get_connection_url(self, host=None) -> str: # TODO: When using `db_name=self.CRATEDB_DB`: # Connection.__init__() got an unexpected keyword argument 'database' @@ -143,3 +150,27 @@ def stop(self, **kwargs): logger.info("Stopping CrateDB") return super().stop() return None + + +def get_docker_host(): + """ + https://github.com/testcontainers/testcontainers-python/blob/main/core/tests/test_docker_in_docker.py + """ + # real dind isn't possible (AFAIK) in CI + # forwarding the socket to a container port is at least somewhat the same + client = DockerClient() + not_really_dind = client.run( + image="alpine/socat", + command="tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock", + volumes={"/var/run/docker.sock": {"bind": "/var/run/docker.sock"}}, + detach=True, + ) + + not_really_dind.start() + + # get ip address for DOCKER_HOST + # avoiding DockerContainer class here to prevent code changes affecting the test + specs = client.get_container(not_really_dind.id) + docker_host_ip = specs["NetworkSettings"]["Networks"]["bridge"]["IPAddress"] + docker_host = f"tcp://{docker_host_ip}:2375" + return docker_host