Skip to content

Commit

Permalink
Add diagnostics for tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tillahoffmann committed Dec 17, 2021
1 parent fcbad41 commit d48294c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ jobs:
python -m pip install --upgrade pip
pip install wheel
pip install -r requirements/${{ matrix.python-version }}.txt
- name: Run docker diagnostics
run: |
echo "Build minimal container for docker-in-docker diagnostics"
docker build -f Dockerfile.diagnostics -t testcontainers-python .
echo "Bare metal diagnostics"
python diagnostics.py
echo "Container diagnostics with bridge network"
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --network=bridge testcontainers-python python diagnostics.py
echo "Container diagnostics with host network"
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --network=host testcontainers-python python diagnostics.py
- name: Run checks
run: |
flake8
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ FROM python:${version}
WORKDIR /workspace
ARG version=3.8
COPY requirements/${version}.txt requirements.txt
COPY setup.py README.md ./
COPY setup.py README.rst ./
RUN pip install -r requirements.txt
COPY . .
7 changes: 7 additions & 0 deletions Dockerfile.diagnostics
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG version=3.8
FROM python:${version}

WORKDIR /workspace
COPY setup.py README.rst ./
RUN pip install -e .
COPY . .
23 changes: 23 additions & 0 deletions diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json
from testcontainers.core import utils
from testcontainers.core.container import DockerContainer


result = {
'is_linux': utils.is_linux(),
'is_mac': utils.is_mac(),
'is_windows': utils.is_windows(),
'inside_container': utils.inside_container(),
'default_gateway_ip': utils.default_gateway_ip(),
}

with DockerContainer('alpine:latest') as container:
client = container.get_docker_client()
result.update({
'container_host_ip': container.get_container_host_ip(),
'docker_client_gateway_ip': client.gateway_ip(container._container.id),
'docker_client_bridge_ip': client.bridge_ip(container._container.id),
'docker_client_host': client.host(),
})

print(json.dumps(result, indent=2))

0 comments on commit d48294c

Please sign in to comment.