Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +38 -25
Dockerfile
CHANGED
|
@@ -1,12 +1,9 @@
|
|
| 1 |
# syntax=docker/dockerfile:1.4
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
-
# Set working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
# --- Install System Dependencies ---
|
| 8 |
-
# Includes git (for cloning), R, and R development tools (needed for R packages/rpy2)
|
| 9 |
-
# Add any other system libraries needed by specific R packages here (e.g., libcurl4-openssl-dev, libssl-dev)
|
| 10 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 11 |
git \
|
| 12 |
r-base \
|
|
@@ -14,37 +11,53 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
|
| 16 |
# --- Install R Packages ---
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
# --- Python Setup ---
|
| 22 |
-
# Upgrade pip
|
| 23 |
RUN pip install --upgrade pip
|
| 24 |
|
| 25 |
-
# Create app directory (redundant with WORKDIR, but harmless) and set permissions
|
| 26 |
-
# Using 755 is generally safer than 777 unless specifically needed
|
| 27 |
-
RUN mkdir -p /app && chmod -R 755 /app
|
| 28 |
-
WORKDIR /app # Ensure we are in the workdir
|
| 29 |
-
|
| 30 |
# --- Application Code ---
|
| 31 |
-
# Clone
|
| 32 |
-
# This will bring in api.py, rf_model.rds, requirements.txt, etc.
|
| 33 |
RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
|
| 34 |
-
git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/pdpredict.git .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# --- Install Python Dependencies ---
|
| 37 |
-
# requirements.txt
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# --- Port and Run Command ---
|
| 42 |
-
#
|
| 43 |
-
# Changed from 7860 to 8000 to match api.py standard uvicorn command
|
| 44 |
EXPOSE 8000
|
| 45 |
-
|
| 46 |
-
# Run the FastAPI app defined in api.py using uvicorn
|
| 47 |
-
# Corrected 'app:app' to 'api:app'
|
| 48 |
-
# Corrected port from 7860 to 8000
|
| 49 |
-
# If HF Spaces requires port 7860, change EXPOSE and --port back to 7860
|
| 50 |
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
|
|
| 1 |
# syntax=docker/dockerfile:1.4
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
|
|
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
# --- Install System Dependencies ---
|
|
|
|
|
|
|
| 7 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 8 |
git \
|
| 9 |
r-base \
|
|
|
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
# --- Install R Packages ---
|
| 14 |
+
# Using tryCatch for basic error checking during R package installation
|
| 15 |
+
RUN Rscript -e "tryCatch(install.packages(c('randomForest'), repos='https://cloud.r-project.org/', dependencies=TRUE), error=function(e){print(e); q(status=1)})" \
|
| 16 |
+
&& echo "R packages installed successfully."
|
| 17 |
|
| 18 |
# --- Python Setup ---
|
|
|
|
| 19 |
RUN pip install --upgrade pip
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# --- Application Code ---
|
| 22 |
+
# Clone repository
|
|
|
|
| 23 |
RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
|
| 24 |
+
git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/pdpredict.git . \
|
| 25 |
+
|| (echo "GIT CLONE FAILED!" && exit 1) # Add basic error check for clone
|
| 26 |
+
|
| 27 |
+
# --- DEBUG: List files in /app AFTER cloning ---
|
| 28 |
+
# This is CRITICAL to see if api.py and requirements.txt are where they should be
|
| 29 |
+
RUN echo "--- Listing files in /app after clone ---" && ls -la /app
|
| 30 |
|
| 31 |
# --- Install Python Dependencies ---
|
| 32 |
+
# Check if requirements.txt exists before trying to install
|
| 33 |
+
RUN if [ ! -f requirements.txt ]; then \
|
| 34 |
+
echo "ERROR: requirements.txt not found in /app after clone!"; \
|
| 35 |
+
exit 1; \
|
| 36 |
+
fi
|
| 37 |
+
# Install dependencies
|
| 38 |
+
RUN pip install --no-cache-dir -r requirements.txt \
|
| 39 |
+
|| (echo "PIP INSTALL FAILED!" && exit 1) # Add basic error check
|
| 40 |
+
|
| 41 |
+
# --- DEBUG: Test Critical Imports ---
|
| 42 |
+
# Test if R library can be loaded via Rscript
|
| 43 |
+
RUN echo "--- Testing R library load ---" \
|
| 44 |
+
&& Rscript -e "library(randomForest)" \
|
| 45 |
+
|| (echo "ERROR: Failed to load randomForest R library" && exit 1)
|
| 46 |
+
# Test if rpy2 can be imported in Python
|
| 47 |
+
RUN echo "--- Testing rpy2 import ---" \
|
| 48 |
+
&& python -c "import rpy2.robjects; print('rpy2 import OK')" \
|
| 49 |
+
|| (echo "ERROR: Failed to import rpy2 in Python" && exit 1)
|
| 50 |
+
|
| 51 |
+
# --- DEBUG: Check api.py syntax (optional but helpful) ---
|
| 52 |
+
# This tries to compile api.py to catch basic syntax errors
|
| 53 |
+
RUN echo "--- Checking api.py syntax ---" \
|
| 54 |
+
&& python -m compileall api.py \
|
| 55 |
+
|| (echo "ERROR: api.py has syntax errors" && exit 1)
|
| 56 |
+
|
| 57 |
+
# Set permissions (can often be skipped if owner is correct, but good practice)
|
| 58 |
+
RUN chmod -R 755 /app
|
| 59 |
|
| 60 |
# --- Port and Run Command ---
|
| 61 |
+
# Using port 8000 based on api.py, adjust if HF requires 7860
|
|
|
|
| 62 |
EXPOSE 8000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]
|