kltn20133118 commited on
Commit
6c40988
·
verified ·
1 Parent(s): a510602

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +72 -11
Dockerfile CHANGED
@@ -1,7 +1,20 @@
1
- FROM python:3.11
2
 
3
- WORKDIR /code
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  build-essential \
7
  curl \
@@ -15,6 +28,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
15
  libpng-dev \
16
  && rm -rf /var/lib/apt/lists/*
17
 
 
18
  RUN apt-get update && apt-get install -y --no-install-recommends \
19
  libglib2.0-0 \
20
  libnss3 \
@@ -39,17 +53,64 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
39
  libatspi2.0-0 \
40
  && rm -rf /var/lib/apt/lists/*
41
 
42
- ENV HOME=/code
43
- ENV XDG_CACHE_HOME=/code/.cache
 
 
 
 
 
 
44
 
45
- RUN mkdir -p /code/.cache && chmod -R 777 /code
46
- COPY ./requirements.txt /code/requirements.txt
47
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
48
- RUN pip install playwright
49
- RUN playwright install chromium
50
 
 
51
  COPY . .
52
 
53
- EXPOSE 9091 9222 8000 8080
54
 
55
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "9091"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # syntax=docker/dockerfile:1.4
2
 
3
+ ARG TARGETPLATFORM
4
+ ARG BUILDPLATFORM
5
 
6
+ # Other build arguments
7
+ ARG PYTHON_VERSION=3.10
8
+
9
+ # Base stage with system dependencies
10
+ FROM python:${PYTHON_VERSION}-slim as base
11
+
12
+ # Declare ARG variables again within the build stage
13
+ ARG INSTALL_TYPE=all
14
+ ARG ENABLE_GPU=false
15
+
16
+
17
+ # Install system dependencies
18
  RUN apt-get update && apt-get install -y --no-install-recommends \
19
  build-essential \
20
  curl \
 
28
  libpng-dev \
29
  && rm -rf /var/lib/apt/lists/*
30
 
31
+ # Playwright system dependencies for Linux
32
  RUN apt-get update && apt-get install -y --no-install-recommends \
33
  libglib2.0-0 \
34
  libnss3 \
 
53
  libatspi2.0-0 \
54
  && rm -rf /var/lib/apt/lists/*
55
 
56
+ # GPU support if enabled and architecture is supported
57
+ RUN if [ "$ENABLE_GPU" = "true" ] && [ "$TARGETPLATFORM" = "linux/amd64" ] ; then \
58
+ apt-get update && apt-get install -y --no-install-recommends \
59
+ nvidia-cuda-toolkit \
60
+ && rm -rf /var/lib/apt/lists/* ; \
61
+ else \
62
+ echo "Skipping NVIDIA CUDA Toolkit installation (unsupported platform or GPU disabled)"; \
63
+ fi
64
 
65
+ # Create and set working directory
66
+ WORKDIR /app
 
 
 
67
 
68
+ # Copy the entire project
69
  COPY . .
70
 
 
71
 
72
+ RUN pip install --no-cache-dir -r requirements.txt
73
+
74
+ # Install required library for FastAPI
75
+ RUN pip install fastapi uvicorn psutil
76
+
77
+ # Install ML dependencies first for better layer caching
78
+ RUN if [ "$INSTALL_TYPE" = "all" ] ; then \
79
+ pip install --no-cache-dir \
80
+ torch \
81
+ torchvision \
82
+ torchaudio \
83
+ scikit-learn \
84
+ nltk \
85
+ transformers \
86
+ tokenizers && \
87
+ python -m nltk.downloader punkt stopwords ; \
88
+ fi
89
+
90
+ # Install the package
91
+ RUN if [ "$INSTALL_TYPE" = "all" ] ; then \
92
+ pip install ".[all]" && \
93
+ python -m crawl4ai.model_loader ; \
94
+ elif [ "$INSTALL_TYPE" = "torch" ] ; then \
95
+ pip install ".[torch]" ; \
96
+ elif [ "$INSTALL_TYPE" = "transformer" ] ; then \
97
+ pip install ".[transformer]" && \
98
+ python -m crawl4ai.model_loader ; \
99
+ else \
100
+ pip install "." ; \
101
+ fi
102
+
103
+
104
+
105
+ # Install Playwright and browsers
106
+ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
107
+ playwright install chromium; \
108
+ elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
109
+ playwright install chromium; \
110
+ fi
111
+
112
+ # Expose port
113
+ EXPOSE 8000 11235 9222 8080
114
+
115
+ # Start the FastAPI server
116
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "11235"]