Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Add testing on macOS and Windows #60

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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:
Expand Down
31 changes: 31 additions & 0 deletions cratedb_toolkit/testing/testcontainers/cratedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -85,6 +86,12 @@
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'
Expand Down Expand Up @@ -143,3 +150,27 @@
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(

Check warning on line 162 in cratedb_toolkit/testing/testcontainers/cratedb.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/testcontainers/cratedb.py#L161-L162

Added lines #L161 - L162 were not covered by tests
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()

Check warning on line 169 in cratedb_toolkit/testing/testcontainers/cratedb.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/testcontainers/cratedb.py#L169

Added line #L169 was not covered by tests

# 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

Check warning on line 176 in cratedb_toolkit/testing/testcontainers/cratedb.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/testcontainers/cratedb.py#L173-L176

Added lines #L173 - L176 were not covered by tests
Loading