hackathongenai / Dockerfile
kushal2006's picture
Update Dockerfile
7db7d5b verified
# Use an official Python runtime as a parent image
FROM python:3.10-slim
# Set the working directory in the container
WORKDIR /app
# Set environment variables for HuggingFace Spaces
ENV HOME=/app
ENV STREAMLIT_HOME=/app/.streamlit
ENV DATABASE_PATH=/tmp/resume_analysis.db
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
curl \
wget \
git \
sqlite3 \
&& rm -rf /var/lib/apt/lists/*
# Copy the requirements file first for better caching
COPY requirements.txt .
# Install Python packages
RUN pip install --no-cache-dir -r requirements.txt
# Create directories that we can write to
RUN mkdir -p /tmp/data /tmp/uploads /tmp/logs && \
mkdir -p /app/.streamlit
# Copy the rest of the application code
COPY . .
# Create Streamlit config file
RUN echo '[server]' > /app/.streamlit/config.toml && \
echo 'headless = true' >> /app/.streamlit/config.toml && \
echo 'port = 8501' >> /app/.streamlit/config.toml && \
echo 'address = "0.0.0.0"' >> /app/.streamlit/config.toml && \
echo 'enableCORS = false' >> /app/.streamlit/config.toml && \
echo 'enableXsrfProtection = false' >> /app/.streamlit/config.toml && \
echo '' >> /app/.streamlit/config.toml && \
echo '[browser]' >> /app/.streamlit/config.toml && \
echo 'gatherUsageStats = false' >> /app/.streamlit/config.toml && \
echo 'serverAddress = "0.0.0.0"' >> /app/.streamlit/config.toml && \
echo '' >> /app/.streamlit/config.toml && \
echo '[theme]' >> /app/.streamlit/config.toml && \
echo 'primaryColor = "#3B82F6"' >> /app/.streamlit/config.toml && \
echo 'backgroundColor = "#F9FAFB"' >> /app/.streamlit/config.toml && \
echo 'secondaryBackgroundColor = "#FFFFFF"' >> /app/.streamlit/config.toml && \
echo 'textColor = "#1F2937"' >> /app/.streamlit/config.toml
# Make port 8000 (FastAPI) and 8501 (Streamlit) available
EXPOSE 8000 8501
# Create the startup script directly in Dockerfile (no chmod needed)
RUN echo '#!/bin/bash' > /app/start.sh && \
echo 'set -e' >> /app/start.sh && \
echo '' >> /app/start.sh && \
echo '# HuggingFace Spaces Safe Startup' >> /app/start.sh && \
echo 'echo "🤗 Starting AI Resume Analyzer on HuggingFace Spaces"' >> /app/start.sh && \
echo '' >> /app/start.sh && \
echo '# Create writable directories in /tmp' >> /app/start.sh && \
echo 'mkdir -p /tmp/data /tmp/uploads /tmp/logs 2>/dev/null || true' >> /app/start.sh && \
echo '' >> /app/start.sh && \
echo '# Start FastAPI Backend' >> /app/start.sh && \
echo 'echo "⚡ Starting FastAPI Backend..."' >> /app/start.sh && \
echo 'uvicorn app:app --host 0.0.0.0 --port 8000 --workers 1 &' >> /app/start.sh && \
echo 'BACKEND_PID=$!' >> /app/start.sh && \
echo 'echo "Backend PID: $BACKEND_PID"' >> /app/start.sh && \
echo '' >> /app/start.sh && \
echo '# Wait for backend startup' >> /app/start.sh && \
echo 'echo "⏳ Waiting for backend to start..."' >> /app/start.sh && \
echo 'for i in {1..30}; do' >> /app/start.sh && \
echo ' if curl -s http://localhost:8000/health > /dev/null 2>&1; then' >> /app/start.sh && \
echo ' echo "✅ Backend is ready!"' >> /app/start.sh && \
echo ' break' >> /app/start.sh && \
echo ' fi' >> /app/start.sh && \
echo ' echo "Waiting for backend... ($i/30)"' >> /app/start.sh && \
echo ' sleep 2' >> /app/start.sh && \
echo 'done' >> /app/start.sh && \
echo '' >> /app/start.sh && \
echo '# Start Streamlit Frontend' >> /app/start.sh && \
echo 'echo "🎨 Starting Streamlit Frontend..."' >> /app/start.sh && \
echo 'export STREAMLIT_SERVER_HEADLESS=true' >> /app/start.sh && \
echo 'export STREAMLIT_BROWSER_GATHER_USAGE_STATS=false' >> /app/start.sh && \
echo 'export STREAMLIT_SERVER_ENABLE_CORS=false' >> /app/start.sh && \
echo 'streamlit run streamlit_app.py' >> /app/start.sh
# No chmod needed - run with bash explicitly
CMD ["bash", "/app/start.sh"]