leonsimon23 commited on
Commit
88f45cc
·
verified ·
1 Parent(s): 889a10a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +14 -26
Dockerfile CHANGED
@@ -4,6 +4,7 @@ FROM python:3.10-slim
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,46 +12,33 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
  # --- Install R Packages ---
14
- RUN Rscript -e "tryCatch(install.packages(c('randomForest'), repos='https://cloud.r-project.org/', dependencies=TRUE), error=function(e){print(e); q(status=1)})" \
15
- && echo "R packages installed successfully."
16
 
17
  # --- Python Setup ---
 
18
  RUN pip install --upgrade pip
19
 
20
  # --- Application Code ---
 
 
21
  RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
22
  git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/pdpredict.git . \
23
  || (echo "GIT CLONE FAILED!" && exit 1)
24
 
25
- RUN echo "--- Listing files in /app after clone ---" && ls -la /app
26
-
27
  # --- Install Python Dependencies ---
28
- RUN if [ ! -f requirements.txt ]; then \
29
- echo "ERROR: requirements.txt not found!"; exit 1; \
30
- fi
31
  RUN pip install --no-cache-dir -r requirements.txt \
32
  || (echo "PIP INSTALL FAILED!" && exit 1)
33
 
34
- # --- DEBUG: Test R and rpy2 imports ---
35
- RUN echo "--- Testing R library load ---" \
36
- && Rscript -e "library(randomForest)" \
37
- || (echo "ERROR: Failed to load randomForest R library" && exit 1)
38
- RUN echo "--- Testing rpy2 import ---" \
39
- && python -c "import rpy2.robjects; print('rpy2 import OK')" \
40
- || (echo "ERROR: Failed to import rpy2 in Python" && exit 1)
41
-
42
- # --- DEBUG: Try importing the 'api' module directly with Python ---
43
- # This will execute the module-level code in api.py and show any import-time errors
44
- RUN echo "--- Attempting Python import of 'api' module ---" \
45
- && python -c "import api; print('SUCCESS: Python successfully imported api module')" \
46
- || (echo "ERROR: Python failed to import the 'api' module. Check traceback above." && exit 1)
47
-
48
- # Set permissions
49
  RUN chmod -R 755 /app
50
 
51
- # --- DEBUG: List files right before CMD ---
52
- RUN echo "--- Listing files in /app before CMD ---" && ls -la /app
53
-
54
  # --- Port and Run Command ---
 
55
  EXPOSE 8000
56
- CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]
 
 
 
 
4
  WORKDIR /app
5
 
6
  # --- Install System Dependencies ---
7
+ # Includes git (for cloning), R, and R development tools
8
  RUN apt-get update && apt-get install -y --no-install-recommends \
9
  git \
10
  r-base \
 
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
  # --- Install R Packages ---
15
+ # Install the R packages required by your model (adjust if needed)
16
+ RUN Rscript -e "install.packages(c('randomForest'), repos='https://cloud.r-project.org/', dependencies=TRUE)"
17
 
18
  # --- Python Setup ---
19
+ # Upgrade pip
20
  RUN pip install --upgrade pip
21
 
22
  # --- Application Code ---
23
+ # Clone private repository using mounted secret
24
+ # Assumes app.py, requirements.txt, rf_model.rds are in the repo root
25
  RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
26
  git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/pdpredict.git . \
27
  || (echo "GIT CLONE FAILED!" && exit 1)
28
 
 
 
29
  # --- Install Python Dependencies ---
30
+ # Install Python requirements from file cloned via git
 
 
31
  RUN pip install --no-cache-dir -r requirements.txt \
32
  || (echo "PIP INSTALL FAILED!" && exit 1)
33
 
34
+ # --- Permissions ---
35
+ # Optional, but can help prevent permission issues in some environments
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  RUN chmod -R 755 /app
37
 
 
 
 
38
  # --- Port and Run Command ---
39
+ # Expose the port (Using 8000, change to 7860 if required by Hugging Face Spaces)
40
  EXPOSE 8000
41
+
42
+ # Run the FastAPI app defined in app.py (app:app) using uvicorn
43
+ # Using port 8000, change to 7860 if required by Hugging Face Spaces
44
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]