From 521c33a6b11d646a91b8b4afdddb764be26a54e2 Mon Sep 17 00:00:00 2001 From: Mery-Sanz Date: Tue, 20 May 2025 16:05:20 +0200 Subject: [PATCH] cker virtualization for ctf_inside false --- .devcontainer/qdrant_storage/raft_state.json | 2 +- src/cai/util.py | 37 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.devcontainer/qdrant_storage/raft_state.json b/.devcontainer/qdrant_storage/raft_state.json index b7bcb749..23b070d6 100644 --- a/.devcontainer/qdrant_storage/raft_state.json +++ b/.devcontainer/qdrant_storage/raft_state.json @@ -1 +1 @@ -{"state":{"hard_state":{"term":0,"vote":0,"commit":0},"conf_state":{"voters":[6120741261401965],"learners":[],"voters_outgoing":[],"learners_next":[],"auto_leave":false}},"latest_snapshot_meta":{"term":0,"index":0},"apply_progress_queue":null,"first_voter":6120741261401965,"peer_address_by_id":{},"peer_metadata_by_id":{},"this_peer_id":6120741261401965} \ No newline at end of file +{"state":{"hard_state":{"term":0,"vote":0,"commit":0},"conf_state":{"voters":[6120741261401965],"learners":[],"voters_outgoing":[],"learners_next":[],"auto_leave":false}},"latest_snapshot_meta":{"term":0,"index":0},"apply_progress_queue":null,"first_voter":6120741261401965,"peer_address_by_id":{},"peer_metadata_by_id":{},"this_peer_id":6120741261401965} diff --git a/src/cai/util.py b/src/cai/util.py index b7223fad..ff62608b 100644 --- a/src/cai/util.py +++ b/src/cai/util.py @@ -2997,3 +2997,40 @@ def setup_ctf(): bg="blue")) return ctf, messages + + +def build_docker_container(devcontainer_path: str) -> str: + dockerfile_path = os.path.join(devcontainer_path, "Dockerfile") + image_name = "cai-container3" + container_name = "cai-container3" + + # Try to remove existing container with the same name + try: + subprocess.run(["docker", "rm", "-f", container_name], check=True) + except subprocess.CalledProcessError: + pass # If it doesn't exist, continue normally + + # Build the image + subprocess.run([ + "docker", "build", + "-t", image_name, + "-f", dockerfile_path, + devcontainer_path + ], check=True) + + # Run the container + result = subprocess.run([ + "docker", "run", "-d", "--name", container_name, image_name, "tail", "-f", "/dev/null" + ], stdout=subprocess.PIPE, check=True, text=True) + + container_id = result.stdout.strip() + return container_id + +def remove_container(name_or_id: str): + try: + # Force removal (stops if running, then removes) + subprocess.run(["docker", "rm", "-f", name_or_id], check=True) + print(f"Container '{name_or_id}' removed successfully.") + except subprocess.CalledProcessError as e: + print(f"Error removing container {name_or_id}:", e) +