Spaces:
Sleeping
Sleeping
| # Stage 1: Builder stage with Mambaforge to install dependencies | |
| FROM condaforge/mambaforge:latest AS builder | |
| # Set environment variables for non-interactive package installation | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| ENV TZ=Etc/UTC | |
| # Set environment variables for GMT/PyGMT | |
| ENV GMT_HOME=/opt/conda | |
| ENV PROJ_LIB=/opt/conda/share/proj | |
| ENV PATH="/opt/conda/bin:${PATH}" | |
| WORKDIR /app | |
| # Install essential system dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| ghostscript \ | |
| imagemagick \ | |
| tzdata \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy all necessary files into the builder | |
| COPY requirements.txt ./ | |
| COPY src/ ./src/ | |
| COPY GDMS_earthquake_catalog.csv ./ | |
| COPY CWASN_station_list.txt ./ | |
| # --- MODIFIED INSTALLATION STEPS --- | |
| # 1. Use mamba ONLY for the complex scientific stack | |
| RUN mamba install -c conda-forge \ | |
| gmt=6.5.0 \ | |
| pygmt>=0.10.0 \ | |
| matplotlib -y && \ | |
| mamba clean --all -f -y | |
| # 2. Use pip to install the rest of the Python libraries from requirements.txt | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Stage 2: Final, lightweight production image | |
| FROM python:3.9-slim | |
| WORKDIR /app | |
| # Create a non-root user for security | |
| RUN useradd -ms /bin/bash appuser | |
| # Copy the environment, application code, and data files from the builder stage | |
| COPY --from=builder /opt/conda /opt/conda | |
| COPY --from=builder /app/src ./src | |
| COPY --from=builder /app/GDMS_earthquake_catalog.csv ./ | |
| COPY --from=builder /app/CWASN_station_list.txt ./ | |
| # Set environment variables for the new stage | |
| ENV PATH="/opt/conda/bin:${PATH}" | |
| # Grant ownership of the app directory to the non-root user | |
| RUN chown -R appuser:appuser /app | |
| # Switch to the non-root user | |
| USER appuser | |
| EXPOSE 8501 | |
| HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health | |
| # Use the full path to the streamlit executable | |
| ENTRYPOINT ["/opt/conda/bin/streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"] |