Skip to content

Commit 6ba5747

Browse files
committed
feat: Refactor Dockerfile and Dockerfile.prod for improved build process and dependency management
1 parent 1a21325 commit 6ba5747

File tree

4 files changed

+83
-51
lines changed

4 files changed

+83
-51
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ README.md
1616
.git
1717
.gitattributes
1818
.gitignore
19+
.github
20+
21+
evaluation/

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "debugpy",
77
"justMyCode":false,
88
"request": "launch",
9-
"program": "/usr/local/bin/streamlit",
9+
"program": "/opt/venv/bin/streamlit",
1010
"args": [
1111
"run",
1212
"./start.py"
@@ -18,7 +18,7 @@
1818
"type": "debugpy",
1919
"request": "launch",
2020
"justMyCode":false,
21-
"program": "/usr/local/bin/streamlit",
21+
"program": "/opt/venv/bin/streamlit",
2222
"env":{ "PYTHONPATH": "/app"},
2323
"args": [
2424
"run",

Dockerfile

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
1-
# Use the official Python image from Docker Hub
2-
FROM python:3.11
1+
FROM python:3.11 as builder
32

43
# Set the working directory inside the container
54
WORKDIR /app
65

7-
# Install dependencies
6+
# Install build dependencies
87
RUN apt-get update && apt-get install -y \
98
sudo \
109
wget \
11-
gettext
10+
gettext \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
RUN python -m venv /opt/venv
14+
ENV PATH="/opt/venv/bin:$PATH"
15+
16+
# Install Python packages
17+
RUN pip install --upgrade pip
18+
COPY ./requirements.txt .
19+
RUN pip install -r requirements.txt
20+
21+
# Download Python source for internationalization
22+
RUN wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz \
23+
&& tar xzf Python-3.11.0.tgz \
24+
&& mv Python-3.11.0 /usr/local/src/ \
25+
&& rm Python-3.11.0.tgz
26+
27+
# Copy application code and compile messages
28+
COPY . .
29+
RUN chmod +x /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py
30+
RUN /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py /app/locale/de/LC_MESSAGES/base.po /app/locale/de/LC_MESSAGES/base
31+
32+
# Final stage
33+
FROM python:3.11-slim
1234

35+
# Set the working directory
36+
WORKDIR /app
1337

14-
# Playwright system dependencies for Linux
38+
# Install runtime dependencies
1539
RUN apt-get update && apt-get install -y --no-install-recommends \
1640
libglib2.0-0 \
1741
libnss3 \
@@ -36,30 +60,21 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3660
libatspi2.0-0 \
3761
&& rm -rf /var/lib/apt/lists/*
3862

63+
# Copy only necessary files from builder
3964

40-
RUN pip install --upgrade pip
41-
COPY ./requirements.txt .
42-
RUN pip install -r requirements.txt
43-
RUN playwright install
44-
RUN crawl4ai-setup
45-
46-
65+
COPY --from=builder /opt/venv /opt/venv
66+
ENV PATH="/opt/venv/bin:$PATH"
67+
COPY --from=builder /app/locale /app/locale
68+
COPY --from=builder /app /app
4769

48-
# Download Python source (Needed for internationalization)
49-
RUN wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz \
50-
&& tar xzf Python-3.11.0.tgz \
51-
&& mv Python-3.11.0 /usr/local/src/ \
52-
&& rm Python-3.11.0.tgz
5370

71+
RUN echo $PATH
72+
RUN echo $(which python)
5473

55-
# Copy the rest of the application code into the container
56-
COPY . .
57-
58-
# Compile the .po file into a .mo file
59-
#RUN ls -l /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py
60-
RUN chmod +x /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py
61-
RUN /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py /app/locale/de/LC_MESSAGES/base.po /app/locale/de/LC_MESSAGES/base
6274

75+
# Install Playwright browsers
76+
RUN playwright install
77+
RUN crawl4ai-setup
6378
# Expose the port that Streamlit will run on
6479
EXPOSE 8501
6580

Dockerfile.prod

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
1-
# Use the official Python image from Docker Hub
2-
# Use the official Python image from Docker Hub
3-
FROM python:3.11
1+
FROM python:3.11 as builder
42

53
# Set the working directory inside the container
64
WORKDIR /app
75

8-
# Install dependencies
6+
# Install build dependencies
97
RUN apt-get update && apt-get install -y \
108
sudo \
119
wget \
12-
gettext
10+
gettext \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
RUN python -m venv /opt/venv
14+
ENV PATH="/opt/venv/bin:$PATH"
15+
16+
# Install Python packages
17+
RUN pip install --upgrade pip
18+
COPY ./requirements.prod.txt .
19+
RUN pip install -r requirements.prod.txt
20+
21+
# Download Python source for internationalization
22+
RUN wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz \
23+
&& tar xzf Python-3.11.0.tgz \
24+
&& mv Python-3.11.0 /usr/local/src/ \
25+
&& rm Python-3.11.0.tgz
26+
27+
# Copy application code and compile messages
28+
COPY . .
29+
RUN chmod +x /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py
30+
RUN /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py /app/locale/de/LC_MESSAGES/base.po /app/locale/de/LC_MESSAGES/base
31+
32+
# Final stage
33+
FROM python:3.11-slim
1334

35+
# Set the working directory
36+
WORKDIR /app
1437

15-
# Playwright system dependencies for Linux
38+
# Install runtime dependencies
1639
RUN apt-get update && apt-get install -y --no-install-recommends \
1740
libglib2.0-0 \
1841
libnss3 \
@@ -37,30 +60,21 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3760
libatspi2.0-0 \
3861
&& rm -rf /var/lib/apt/lists/*
3962

40-
RUN pip install --upgrade pip
41-
COPY ./requirements.prod.txt .
42-
RUN pip install -r requirements.prod.txt
43-
RUN playwright install
44-
RUN crawl4ai-setup
45-
46-
47-
# Download Python source (Needed for internationalization)
48-
RUN wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz \
49-
&& tar xzf Python-3.11.0.tgz \
50-
&& mv Python-3.11.0 /usr/local/src/ \
51-
&& rm Python-3.11.0.tgz
63+
# Copy only necessary files from builder
5264

65+
COPY --from=builder /opt/venv /opt/venv
66+
ENV PATH="/opt/venv/bin:$PATH"
67+
COPY --from=builder /app/locale /app/locale
68+
COPY --from=builder /app /app
5369

5470

55-
# Copy the rest of the application code into the container
56-
COPY . .
57-
58-
# Compile the .po file into a .mo file
59-
#RUN ls -l /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py
60-
RUN chmod +x /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py
61-
RUN /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py /app/locale/de/LC_MESSAGES/base.po /app/locale/de/LC_MESSAGES/base
71+
RUN echo $PATH
72+
RUN echo $(which python)
6273

6374

75+
# Install Playwright browsers
76+
RUN playwright install
77+
RUN crawl4ai-setup
6478
# Expose the port that Streamlit will run on
6579
EXPOSE 8501
6680

0 commit comments

Comments
 (0)