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

Dockerized version #152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use Python 3.10 slim image as base
FROM python:3.10-slim
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May change it to python 3.13. Python 3.10 will be end of life next year.


# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
python3-dev \
curl \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed when you use "pip install poetry"

&& rm -rf /var/lib/apt/lists/*

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "pip install poetry" to get rid of curl

ENV PATH="/root/.local/bin:$PATH"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can combine this with line 30 to remove this docker layer:

ENV PYTHONUNBUFFERED=1
PATH="/root/.local/bin:$PATH"


# Copy requirements first to leverage Docker cache
# Copy source code
COPY src/ src/
COPY .env .
COPY .gitignore .
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed

COPY README.md .
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed

COPY LICENSE .
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed

COPY pyproject.toml .

# Install Python dependencies
RUN poetry install

# Set environment variable for Python to run in unbuffered mode
ENV PYTHONUNBUFFERED=1

# Set default command with -u flag for unbuffered output
ENTRYPOINT ["poetry", "run", "python", "-u", "src/main.py"]
CMD ["--ticker", "AAPL,MSFT,NVDA"] # Optional default arguments
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new line at end of file.

12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ You can optionally specify the start and end dates to backtest over a specific t
poetry run python src/backtester.py --ticker AAPL,MSFT,NVDA --start-date 2024-01-01 --end-date 2024-03-01
```

## Using Docker

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the info to create a .env file first.

To build the docker container:
```bash
docker build .
```

To run the docker container:
```bash
docker run -it <container_name> --ticker AAPL,MSFT,NVDA
```

## Project Structure
```
ai-hedge-fund/
Expand Down