Skip to content

Commit

Permalink
test that all containers have started successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasertl committed Jan 5, 2025
1 parent 7140a7f commit 2bb1b48
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion devscripts/validation/docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Functions for validating docker compose and the respective tutorial."""

import argparse
import json
import os
import re
import shutil
Expand Down Expand Up @@ -57,6 +58,20 @@ def _compose_up(remove_volumes: bool = True, **kwargs: Any) -> Iterator[None]:
utils.run(down, **down_kwargs)


def compose_status():
"""Assert that all containers have started successfully."""
proc = utils.run(["docker", "compose", "ps", "-a", "--format=json"], capture_output=True, text=True)
errors = 0
for line in proc.stdout.splitlines():
container_data = json.loads(line)
if (exit_code := container_data["ExitCode"]) != 0:
errors += err(f"{container_data['Service']}: Exit code {exit_code}")

if errors != 0:
raise RuntimeError(f"{errors} container(s) have not started successfully.")
ok("Containers seem to have started properly.")


def _compose_exec(*args: str, **kwargs: Any) -> "subprocess.CompletedProcess[Any]":
cmd = ["docker", "compose", "exec", *kwargs.pop("compose_args", []), *args]
return utils.run(cmd, **kwargs)
Expand Down Expand Up @@ -298,7 +313,7 @@ def test_tutorial(release: str) -> int: # pylint: disable=too-many-locals # no
(live_path / "fullchain.pem").symlink_to(os.path.relpath(archive_fullchain, live_path))

with tut.run("dhparam.yaml"), tut.run("docker-compose-up.yaml"), tut.run("verify-setup.yaml"):
ok("Containers seem to have started properly.")
compose_status()

# Validate that the container versions match the expected version
errors += _validate_container_versions(release)
Expand Down

0 comments on commit 2bb1b48

Please sign in to comment.