From 87afa718d5109b518dcce59de6f55578df94e09c Mon Sep 17 00:00:00 2001 From: znack Date: Thu, 24 Apr 2025 20:33:49 +0200 Subject: [PATCH] Add Docker for better DX from Znack's PR --- Dockerfile | 30 +++++++++ docker-compose.override.yml | 20 ++++++ docker-compose.yml | 120 ++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.override.yml create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0666e24 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM python:3.10-slim + +WORKDIR /app + +# Install system dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends gcc build-essential && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Copy requirements first for better caching +RUN pip install --no-cache-dir poetry + +# Install Python dependencies without creating a virtualenv +COPY pyproject.toml poetry.lock ./ +RUN poetry config virtualenvs.create false \ + && poetry install --without dev --no-interaction --no-ansi --no-root + +# Copy application code +COPY . . + +# Set Python to run in unbuffered mode (recommended for Docker) +ENV PYTHONUNBUFFERED=1 +ENV PYTHONPATH=/app + +# Expose the port the app will run on +EXPOSE 8000 + +# Default to running only the API server; worker and train-api are separate Compose services +CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..2a14573 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,20 @@ +services: + api: + volumes: + - ./:/app:cached + command: uvicorn api.main:app --host 0.0.0.0 --port 8000 --reload + + worker: + volumes: + - ./:/app:cached + command: python scripts/run_worker.py + + train-api: + volumes: + - ./:/app:cached + command: python thirdparty/train_api.py + + frontend: + volumes: + - ./frontend:/app:cached + command: sh -c "apk update && apk add --no-cache xdg-utils && npm install && npx vite --host 0.0.0.0 --port 5173" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e3b20eb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,120 @@ +services: + # Database service + postgresql: + image: postgres:14 + container_name: temporal-postgresql + environment: + POSTGRES_USER: temporal + POSTGRES_PASSWORD: temporal + POSTGRES_DB: temporal + volumes: + - postgresql:/var/lib/postgresql/data + networks: + - temporal-network + + # Temporal services + temporal: + image: temporalio/auto-setup:1.27.2 + container_name: temporal + ports: + - "7233:7233" + environment: + - DB=postgres12 + - DB_PORT=5432 + - POSTGRES_USER=temporal + - POSTGRES_PWD=temporal + - POSTGRES_SEEDS=postgresql + depends_on: + - postgresql + networks: + - temporal-network + + temporal-admin-tools: + image: temporalio/admin-tools:1.27 + container_name: temporal-admin-tools + depends_on: + - temporal + environment: + - TEMPORAL_CLI_ADDRESS=temporal:7233 + networks: + - temporal-network + + temporal-ui: + image: temporalio/ui:2.37.2 + container_name: temporal-ui + ports: + - "8080:8080" + environment: + - TEMPORAL_ADDRESS=temporal:7233 + - TEMPORAL_CORS_ORIGINS=http://localhost:8080 + depends_on: + - temporal + networks: + - temporal-network + + api: + build: + context: . + dockerfile: Dockerfile + container_name: temporal-ai-agent-api + ports: + - "8000:8000" + depends_on: + - temporal + networks: + - temporal-network + env_file: + - .env + environment: + - TEMPORAL_ADDRESS=temporal:7233 + + worker: + build: + context: . + dockerfile: Dockerfile + container_name: temporal-ai-agent-worker + depends_on: + - temporal + env_file: + - .env + environment: + - TEMPORAL_ADDRESS=temporal:7233 + command: python scripts/run_worker.py + networks: + - temporal-network + + train-api: + build: + context: . + dockerfile: Dockerfile + container_name: temporal-ai-agent-train-api + depends_on: + - temporal + env_file: + - .env + environment: + - TEMPORAL_ADDRESS=temporal:7233 + command: python thirdparty/train_api.py + networks: + - temporal-network + + frontend: + image: node:18-alpine + container_name: temporal-ai-agent-frontend + working_dir: /app + volumes: + - ./frontend:/app + command: sh -c "apk update && apk add --no-cache xdg-utils && npm install && npx vite --host 0.0.0.0" + ports: + - "5173:5173" + depends_on: + - api + networks: + - temporal-network + +networks: + temporal-network: + driver: bridge + +volumes: + postgresql: