2023-05-26 04:10:56 +05:30
|
|
|
import logging
|
2023-10-31 21:28:38 -07:00
|
|
|
import os
|
2021-04-13 17:30:24 -07:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-08-21 21:43:36 +05:30
|
|
|
from datahub.testing.docker_utils import ( # noqa: F401
|
|
|
|
docker_compose_runner,
|
|
|
|
is_responsive,
|
|
|
|
wait_for_port,
|
|
|
|
)
|
2021-04-13 17:30:24 -07:00
|
|
|
|
2024-08-21 21:43:36 +05:30
|
|
|
logger = logging.getLogger(__name__)
|
2021-04-13 17:30:24 -07:00
|
|
|
|
|
|
|
|
2022-12-27 17:06:16 -05:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def docker_compose_command():
|
|
|
|
"""Docker Compose command to use, it could be either `docker-compose`
|
|
|
|
for Docker Compose v1 or `docker compose` for Docker Compose
|
|
|
|
v2."""
|
|
|
|
|
|
|
|
return "docker compose"
|
|
|
|
|
|
|
|
|
2023-10-03 23:17:49 -04:00
|
|
|
def cleanup_image(image_name: str) -> None:
|
|
|
|
assert ":" not in image_name, "image_name should not contain a tag"
|
|
|
|
|
2023-10-31 21:28:38 -07:00
|
|
|
if not os.environ.get("CI"):
|
|
|
|
logger.debug("Not cleaning up images to speed up local development")
|
|
|
|
return
|
|
|
|
|
2023-10-03 23:17:49 -04:00
|
|
|
images_proc = subprocess.run(
|
|
|
|
f"docker image ls --filter 'reference={image_name}*' -q",
|
|
|
|
shell=True,
|
|
|
|
capture_output=True,
|
|
|
|
text=True,
|
|
|
|
check=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
if not images_proc.stdout:
|
|
|
|
logger.debug(f"No images to cleanup for {image_name}")
|
|
|
|
return
|
|
|
|
|
|
|
|
image_ids = images_proc.stdout.splitlines()
|
|
|
|
subprocess.run(
|
|
|
|
f"docker image rm {' '.join(image_ids)}",
|
|
|
|
shell=True,
|
|
|
|
check=True,
|
|
|
|
)
|