Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add Docker, Docker Compose, System Requirements, and CI/CD Pipeline for Container Publishing #11

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
49 changes: 49 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Docker

on:
push:
branches: [ "main" ]
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.9-slim

WORKDIR /app

RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sSL https://install.python-poetry.org | python3 -

ENV PATH="${PATH}:/root/.local/bin"

COPY pyproject.toml README.md ./
COPY src/ ./src/

RUN poetry config virtualenvs.create false

RUN poetry install --no-dev

COPY .env* ./

ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1

# Default to showing help for agents.py
CMD ["python", "src/agents.py", "--help"]
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ git clone https://github.com/virattt/ai-hedge-fund.git
cd ai-hedge-fund
```

### System Requirements
- CPU: Any modern CPU (last 5 years)
- RAM: 2GB minimum, 4GB recommended
- Storage: 1GB free space
- Internet: Stable connection required
- No GPU required

The system is lightweight as it primarily manages workflows between APIs (OpenAI and financial data) without running any local AI models.

### Option 1: Local Setup

1. Install Poetry (if not already installed):
```bash
curl -sSL https://install.python-poetry.org | python3 -
Expand All @@ -63,6 +74,28 @@ export OPENAI_API_KEY='your-api-key-here' # Get a key from https://platform.open
export FINANCIAL_DATASETS_API_KEY='your-api-key-here' # Get a key from https://financialdatasets.ai/
```

### Option 2: Docker Setup

You can either build the image locally or use our official image from GitHub Container Registry:

#### Using the Official Image

1. Create and configure your `.env` file as explained above.

2. Pull and run the official image using docker compose:
```bash
# Run the trading agent
docker compose run agent --ticker AAPL

# Run the backtester
docker compose run backtester --ticker AAPL

# Run with custom parameters
docker compose run agent --ticker AAPL --start-date 2024-01-01 --end-date 2024-03-01 --show-reasoning
```

The Docker setup uses a lightweight Python 3.9 base image and installs only the required dependencies.

## Usage

### Running the Hedge Fund
Expand Down Expand Up @@ -108,7 +141,7 @@ You can optionally specify the start and end dates to backtest over a specific t
poetry run python src/backtester.py --ticker AAPL --start-date 2024-01-01 --end-date 2024-03-01
```

## Project Structure
## Project Structure
```
ai-hedge-fund/
├── src/
Expand Down Expand Up @@ -139,3 +172,4 @@ ai-hedge-fund/
## License

This project is licensed under the MIT License - see the LICENSE file for details.

26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.8'

services:
agent:
image: ghcr.io/virattt/ai-hedge-fund:main
charlesvien marked this conversation as resolved.
Show resolved Hide resolved
env_file: .env
volumes:
- .:/app
entrypoint: python src/main.py
command: --ticker AAPL
networks:
- ai-hedge-fund

backtester:
image: ghcr.io/virattt/ai-hedge-fund:main
env_file: .env
volumes:
- .:/app
entrypoint: python src/backtester.py
command: --ticker AAPL
networks:
- ai-hedge-fund

networks:
ai-hedge-fund:
driver: bridge