Spaces:
Sleeping
Sleeping
| FROM python:3.11-slim | |
| # Create a non-root user and set up directories | |
| RUN useradd --create-home --shell /bin/bash app | |
| USER app | |
| WORKDIR /home/app | |
| # Switch back to root for package installation | |
| USER root | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| curl \ | |
| git \ | |
| wget \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set up git config with proper user context to avoid permission errors | |
| RUN mkdir -p /home/app && chown -R app:app /home/app | |
| USER app | |
| # Pre-configure git to avoid build-time permission issues | |
| RUN git config --global user.email "pgits.job@gmail.com" || true | |
| RUN git config --global user.name "pgits" || true | |
| # Set working directory with proper ownership | |
| WORKDIR /home/app | |
| # Copy requirements first for better caching (as root to ensure permissions) | |
| USER root | |
| COPY requirements.txt /home/app/ | |
| RUN chown app:app /home/app/requirements.txt | |
| # Switch back to app user for pip install | |
| USER app | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy application files as root, then fix permissions | |
| USER root | |
| COPY . /home/app/ | |
| COPY hello_world.py /home/app/app.py | |
| RUN chown -R app:app /home/app/ | |
| RUN ls -la /home/app/ # Debug: list files to verify copy worked | |
| # Switch back to app user for runtime | |
| USER app | |
| # Expose the port that Streamlit runs on | |
| EXPOSE 7860 | |
| # Set Streamlit configuration for HuggingFace Spaces | |
| ENV STREAMLIT_SERVER_PORT=7860 | |
| ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0 | |
| ENV STREAMLIT_SERVER_HEADLESS=true | |
| ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false | |
| # Health check | |
| HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health | |
| # Verify files exist and run Streamlit | |
| CMD ["sh", "-c", "ls -la /home/app/ && python -m streamlit run app.py --server.port=7860 --server.address=0.0.0.0"] | |