Skip to content

Commit bac1082

Browse files
alexanderankinCarliJoy
authored andcommitted
test ci
1 parent 9bda90e commit bac1082

File tree

2 files changed

+86
-65
lines changed

2 files changed

+86
-65
lines changed

.github/workflows/ci-core.yml

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,42 @@ jobs:
2222
with:
2323
python-version: ${{ matrix.python-version }}
2424
- name: Install Python dependencies
25-
run: poetry install --all-extras
26-
- name: Run twine check
27-
run: rm -f LICENSE.txt && poetry build && poetry run twine check dist/*.tar.gz
28-
- name: Run tests
29-
run: make core/tests
30-
- name: Rename coverage file
31-
run: mv .coverage .coverage.${{ matrix.python-version}}
32-
- name: "Save coverage artifact"
33-
uses: actions/upload-artifact@v4
34-
with:
35-
name: "coverage-artifact-${{ matrix.python-version}}"
36-
include-hidden-files: true
37-
path: ".coverage.*"
38-
retention-days: 1
39-
- name: Run doctests
40-
run: make core/doctests
41-
42-
coverage-compile:
43-
needs: "run-tests-and-coverage"
44-
runs-on: ubuntu-22.04
45-
steps:
46-
- uses: actions/checkout@v4
47-
- name: Set up Python
48-
uses: ./.github/actions/setup-env
49-
- name: Install Python dependencies
50-
run: poetry install --all-extras
51-
- name: "Download coverage artifacts"
52-
uses: actions/download-artifact@v4
53-
with:
54-
pattern: "coverage-artifact-*"
55-
merge-multiple: true
56-
- name: Compile coverage
57-
run: make coverage
58-
- name: Upload coverage to Codecov
59-
uses: codecov/codecov-action@v4
60-
with:
61-
token: ${{ secrets.CODECOV_TOKEN }}
25+
run: poetry install --all-groups
26+
- name: debug dind
27+
run: DIND=1 poetry run pytest core/tests/test_docker_in_docker.py
28+
# - name: Run twine check
29+
# run: rm -f LICENSE.txt && poetry build && poetry run twine check dist/*.tar.gz
30+
# - name: Run tests
31+
# run: make core/tests
32+
# - name: Rename coverage file
33+
# run: mv .coverage .coverage.${{ matrix.python-version}}
34+
# - name: "Save coverage artifact"
35+
# uses: actions/upload-artifact@v4
36+
# with:
37+
# name: "coverage-artifact-${{ matrix.python-version}}"
38+
# include-hidden-files: true
39+
# path: ".coverage.*"
40+
# retention-days: 1
41+
# - name: Run doctests
42+
# run: make core/doctests
43+
#
44+
# coverage-compile:
45+
# needs: "run-tests-and-coverage"
46+
# runs-on: ubuntu-22.04
47+
# steps:
48+
# - uses: actions/checkout@v4
49+
# - name: Set up Python
50+
# uses: ./.github/actions/setup-env
51+
# - name: Install Python dependencies
52+
# run: poetry install --all-extras
53+
# - name: "Download coverage artifacts"
54+
# uses: actions/download-artifact@v4
55+
# with:
56+
# pattern: "coverage-artifact-*"
57+
# merge-multiple: true
58+
# - name: Compile coverage
59+
# run: make coverage
60+
# - name: Upload coverage to Codecov
61+
# uses: codecov/codecov-action@v4
62+
# with:
63+
# token: ${{ secrets.CODECOV_TOKEN }}

core/tests/test_docker_in_docker.py

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import contextlib
22
import json
3+
import logging
34
import os
45
import time
56
import socket
67
import sys
8+
from textwrap import indent
79
from pathlib import Path
810
from typing import Final, Any, Generator
911

@@ -21,9 +23,12 @@
2123
from testcontainers.core.waiting_utils import wait_for_logs
2224

2325
_DIND_PYTHON_VERSION = (3, 13)
26+
logger = logging.getLogger(__name__)
2427

2528

2629
def _should_skip_dind() -> bool:
30+
if os.getenv("DIND"):
31+
return False
2732
# todo refine macos check -> run in ci but not locally
2833
return is_mac() or tuple([*sys.version_info][:2]) != _DIND_PYTHON_VERSION
2934

@@ -50,6 +55,7 @@ def _wait_for_dind_return_ip(client: DockerClient, dind: Container):
5055
def test_wait_for_logs_docker_in_docker():
5156
# real dind isn't possible (AFAIK) in CI
5257
# forwarding the socket to a container port is at least somewhat the same
58+
logger.info("starting test_wait_for_logs_docker_in_docker")
5359
client = DockerClient()
5460
not_really_dind = client.run(
5561
image="alpine/socat",
@@ -58,21 +64,26 @@ def test_wait_for_logs_docker_in_docker():
5864
detach=True,
5965
)
6066

67+
logger.info("starting not_really_dind")
6168
not_really_dind.start()
69+
logger.info("started not_really_dind")
6270
docker_host_ip = _wait_for_dind_return_ip(client, not_really_dind)
71+
logger.info("waited for not_really_dind: '_wait_for_dind_return_ip'")
6372
docker_host = f"tcp://{docker_host_ip}:2375"
6473

65-
with DockerContainer(
66-
image="hello-world",
67-
docker_client_kw={"environment": {"DOCKER_HOST": docker_host, "DOCKER_CERT_PATH": "", "DOCKER_TLS_VERIFY": ""}},
68-
) as container:
69-
assert container.get_container_host_ip() == docker_host_ip
70-
wait_for_logs(container, "Hello from Docker!")
71-
stdout, stderr = container.get_logs()
72-
assert stdout, "There should be something on stdout"
73-
74-
not_really_dind.stop()
75-
not_really_dind.remove()
74+
try:
75+
with DockerContainer(
76+
image="hello-world",
77+
docker_client_kw={"environment": {"DOCKER_HOST": docker_host, "DOCKER_CERT_PATH": "", "DOCKER_TLS_VERIFY": ""}},
78+
) as container:
79+
logger.info("started hello-world container")
80+
assert container.get_container_host_ip() == docker_host_ip
81+
wait_for_logs(container, "Hello from Docker!")
82+
stdout, stderr = container.get_logs()
83+
assert stdout, "There should be something on stdout"
84+
finally:
85+
not_really_dind.stop()
86+
not_really_dind.remove()
7687

7788

7889
@pytest.mark.skipif(
@@ -122,19 +133,19 @@ def print_surround_header(what: str, header_len: int = 80) -> Generator[None, No
122133
start = f"# Beginning of {what}"
123134
end = f"# End of {what}"
124135

125-
print("\n")
126-
print("#" * header_len)
127-
print(start + " " * (header_len - len(start) - 1) + "#")
128-
print("#" * header_len)
129-
print("\n")
136+
logger.info("\n")
137+
logger.info("#" * header_len)
138+
logger.info(start + " " * (header_len - len(start) - 1) + "#")
139+
logger.info("#" * header_len)
140+
logger.info("\n")
130141

131142
yield
132143

133-
print("\n")
134-
print("#" * header_len)
135-
print(end + " " * (header_len - len(end) - 1) + "#")
136-
print("#" * header_len)
137-
print("\n")
144+
logger.info("\n")
145+
logger.info("#" * header_len)
146+
logger.info(end + " " * (header_len - len(end) - 1) + "#")
147+
logger.info("#" * header_len)
148+
logger.info("\n")
138149

139150

140151
EXPECTED_NETWORK_VAR: Final[str] = "TCC_EXPECTED_NETWORK"
@@ -165,10 +176,10 @@ def test_find_host_network_in_dood() -> None:
165176
"""
166177
Check that the correct host network is found for DooD
167178
"""
168-
LOGGER.info(f"Running container id={utils.get_running_in_container_id()}")
179+
logger.info(f"Running container id={utils.get_running_in_container_id()}")
169180
# Get some debug information in the hope this helps to find
170-
LOGGER.info(f"hostname: {socket.gethostname()}")
171-
LOGGER.info(f"docker info: {json.dumps(get_docker_info(), indent=2)}")
181+
logger.info(f"hostname: {socket.gethostname()}")
182+
logger.info(f"docker info: {json.dumps(get_docker_info(), indent=2)}")
172183
assert DockerClient().find_host_network() == os.environ[EXPECTED_NETWORK_VAR]
173184

174185

@@ -183,6 +194,7 @@ def test_dood(python_testcontainer_image: str) -> None:
183194

184195
docker_sock = tcc.ryuk_docker_socket
185196
with Network() as network:
197+
logger.info("test_dood - created network")
186198
with (
187199
DockerContainer(
188200
image=python_testcontainer_image,
@@ -196,7 +208,9 @@ def test_dood(python_testcontainer_image: str) -> None:
196208
.with_env("RYUK_RECONNECTION_TIMEOUT", "1s")
197209
.with_network(network)
198210
) as container:
211+
logger.info("test_dood - created container")
199212
status = container.get_wrapped_container().wait()
213+
logger.info("test_dood - container returned status %s", status)
200214
stdout, stderr = container.get_logs()
201215
# ensure ryuk removed the containers created inside container
202216
# because they are bound our network the deletion of the network
@@ -205,8 +219,8 @@ def test_dood(python_testcontainer_image: str) -> None:
205219

206220
# Show what was done inside test
207221
with print_surround_header("test_dood results"):
208-
print(stdout.decode("utf-8", errors="replace"))
209-
print(stderr.decode("utf-8", errors="replace"))
222+
logger.info(indent(stdout.decode("utf-8", errors="replace"), prefix=(" " * 4) + "container log: "))
223+
logger.info(indent(stderr.decode("utf-8", errors="replace"), prefix=(" " * 4) + "container log: "))
210224
assert status["StatusCode"] == 0
211225

212226

@@ -220,6 +234,7 @@ def test_dind(python_testcontainer_image: str, tmp_path: Path) -> None:
220234
cert_dir = tmp_path / "certs"
221235
dind_name = f"docker_{SESSION_ID}"
222236
with Network() as network:
237+
logger.info("test_dind - created network")
223238
with (
224239
DockerContainer(image="docker:dind", privileged=True)
225240
.with_name(dind_name)
@@ -229,7 +244,9 @@ def test_dind(python_testcontainer_image: str, tmp_path: Path) -> None:
229244
.with_network(network)
230245
.with_network_aliases("docker")
231246
) as dind_container:
247+
logger.info("test_dind - created docker:dind container")
232248
wait_for_logs(dind_container, "API listen on")
249+
logger.info("test_dind - waited for ready message in logs")
233250
client_dir = cert_dir / "docker" / "client"
234251
ca_file = client_dir / "ca.pem"
235252
assert ca_file.is_file()
@@ -247,7 +264,9 @@ def test_dind(python_testcontainer_image: str, tmp_path: Path) -> None:
247264
.with_env("DOCKER_HOST", "tcp://docker:2376")
248265
.with_network(network)
249266
) as test_container:
267+
logger.info("test_dind - created test suite container")
250268
status = test_container.get_wrapped_container().wait()
269+
logger.info("test_dind - test suite container returned status %s", status)
251270
stdout, stderr = test_container.get_logs()
252271
finally:
253272
# ensure the certs are deleted from inside the container
@@ -258,6 +277,6 @@ def test_dind(python_testcontainer_image: str, tmp_path: Path) -> None:
258277

259278
# Show what was done inside test
260279
with print_surround_header("test_dood results"):
261-
print(stdout.decode("utf-8", errors="replace"))
262-
print(stderr.decode("utf-8", errors="replace"))
280+
logger.info(indent(stdout.decode("utf-8", errors="replace"), prefix=(" " * 4) + "container log: "))
281+
logger.info(indent(stderr.decode("utf-8", errors="replace"), prefix=(" " * 4) + "container log: "))
263282
assert status["StatusCode"] == 0

0 commit comments

Comments
 (0)