Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +34 -14
Dockerfile
CHANGED
|
@@ -4,27 +4,47 @@ FROM python:3.10-slim
|
|
| 4 |
# Set working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
# Install
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
RUN pip install --upgrade pip
|
| 12 |
|
| 13 |
-
# Create
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
# Clone private repository using mounted secret
|
|
|
|
| 17 |
RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
|
| 18 |
git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/pdpredict.git .
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# Install Python dependencies
|
| 24 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
# Run the FastAPI app
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 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 \
|
| 13 |
+
r-base-dev \
|
| 14 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
+
|
| 16 |
+
# --- Install R Packages ---
|
| 17 |
+
# Install the R packages required by your model.
|
| 18 |
+
# *** Adjust the list c('randomForest') if your model needs other packages ***
|
| 19 |
+
RUN Rscript -e "install.packages(c('randomForest'), repos='https://cloud.r-project.org/', dependencies=TRUE)"
|
| 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 private repository using mounted secret
|
| 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 should be present after cloning
|
| 38 |
+
# This MUST run *after* R is installed so rpy2 can find it
|
|
|
|
| 39 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 40 |
|
| 41 |
+
# --- Port and Run Command ---
|
| 42 |
+
# Expose the port your FastAPI app runs on (as defined in api.py or CMD)
|
| 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"]
|