Compare commits

...

5 Commits

Author SHA1 Message Date
4666e09385 fix: prevent restart loop on missing API keys
Add validation at startup to check required environment variables:
- OPENAI_API_KEY
- ALPHAADVANTAGE_API_KEY
- JINA_API_KEY

If any are missing, display clear error message with setup
instructions and exit immediately (no restart loop).

Change restart policy from 'unless-stopped' to 'on-failure:3'
to limit restart attempts and prevent endless loops on
configuration errors.
2025-10-30 21:00:12 -04:00
0c58baed42 fix: separate data scripts from volume mount directory
Move get_daily_price.py and merge_jsonl.py to /app/scripts
to prevent volume mount from overlaying the scripts.
Scripts run from /app/data context to output correctly.

Fixes container startup error where scripts were not found
after ./data volume mount replaced container's /app/data.
2025-10-30 20:53:44 -04:00
2d1c356199 feat: add configurable web interface host port
Add WEB_HTTP_PORT environment variable to configure
the host port for the web interface (port 8888).
Container still uses 8888 internally, but host port
can be customized via .env file.
2025-10-30 20:51:21 -04:00
ffa158224d fix: use fixed internal ports with configurable host ports
Internal container ports are now fixed at 8000-8003.
Host ports are configurable via .env variables.
This prevents port conflicts inside the container while
allowing users to map to different host ports if needed.
2025-10-30 20:50:37 -04:00
6825a60b20 feat: use pre-built image by default in docker-compose
Pull ghcr.io/xe138/ai-trader:latest by default instead of building.
Add commented build option for local development.
Makes deployment faster for end users.
2025-10-30 20:47:11 -04:00
4 changed files with 65 additions and 15 deletions

View File

@@ -15,11 +15,17 @@ JINA_API_KEY=your_jina_key_here
# System Configuration (Docker default paths)
RUNTIME_ENV_PATH=/app/data/runtime_env.json
# MCP Service Ports (defaults shown)
# MCP Service Host Ports (exposed on host machine)
# Container always uses 8000-8003 internally
# Change these if you need different ports on your host
MATH_HTTP_PORT=8000
SEARCH_HTTP_PORT=8001
TRADE_HTTP_PORT=8002
GETPRICE_HTTP_PORT=8003
# Web Interface Host Port (exposed on host machine)
# Container always uses 8888 internally
WEB_HTTP_PORT=8888
# Agent Configuration
AGENT_MAX_STEP=30

View File

@@ -15,6 +15,12 @@ WORKDIR /app
# Copy application code
COPY . .
# Copy data scripts to separate directory (volume mount won't overlay these)
RUN mkdir -p /app/scripts && \
cp data/get_daily_price.py /app/scripts/ && \
cp data/get_interdaily_price.py /app/scripts/ && \
cp data/merge_jsonl.py /app/scripts/
# Create necessary directories
RUN mkdir -p data logs data/agent_data

View File

@@ -1,6 +1,8 @@
services:
ai-trader:
build: .
image: ghcr.io/xe138/ai-trader:latest
# Uncomment to build locally instead of pulling:
# build: .
container_name: ai-trader-app
volumes:
- ./data:/app/data
@@ -17,18 +19,19 @@ services:
# System Configuration
- RUNTIME_ENV_PATH=/app/data/runtime_env.json
# MCP Service Ports
- MATH_HTTP_PORT=${MATH_HTTP_PORT:-8000}
- SEARCH_HTTP_PORT=${SEARCH_HTTP_PORT:-8001}
- TRADE_HTTP_PORT=${TRADE_HTTP_PORT:-8002}
- GETPRICE_HTTP_PORT=${GETPRICE_HTTP_PORT:-8003}
# MCP Service Ports (fixed internally)
- MATH_HTTP_PORT=8000
- SEARCH_HTTP_PORT=8001
- TRADE_HTTP_PORT=8002
- GETPRICE_HTTP_PORT=8003
# Agent Configuration
- AGENT_MAX_STEP=${AGENT_MAX_STEP:-30}
ports:
- "8000:8000"
- "8001:8001"
- "8002:8002"
- "8003:8003"
- "8888:8888"
restart: unless-stopped
# Format: "HOST:CONTAINER" - container ports are fixed, host ports configurable via .env
- "${MATH_HTTP_PORT:-8000}:8000"
- "${SEARCH_HTTP_PORT:-8001}:8001"
- "${TRADE_HTTP_PORT:-8002}:8002"
- "${GETPRICE_HTTP_PORT:-8003}:8003"
- "${WEB_HTTP_PORT:-8888}:8888"
restart: on-failure:3 # Restart max 3 times on failure, prevents endless loops

View File

@@ -3,11 +3,46 @@ set -e # Exit on any error
echo "🚀 Starting AI-Trader..."
# Validate required environment variables
echo "🔍 Validating environment variables..."
MISSING_VARS=()
if [ -z "$OPENAI_API_KEY" ]; then
MISSING_VARS+=("OPENAI_API_KEY")
fi
if [ -z "$ALPHAADVANTAGE_API_KEY" ]; then
MISSING_VARS+=("ALPHAADVANTAGE_API_KEY")
fi
if [ -z "$JINA_API_KEY" ]; then
MISSING_VARS+=("JINA_API_KEY")
fi
if [ ${#MISSING_VARS[@]} -gt 0 ]; then
echo ""
echo "❌ ERROR: Missing required environment variables:"
for var in "${MISSING_VARS[@]}"; do
echo " - $var"
done
echo ""
echo "Please set these variables in your .env file:"
echo " 1. Copy .env.example to .env"
echo " 2. Edit .env and add your API keys"
echo " 3. Restart the container"
echo ""
echo "See docs/DOCKER.md for more information."
exit 1
fi
echo "✅ Environment variables validated"
# Step 1: Data preparation
echo "📊 Fetching and merging price data..."
# Run scripts from /app/scripts but output to /app/data
cd /app/data
python get_daily_price.py
python merge_jsonl.py
python /app/scripts/get_daily_price.py
python /app/scripts/merge_jsonl.py
cd /app
# Step 2: Start MCP services in background