Changeset View
Changeset View
Standalone View
Standalone View
python_modules/dagster-test/dagster_test/fixtures/docker_compose.py
# pylint: disable=redefined-outer-name | # pylint: disable=redefined-outer-name | ||||
import json | import json | ||||
import os | import os | ||||
import subprocess | import subprocess | ||||
from contextlib import contextmanager | from contextlib import contextmanager | ||||
import pytest | import pytest | ||||
from .utils import BUILDKITE | from .utils import BUILDKITE | ||||
@pytest.fixture | @pytest.fixture(scope="module") | ||||
jordansanders: Can you include a test that shows how this is used? | |||||
def docker_compose_cm(test_directory): | def docker_compose_cm(test_directory): | ||||
@contextmanager | @contextmanager | ||||
def docker_compose( | def docker_compose( | ||||
docker_compose_yml=None, | docker_compose_yml=None, | ||||
network_name=None, | network_name=None, | ||||
docker_context=None, | docker_context=None, | ||||
): | ): | ||||
if not docker_compose_yml: | if not docker_compose_yml: | ||||
Show All 13 Lines | ): | ||||
# just yield a dict of container name to "localhost". | # just yield a dict of container name to "localhost". | ||||
yield dict((container, "localhost") for container in list_containers()) | yield dict((container, "localhost") for container in list_containers()) | ||||
finally: | finally: | ||||
docker_compose_down(docker_compose_yml, docker_context) | docker_compose_down(docker_compose_yml, docker_context) | ||||
return docker_compose | return docker_compose | ||||
@pytest.fixture | @pytest.fixture(scope="module") | ||||
def docker_compose(docker_compose_cm): | def docker_compose(docker_compose_cm): | ||||
with docker_compose_cm() as docker_compose: | with docker_compose_cm() as hostnames: | ||||
yield docker_compose | yield hostnames | ||||
def docker_compose_up(docker_compose_yml, context): | def docker_compose_up(docker_compose_yml, context): | ||||
if context: | if context: | ||||
compose_command = ["docker", "--context", context, "compose"] | compose_command = ["docker", "--context", context, "compose"] | ||||
else: | else: | ||||
compose_command = ["docker-compose"] | compose_command = ["docker-compose"] | ||||
subprocess.check_call( | subprocess.check_call( | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |
Can you include a test that shows how this is used?