File size: 2,243 Bytes
10fcca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# CareFlow Nexus AI Agents - Hugging Face Deployment
FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    gcc \
    g++ \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy all application code
COPY . .

# Create necessary directories
RUN mkdir -p /app/config /app/logs

# Create a startup script that handles secrets
RUN echo '#!/bin/bash\n\
set -e\n\
\n\
echo "=== CareFlow Nexus Agent Server - Hugging Face Deployment ==="\n\
\n\
# Write Firebase service account from secret to file\n\
if [ -n "$FIREBASE_SERVICE_ACCOUNT_JSON" ]; then\n\
  echo "✓ Writing Firebase service account to file..."\n\
  echo "$FIREBASE_SERVICE_ACCOUNT_JSON" > /app/config/serviceAccountKey.json\n\
  export FIREBASE_SERVICE_ACCOUNT_PATH="/app/config/serviceAccountKey.json"\n\
else\n\
  echo "⚠ Warning: FIREBASE_SERVICE_ACCOUNT_JSON not set"\n\
fi\n\
\n\
# Set default values for optional env vars\n\
export GEMINI_MODEL="${GEMINI_MODEL:-gemini-2.0-flash-exp}"\n\
export RULE_WEIGHT="${RULE_WEIGHT:-0.5}"\n\
export AI_WEIGHT="${AI_WEIGHT:-0.5}"\n\
export AGENT_SERVER_PORT="${PORT:-7860}"\n\
export ENVIRONMENT="${ENVIRONMENT:-production}"\n\
export LOG_LEVEL="${LOG_LEVEL:-INFO}"\n\
\n\
echo "✓ Configuration loaded"\n\
echo "  Port: $AGENT_SERVER_PORT"\n\
echo "  Model: $GEMINI_MODEL"\n\
echo "  Weights: Rule=$RULE_WEIGHT, AI=$AI_WEIGHT"\n\
echo ""\n\
echo "Starting Agent Server..."\n\
echo ""\n\
\n\
# Start the agent server\n\
exec uvicorn agent_server:app --host 0.0.0.0 --port $AGENT_SERVER_PORT\n\
' > /app/start.sh && chmod +x /app/start.sh

# Set environment variables with defaults
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PORT=7860

# Expose port (Hugging Face uses 7860 by default)
EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
    CMD curl -f http://localhost:${PORT:-7860}/health || exit 1

# Run startup script
CMD ["/app/start.sh"]