FROM python:3.11-slim WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ gcc \ g++ \ && rm -rf /var/lib/apt/lists/* # Copy requirements COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy application files COPY app.py . COPY ocr_invoice.py . COPY cost_tracker.py . COPY auth.py . COPY allowed_users.txt . COPY static/ ./static/ # Create necessary directories with proper permissions RUN mkdir -p /tmp/uploads && chmod 777 /tmp/uploads RUN mkdir -p /app/credentials && chmod 777 /app/credentials # Expose port EXPOSE 7860 # Set environment variables ENV PYTHONUNBUFFERED=1 # Create startup script that handles credentials RUN echo '#!/bin/bash\n\ if [ ! -z "$GOOGLE_APPLICATION_CREDENTIALS_JSON" ]; then\n\ echo "$GOOGLE_APPLICATION_CREDENTIALS_JSON" > /app/credentials/credentials.json\n\ export GOOGLE_APPLICATION_CREDENTIALS=/app/credentials/credentials.json\n\ echo "✓ Created credentials file from environment variable"\n\ elif [ ! -z "$GOOGLE_APPLICATION_CREDENTIALS" ]; then\n\ if [ ! -f "$GOOGLE_APPLICATION_CREDENTIALS" ]; then\n\ echo "$GOOGLE_APPLICATION_CREDENTIALS" > /app/credentials/credentials.json\n\ export GOOGLE_APPLICATION_CREDENTIALS=/app/credentials/credentials.json\n\ echo "✓ Created credentials file from GOOGLE_APPLICATION_CREDENTIALS"\n\ fi\n\ fi\n\ exec uvicorn app:app --host 0.0.0.0 --port 7860' > /app/start.sh && chmod +x /app/start.sh # Run the application via startup script CMD ["/bin/bash", "/app/start.sh"]