Commit
·
bccd12c
1
Parent(s):
00c4bbe
update Dockerfile
Browse files- Dockerfile +50 -7
Dockerfile
CHANGED
@@ -1,13 +1,56 @@
|
|
1 |
-
FROM python:3.9
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
RUN useradd -m -u 1000 user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
USER user
|
5 |
-
ENV PATH="/home/user/.local/bin:$PATH"
|
6 |
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
+
FROM python:3.9-slim-buster
|
2 |
|
3 |
+
# Install system dependencies as root
|
4 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
5 |
+
git \
|
6 |
+
wget \
|
7 |
+
curl \
|
8 |
+
unzip \
|
9 |
+
libgconf-2-4 \
|
10 |
+
libnss3 \
|
11 |
+
libgl1 \
|
12 |
+
libx11-xcb1 \
|
13 |
+
libxcb-dri3-0 \
|
14 |
+
libdrm2 \
|
15 |
+
libgbm1 \
|
16 |
+
libasound2 \
|
17 |
+
apt-get clean \
|
18 |
+
&& rm -rf /var/lib/apt/lists/*
|
19 |
+
|
20 |
+
# Install Chrome
|
21 |
+
RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
|
22 |
+
&& apt-get install -y ./google-chrome-stable_current_amd64.deb \
|
23 |
+
&& rm google-chrome-stable_current_amd64.deb
|
24 |
+
|
25 |
+
# Install matching Chromedriver
|
26 |
+
RUN CHROME_VERSION=$(google-chrome --version | cut -d ' ' -f3 | cut -d '.' -f1) \
|
27 |
+
&& wget -q https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION} \
|
28 |
+
&& wget -q https://chromedriver.storage.googleapis.com/$(cat LATEST_RELEASE_${CHROME_VERSION})/chromedriver_linux64.zip \
|
29 |
+
&& unzip chromedriver_linux64.zip -d /usr/bin/ \
|
30 |
+
&& rm chromedriver_linux64.zip LATEST_RELEASE_${CHROME_VERSION}
|
31 |
+
|
32 |
+
# Create user with UID 1000
|
33 |
RUN useradd -m -u 1000 user
|
34 |
+
|
35 |
+
# Set environment variables
|
36 |
+
ENV HOME=/home/user \
|
37 |
+
PATH=/home/user/.local/bin:$PATH \
|
38 |
+
CHROME_DRIVER=/usr/bin/chromedriver \
|
39 |
+
CHROME_BIN=/usr/bin/google-chrome-stable \
|
40 |
+
PYTHONUNBUFFERED=1
|
41 |
+
|
42 |
+
# Set working directory
|
43 |
+
WORKDIR $HOME/app
|
44 |
+
|
45 |
+
# Switch to non-root user
|
46 |
USER user
|
|
|
47 |
|
48 |
+
# Copy requirements first to leverage Docker cache
|
49 |
+
COPY --chown=user requirements.txt .
|
50 |
+
RUN pip install --no-cache-dir --upgrade pip \
|
51 |
+
&& pip install --no-cache-dir -r requirements.txt
|
52 |
|
53 |
+
# Copy application code
|
54 |
+
COPY --chown=user . .
|
55 |
|
56 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|