gaia-llamaindex-agent / Dockerfile
LamiaYT's picture
Fix Dockerfile & Gradio compatibility
bbe4b6b
# 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"]