Skip to content

Commit d48294c

Browse files
committed
Add diagnostics for tests.
1 parent fcbad41 commit d48294c

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ jobs:
3737
python -m pip install --upgrade pip
3838
pip install wheel
3939
pip install -r requirements/${{ matrix.python-version }}.txt
40+
- name: Run docker diagnostics
41+
run: |
42+
echo "Build minimal container for docker-in-docker diagnostics"
43+
docker build -f Dockerfile.diagnostics -t testcontainers-python .
44+
echo "Bare metal diagnostics"
45+
python diagnostics.py
46+
echo "Container diagnostics with bridge network"
47+
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --network=bridge testcontainers-python python diagnostics.py
48+
echo "Container diagnostics with host network"
49+
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --network=host testcontainers-python python diagnostics.py
4050
- name: Run checks
4151
run: |
4252
flake8

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ FROM python:${version}
44
WORKDIR /workspace
55
ARG version=3.8
66
COPY requirements/${version}.txt requirements.txt
7-
COPY setup.py README.md ./
7+
COPY setup.py README.rst ./
88
RUN pip install -r requirements.txt
99
COPY . .

Dockerfile.diagnostics

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG version=3.8
2+
FROM python:${version}
3+
4+
WORKDIR /workspace
5+
COPY setup.py README.rst ./
6+
RUN pip install -e .
7+
COPY . .

diagnostics.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
from testcontainers.core import utils
3+
from testcontainers.core.container import DockerContainer
4+
5+
6+
result = {
7+
'is_linux': utils.is_linux(),
8+
'is_mac': utils.is_mac(),
9+
'is_windows': utils.is_windows(),
10+
'inside_container': utils.inside_container(),
11+
'default_gateway_ip': utils.default_gateway_ip(),
12+
}
13+
14+
with DockerContainer('alpine:latest') as container:
15+
client = container.get_docker_client()
16+
result.update({
17+
'container_host_ip': container.get_container_host_ip(),
18+
'docker_client_gateway_ip': client.gateway_ip(container._container.id),
19+
'docker_client_bridge_ip': client.bridge_ip(container._container.id),
20+
'docker_client_host': client.host(),
21+
})
22+
23+
print(json.dumps(result, indent=2))

0 commit comments

Comments
 (0)