Skip to content

Commit

Permalink
feat(agent): Working instance deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Dec 12, 2024
1 parent fdcc728 commit 2993581
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 62 deletions.
62 changes: 9 additions & 53 deletions libertai_client/commands/agent.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import json
import os
import zipfile
from enum import Enum
from typing import Annotated

import aiohttp
import pathspec
import rich
import typer
from dotenv import dotenv_values
from libertai_utils.interfaces.agent import UpdateAgentResponse
from rich.console import Console

from libertai_client.config import config
Expand Down Expand Up @@ -94,59 +97,12 @@ async def deploy(
data=data,
) as response:
if response.status == 200:
print("Request succeeded:", await response.text())
response_data = UpdateAgentResponse(**json.loads(await response.text())) # noqa: F821
rich.print(
f"[green]Agent successfully deployed on http://[{response_data.instance_ip}]:8000/docs"
)
else:
print(f"Request failed: {response.status}")
print(await response.text())
error_message = await response.text()
err_console.print(f"[red]Request failed\n{error_message}")

os.remove(agent_zip_path)

# with Progress(TextColumn(TEXT_PROGRESS_FORMAT),
# SpinnerColumn(finished_text="✔ ")) as progress:
# setup_task_text = "Starting Docker container"
# task = progress.add_task(f"{setup_task_text}", start=True, total=1)
# docker_client = client.from_env()
# container: Container = docker_client.containers.run("debian:bookworm", platform="linux/amd64", tty=True,
# detach=True, volumes={
# requirements_path: {'bind': '/opt/requirements.txt', 'mode': 'ro'},
# code_path: {'bind': '/opt/code', 'mode': 'ro'}
# })
# progress.update(task, description=f"[green]{setup_task_text}", advance=1)
#
# agent_result: str | None = None
# error_message: str | None = None
#
# with Progress(TaskOfTotalColumn(len(commands)), TextColumn(TEXT_PROGRESS_FORMAT),
# SpinnerColumn(finished_text="✔ "),
# TimeElapsedColumn()) as progress:
# for command in commands:
# task = progress.add_task(f"{command.title}", start=True, total=1)
# result = container.exec_run(f'/bin/bash -c "{command.content}"')
#
# if result.exit_code != 0:
# command_output = result.output.decode().strip('\n')
# error_message = f"\n[red]Docker command error: '{command_output}'"
# break
#
# if command.id == "call-backend":
# agent_result = result.output.decode()
# progress.update(task, description=f"[green]{command.title}", advance=1)
# progress.stop_task(task)
#
# if error_message is not None:
# err_console.print(error_message)
#
# # Cleanup
# with Progress(TextColumn(TEXT_PROGRESS_FORMAT),
# SpinnerColumn(finished_text="✔ ")) as progress:
# stop_task_text = "Stopping and removing container"
# task = progress.add_task(f"{stop_task_text}", start=True, total=1)
# container.stop()
# container.remove()
# progress.update(task, description=f"[green]{stop_task_text}", advance=1)
#
# if agent_result is not None:
# agent_data = UpdateAgentResponse(**json.loads(agent_result))
# print(f"Agent successfully deployed on {get_vm_url(agent_data.vm_hash)}")
# else:
# typer.Exit(1)
4 changes: 0 additions & 4 deletions libertai_client/interfaces/agent.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from pydantic import BaseModel


class UpdateAgentResponse(BaseModel):
vm_hash: str


class AgentConfig(BaseModel):
id: str
secret: str
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ python = "^3.11"
typer = "^0.12.5"
pydantic = ">=1.10.5,<2.0.0"
python-dotenv = "^1.0.1"
libertai-utils = "0.0.8"
libertai-utils = "0.0.9"
pathspec = "^0.12.1"

[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 2993581

Please sign in to comment.