File size: 1,835 Bytes
f1c2e53
56597e4
 
bbe4b6b
f1c2e53
bbe4b6b
 
 
 
 
f1c2e53
 
 
 
bbe4b6b
f1c2e53
56597e4
 
 
f1c2e53
bbe4b6b
 
 
 
 
f1c2e53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56597e4
 
bbe4b6b
f1c2e53
 
 
 
 
bbe4b6b
f1c2e53
 
 
 
 
 
 
 
 
 
 
 
56597e4
bbe4b6b
f1c2e53
 
56597e4
f1c2e53
bbe4b6b
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
# Use a base Python image with better compatibility
FROM python:3.10-slim

# Set environment variables to fix permission issues (use /tmp paths)
ENV PYTHONUNBUFFERED=1
ENV NLTK_DATA=/tmp/nltk_data
ENV MPLCONFIGDIR=/tmp/matplotlib_cache
ENV HF_HOME=/tmp/huggingface_cache
ENV TORCH_HOME=/tmp/torch_cache
ENV TRANSFORMERS_CACHE=/tmp/huggingface_cache
ENV GRADIO_SERVER_NAME=0.0.0.0
ENV GRADIO_SERVER_PORT=7860

# Create app user and group for better security
RUN groupadd -r appuser && useradd -r -g appuser -u 1000 -m -s /bin/bash appuser

# Set working directory
WORKDIR /app

# Create cache directories with proper permissions
RUN mkdir -p /tmp/nltk_data \
    /tmp/matplotlib_cache \
    /tmp/huggingface_cache \
    /tmp/torch_cache \
    && chown -R appuser:appuser /tmp

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

# Copy requirements first for better Docker layer caching
COPY requirements.txt .

# Install Python dependencies
RUN pip install --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Change ownership of app files
RUN chown -R appuser:appuser /app

# Switch to non-root user
USER appuser

# Create a startup script
RUN echo '#!/bin/bash\n\
echo "Starting GAIA Agent..."\n\
echo "Environment check:"\n\
echo "NLTK_DATA: $NLTK_DATA"\n\
echo "HF_HOME: $HF_HOME"\n\
echo "MPLCONFIGDIR: $MPLCONFIGDIR"\n\
echo "Working directory: $(pwd)"\n\
echo "User: $(whoami)"\n\
python app.py' > /app/start.sh && chmod +x /app/start.sh

# Expose the port
EXPOSE 7860

# Health check (optional but helpful)
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:7860/ || exit 1

# Run the application
CMD ["/app/start.sh"]