Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
PLA 509 dump docker compose logs on failure (dagster-io#23167)
Browse files Browse the repository at this point in the history
## Summary & Motivation

when docker-compose up throws an exception, just dump docker logs to
stdout. sometimes there isn't anything more revealing here than what we
get in the initial exception, but sometimes it points to an issue with
the underlying service that wasn't in the original exception

## How I Tested These Changes

forced docker-compose to fail with a bad health check definition, and
ensured that the dump_logs function was invoked and did print to stdout

---------

Co-authored-by: Neil Fulwiler <[email protected]>
  • Loading branch information
neilfulwiler and Neil Fulwiler authored Jul 23, 2024
1 parent e556a5a commit 0b032e0
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ def docker_compose_cm(
if not network_name:
network_name = network_name_from_yml(docker_compose_yml)
try:
docker_compose_up(docker_compose_yml, docker_context, service, env_file, no_build=no_build)
try:
docker_compose_up(
docker_compose_yml, docker_context, service, env_file, no_build=no_build
)
except:
dump_docker_compose_logs(docker_context, docker_compose_yml)
raise

if BUILDKITE:
# When running in a container on Buildkite, we need to first connect our container
# and our network and then yield a dict of container name to the container's
Expand All @@ -36,6 +43,21 @@ def docker_compose_cm(
docker_compose_down(docker_compose_yml, docker_context, service, env_file)


def dump_docker_compose_logs(context, docker_compose_yml):
if context:
compose_command = ["docker", "--context", context, "compose"]
else:
compose_command = ["docker-compose"]

compose_command += [
"--file",
str(docker_compose_yml),
"logs",
]

subprocess.run(compose_command, check=False)


@pytest.fixture(scope="module", name="docker_compose_cm")
def docker_compose_cm_fixture(test_directory):
@contextmanager
Expand Down

0 comments on commit 0b032e0

Please sign in to comment.