Skip to content

Commit

Permalink
feat(deployment): Starting to handle fastapi and python usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Jan 11, 2025
1 parent b4bf68a commit f3aaad6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions backend/src/interfaces/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class GetAgentSecretResponse(BaseModel):
secret: str


# TODO: move the agent types in utils package once stable
class AgentPythonPackageManager(str, Enum):
poetry = "poetry"
pip = "pip"


class AgentUsageType(str, Enum):
fastapi = "fastapi"
python = "python"
6 changes: 4 additions & 2 deletions backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from src.interfaces.agent import (
Agent,
AgentPythonPackageManager,
AgentUsageType,
DeleteAgentBody,
GetAgentResponse,
GetAgentSecretMessage,
Expand Down Expand Up @@ -184,9 +185,10 @@ async def update(
agent_id: str,
secret: str = Form(),
deploy_script_url: str = Form(
default="https://raw.githubusercontent.com/Libertai/libertai-agents/refs/heads/reza/deployment-instances/deployment/deploy.sh"
default="https://raw.githubusercontent.com/Libertai/libertai-agents/refs/heads/reza/instances/deployment/deploy.sh"
),
python_version: str = Form(),
usage_type: AgentUsageType = Form(),
package_manager: AgentPythonPackageManager = Form(),
code: UploadFile = File(...),
) -> UpdateAgentResponse:
Expand Down Expand Up @@ -238,7 +240,7 @@ async def update(

# Execute the command
ssh_client.exec_command(
f"wget {deploy_script_url} -O /tmp/deploy-agent.sh -q --no-cache && chmod +x /tmp/deploy-agent.sh && /tmp/deploy-agent.sh {python_version} {package_manager.value}"
f"wget {deploy_script_url} -O /tmp/deploy-agent.sh -q --no-cache && chmod +x /tmp/deploy-agent.sh && /tmp/deploy-agent.sh {python_version} {package_manager.value} {usage_type.value}"
)

# Close the connection
Expand Down
12 changes: 11 additions & 1 deletion deployment/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ ZIP_PATH="/tmp/libertai-agent.zip"
CODE_PATH="/root/libertai-agent"
DOCKERFILE_PATH="/tmp/libertai-agent.Dockerfile"

case "$3" in
fastapi)
ENTRYPOINT="fastapi run src/main.py"
;;
python)
ENTRYPOINT="python -m src.main"
;;
esac

# Setup
apt update
apt install docker.io unzip -y
Expand All @@ -18,7 +27,8 @@ wget https://raw.githubusercontent.com/Libertai/libertai-agents/refs/heads/reza/
docker build $CODE_PATH \
-f $DOCKERFILE_PATH \
-t libertai-agent \
--build-arg PYTHON_VERSION=$1
--build-arg PYTHON_VERSION=$1 \
--build-arg ENTRYPOINT=$ENTRYPOINT
docker run --name libertai-agent -p 8000:8000 -d libertai-agent

# Cleanup
Expand Down
3 changes: 2 additions & 1 deletion deployment/pip.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARG PYTHON_VERSION=3.11
ARG ENTRYPOINT="fastapi run src/main.py"

FROM python:${PYTHON_VERSION}-slim

Expand All @@ -12,4 +13,4 @@ COPY . .

EXPOSE 8000

CMD ["fastapi", "run", "src/main.py"]
ENTRYPOINT ${ENTRYPOINT}
3 changes: 2 additions & 1 deletion deployment/poetry.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARG PYTHON_VERSION=3.11
ARG ENTRYPOINT="fastapi run src/main.py"

FROM python:${PYTHON_VERSION}-slim

Expand All @@ -14,4 +15,4 @@ COPY . .

EXPOSE 8000

CMD ["fastapi", "run", "src/main.py"]
ENTRYPOINT ${ENTRYPOINT}

0 comments on commit f3aaad6

Please sign in to comment.