From e02c08159400755c6d64f73f850d70da25b1f4af Mon Sep 17 00:00:00 2001 From: Adil Hafeez Date: Mon, 25 Nov 2024 19:20:30 -0800 Subject: [PATCH] fix more --- arch/tools/cli/core.py | 75 +++++++++++++++++++-------------------- arch/tools/poetry.lock | 16 ++++++++- arch/tools/pyproject.toml | 1 + 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/arch/tools/cli/core.py b/arch/tools/cli/core.py index 17375cca..f76bb171 100644 --- a/arch/tools/cli/core.py +++ b/arch/tools/cli/core.py @@ -1,12 +1,9 @@ import subprocess import os import time -import pkg_resources -import select import sys import glob import docker -from cli.utils import run_docker_compose_ps, print_service_status, check_services_state from cli.utils import getLogger from cli.consts import ( ARCHGW_DOCKER_IMAGE, @@ -16,18 +13,50 @@ from cli.consts import ( ACCESS_LOG_FILES, ) from huggingface_hub import snapshot_download +from dotenv import dotenv_values + log = getLogger(__name__) +dot_env = dotenv_values(".env") +dot_env["OTEL_TRACING_HTTP_ENDPOINT"] = "http://host.docker.internal:4318/v1/traces" + + +def start_archgw_docker(client, arch_config_file): + return client.containers.run( + name=ARCHGW_DOCKER_NAME, + image=ARCHGW_DOCKER_IMAGE, + detach=True, # Run in detached mode + ports={ + "10000/tcp": 10000, + "10001/tcp": 10001, + "11000/tcp": 11000, + "12000/tcp": 12000, + "19901/tcp": 19901, + }, + volumes={ + f"{arch_config_file}": { + "bind": "/app/arch_config.yaml", + "mode": "ro", + }, + "/etc/ssl/cert.pem": {"bind": "/etc/ssl/cert.pem", "mode": "ro"}, + "archgw_logs": {"bind": "/var/log"}, + }, + environment=dot_env, + extra_hosts={"host.docker.internal": "host-gateway"}, + healthcheck={ + "test": ["CMD", "curl", "-f", "http://localhost:10000/healthz"], + "interval": 5000000000, # 5 seconds + "timeout": 1000000000, # 1 seconds + "retries": 3, + }, + ) + def stream_gateway_logs(follow): """ Stream logs from the arch gateway service. """ - compose_file = pkg_resources.resource_filename( - __name__, "../config/docker-compose.yaml" - ) - log.info("Logs from arch gateway service.") options = ["docker", "logs", "archgw"] @@ -37,7 +66,6 @@ def stream_gateway_logs(follow): # Run `docker-compose logs` to stream logs from the gateway service subprocess.run( options, - cwd=os.path.dirname(compose_file), check=True, stdout=sys.stdout, stderr=sys.stderr, @@ -99,36 +127,7 @@ def start_arch(arch_config_file, env, log_timeout=120): try: client = docker.from_env() - container = client.containers.run( - name=ARCHGW_DOCKER_NAME, - image=ARCHGW_DOCKER_IMAGE, - detach=True, # Run in detached mode - ports={ - "10000/tcp": 10000, - "10001/tcp": 10001, - "11000/tcp": 11000, - "12000/tcp": 12000, - "19901/tcp": 19901, - }, - volumes={ - f"{arch_config_file}": { - "bind": "/app/arch_config.yaml", - "mode": "ro", - }, - "/etc/ssl/cert.pem": {"bind": "/etc/ssl/cert.pem", "mode": "ro"}, - "archgw_logs": {"bind": "/var/log"}, - }, - environment={ - "OTEL_TRACING_HTTP_ENDPOINT": "http://host.docker.internal:4318/v1/traces" - }, - extra_hosts={"host.docker.internal": "host-gateway"}, - healthcheck={ - "test": ["CMD", "curl", "-f", "http://localhost:10000/healthz"], - "interval": 5000000000, # 5 seconds - "timeout": 1000000000, # 1 seconds - "retries": 3, - }, - ) + container = start_archgw_docker(client, arch_config_file) start_time = time.time() diff --git a/arch/tools/poetry.lock b/arch/tools/poetry.lock index e46249fd..d23783f2 100644 --- a/arch/tools/poetry.lock +++ b/arch/tools/poetry.lock @@ -583,6 +583,20 @@ files = [ [package.dependencies] typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" +[[package]] +name = "python-dotenv" +version = "1.0.1" +description = "Read key-value pairs from a .env file and set them as environment variables" +optional = false +python-versions = ">=3.8" +files = [ + {file = "python-dotenv-1.0.1.tar.gz", hash = "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca"}, + {file = "python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a"}, +] + +[package.extras] +cli = ["click (>=5.0)"] + [[package]] name = "pywin32" version = "308" @@ -879,4 +893,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = ">=3.12" -content-hash = "7d2a1db6c7041a0f41f4cba52ddb7678167c71f4f0787be2eb69edb78b96130d" +content-hash = "c479433cfd43db3edc566b9a2a9a378617398b9cff8c83f245c6cf05129e5694" diff --git a/arch/tools/pyproject.toml b/arch/tools/pyproject.toml index 5c8029d4..eebee3a1 100644 --- a/arch/tools/pyproject.toml +++ b/arch/tools/pyproject.toml @@ -19,6 +19,7 @@ jsonschema = "^4.23.0" setuptools = "75.5.0" huggingface_hub = "^0.26.0" docker = "^7.1.0" +python-dotenv = "^1.0.1" [tool.poetry.scripts] archgw = "cli.main:main"