Skip to content

Commit

Permalink
fixing containers
Browse files Browse the repository at this point in the history
  • Loading branch information
vinicvaz committed Oct 16, 2023
1 parent dd56e8a commit ed72fd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/domino/testing/dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def piece_dry_run(
logger = get_configured_logger("piece_dry_run")

pieces_images_map = os.environ.get("PIECES_IMAGES_MAP", {})
http_server = None
if pieces_images_map and piece_name in pieces_images_map:
try:
from domino.testing.http_client import TestingHttpClient
Expand All @@ -51,8 +52,9 @@ def piece_dry_run(
return dry_run_response.json()
except Exception as e:
logger.error(f"Error running dry run with http client: {e}")
http_server.stop()
http_server.remove()
if http_server:
http_server.stop()
http_server.remove()
raise e

if not repository_folder_path:
Expand Down
7 changes: 4 additions & 3 deletions src/domino/testing/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import time
import docker
from domino.logger import get_configured_logger
from domino.testing import http_server
from pathlib import Path


class TestingHttpClient:

docker_client = docker.from_env()
DOMINO_TESTING_CONTAINER_NAME = 'domino_testing_http_server'
DOMINO_INTERNAL_REPOSITORY_FOLDER_PATH = "/home/domino/pieces_repository/"
BASE_HTTP_SERVER_HOST_URL = "http://0.0.0.0:8080"
logger = get_configured_logger("TestingHttpClient")

@classmethod
def wait_health_check(cls):
max_retries = 10
max_retries = 30
retry_delay_in_seconds = 1
url = f'{cls.BASE_HTTP_SERVER_HOST_URL}/health-check'
for _ in range(max_retries):
Expand All @@ -38,6 +38,7 @@ def start_http_server(cls, image: str):
image=image,
command=["bash", "-c", "python -c 'from domino.testing import http_server; http_server.run_server()'"],
ports={'8080/tcp': ('0.0.0.0', 8080)},
name=cls.DOMINO_TESTING_CONTAINER_NAME,
detach=True,
)
container_state = container.attrs.get('State').get('Running')
Expand All @@ -51,7 +52,7 @@ def start_http_server(cls, image: str):
cls.wait_health_check()
return container
except Exception as e:
container = cls.docker_client.containers.get('domino_testing_http_server')
container = cls.docker_client.containers.get(cls.DOMINO_TESTING_CONTAINER_NAME)
if container:
container.stop()
container.remove()
Expand Down

0 comments on commit ed72fd5

Please sign in to comment.