Skip to content

Commit 22fc24e

Browse files
committed
docker image optimization and streaming improvement
1 parent e20f99d commit 22fc24e

File tree

9 files changed

+151
-235
lines changed

9 files changed

+151
-235
lines changed

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
# dockerfile: .devcontainer/Dockerfile
1313

1414
volumes:
15+
# Make sure the env is created somewher else ex. /opt/venv. Otherwise this volume will override the venv files
1516
# Update this to wherever you want VS Code to mount the folder of your project
1617
- .:/app
1718

.github/workflows/publish-docker-image.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ on:
1111
- 'pages/**'
1212
- 'Dockerfile.prod'
1313
- 'locale/**'
14-
- 'requirements.prod.txt'
14+
- 'uv.lock'
15+
- 'pyproject.toml'
1516

1617
jobs:
1718
push_to_registries:

Dockerfile

Lines changed: 37 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,56 @@
1-
FROM python:3.11 AS builder
2-
3-
# Grab the uv binary from the official image
4-
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
1+
FROM python:3.11.0
52

63
WORKDIR /app
74

8-
# System build deps
9-
RUN apt-get update && apt-get install -y \
10-
sudo \
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
build-essential \
8+
curl \
9+
ca-certificates \
1110
wget \
11+
gnupg \
12+
git \
13+
cmake \
1214
vim \
13-
curl \
14-
gettext \
15+
pkg-config \
16+
python3-dev \
17+
libjpeg-dev \
18+
libpng-dev \
1519
&& rm -rf /var/lib/apt/lists/*
1620

17-
# ── Python dependencies via uv ──────────────
18-
# Copy only dependency metadata first (layer cache)
19-
COPY pyproject.toml uv.lock ./
20-
21-
# Create a venv and install deps — no source code needed yet
22-
# Install deps fro lock, exclude development deps, these are install by vscode .devcontainer.json
23-
RUN uv venv /opt/venv \
24-
&& . /opt/venv/bin/activate \
25-
&& uv sync --frozen --no-dev --no-install-project
26-
27-
ENV PATH="/app/.venv/bin:$PATH"
28-
29-
# ── Application code ────────────────────────
3021
COPY . .
3122

32-
# Download Python source for i18n
33-
RUN wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz \
34-
&& tar xzf Python-3.11.0.tgz \
35-
&& mv Python-3.11.0 /usr/local/src/ \
36-
&& rm Python-3.11.0.tgz
23+
# Download and install uv
24+
ADD https://astral.sh/uv/install.sh /uv-installer.sh
25+
RUN sh /uv-installer.sh && rm /uv-installer.sh
26+
# Ensure the installed binary is on the `PATH`
27+
ENV PATH="/root/.local/bin:$PATH"
3728

38-
RUN chmod +x /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py \
39-
&& /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py \
40-
/app/locale/de/LC_MESSAGES/base.po \
41-
/app/locale/de/LC_MESSAGES/base
29+
# Create venv and install deps
30+
RUN uv sync --frozen
4231

32+
ENV PATH="/app/.venv/bin:$PATH"
4333

44-
# ──────────────────────────────────────────────
45-
# Runtime stage
46-
# ──────────────────────────────────────────────
47-
FROM python:3.11-slim
48-
49-
WORKDIR /app
34+
RUN echo $PATH
35+
RUN echo $(which python)
36+
RUN echo $(which streamlit)
5037

51-
# Grab uv in the runtime image too (handy for devcontainer)
52-
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
38+
#######----- the locale files are compiled locally, they are mounted/baked into the image-----#####
5339

54-
# Runtime system libs
55-
RUN apt-get update && apt-get install -y --no-install-recommends \
56-
libglib2.0-0 \
57-
libnss3 \
58-
libnspr4 \
59-
libatk1.0-0 \
60-
libatk-bridge2.0-0 \
61-
libcups2 \
62-
libdrm2 \
63-
libdbus-1-3 \
64-
libxcb1 \
65-
libxkbcommon0 \
66-
libx11-6 \
67-
libxcomposite1 \
68-
libxdamage1 \
69-
libxext6 \
70-
libxfixes3 \
71-
libxrandr2 \
72-
libgbm1 \
73-
libpango-1.0-0 \
74-
libcairo2 \
75-
libasound2 \
76-
libatspi2.0-0 \
77-
git \
78-
&& rm -rf /var/lib/apt/lists/*
40+
# Download Python source for i18n
41+
# RUN wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz \
42+
# && tar xzf Python-3.11.0.tgz \
43+
# && mv Python-3.11.0 /usr/local/src/ \
44+
# && rm Python-3.11.0.tgz
7945

80-
# Copy venv + app from builder
81-
COPY --from=builder /opt/venv /opt/venv
82-
ENV PATH="/app/.venv/bin:$PATH"
83-
COPY --from=builder /app /app
46+
# RUN /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py \
47+
# && /usr/local/src/Python-3.11.0/Tools/i18n/msgfmt.py \
48+
# /app/locale/de/LC_MESSAGES/base.po \
49+
# /app/locale/de/LC_MESSAGES/base
8450

8551

8652
# Dev-in-container git config
8753
RUN git config --global --add safe.directory /app
54+
55+
# Expose the port that Streamlit will run on
56+
EXPOSE 8501

Dockerfile.prod

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,32 @@
1-
FROM python:3.11 as builder
1+
FROM python:3.11.0
22

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

65
# Install build dependencies
76
RUN apt-get update && apt-get install -y \
87
sudo \
98
wget \
9+
curl \
1010
gettext \
1111
&& rm -rf /var/lib/apt/lists/*
1212

13-
RUN python -m venv /opt/venv
14-
ENV PATH="/opt/venv/bin:$PATH"
1513

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
2814
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
34-
35-
# Set the working directory
36-
WORKDIR /app
37-
38-
# Install runtime dependencies
39-
RUN apt-get update && apt-get install -y --no-install-recommends \
40-
libglib2.0-0 \
41-
libnss3 \
42-
libnspr4 \
43-
libatk1.0-0 \
44-
libatk-bridge2.0-0 \
45-
libcups2 \
46-
libdrm2 \
47-
libdbus-1-3 \
48-
libxcb1 \
49-
libxkbcommon0 \
50-
libx11-6 \
51-
libxcomposite1 \
52-
libxdamage1 \
53-
libxext6 \
54-
libxfixes3 \
55-
libxrandr2 \
56-
libgbm1 \
57-
libpango-1.0-0 \
58-
libcairo2 \
59-
libasound2 \
60-
libatspi2.0-0 \
61-
&& rm -rf /var/lib/apt/lists/*
62-
63-
# Copy only necessary files from builder
6415

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
16+
# Download and install uv
17+
ADD https://astral.sh/uv/install.sh /uv-installer.sh
18+
RUN sh /uv-installer.sh && rm /uv-installer.sh
19+
ENV PATH="/root/.local/bin:$PATH"
6920

21+
# Set venv PATH first
22+
#ENV PATH="/app/.venv/bin:$PATH"
7023

71-
RUN echo $PATH
72-
RUN echo $(which python)
24+
# Create venv and install deps
25+
#RUN uv venv /app/.venv
26+
RUN uv sync --frozen
27+
ENV PATH="/app/.venv/bin:$PATH"
7328

7429

75-
# Install Playwright browsers
76-
RUN playwright install
77-
RUN crawl4ai-setup
7830
# Expose the port that Streamlit will run on
7931
EXPOSE 8501
8032

docker-compose.yml

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ services:
1212
- .env.dev
1313
volumes:
1414
- logs:/app/logs
15-
- .:/app
1615
- sqlite-data:/root/.crawl4ai
1716
- fastembed:/tmp/fastembed_cache/
1817
ports:
1918
- "8501:8501"
2019
depends_on:
21-
- standalone
2220
- redis
2321
healthcheck:
2422
test: ["CMD", "curl", "--fail", "http://localhost:8501/_stcore/health"]
@@ -65,65 +63,65 @@ services:
6563
- default
6664
restart: always
6765

68-
etcd:
69-
container_name: milvus-etcd
70-
image: quay.io/coreos/etcd:v3.5.16
71-
environment:
72-
- ETCD_AUTO_COMPACTION_MODE=revision
73-
- ETCD_AUTO_COMPACTION_RETENTION=1000
74-
- ETCD_QUOTA_BACKEND_BYTES=4294967296
75-
- ETCD_SNAPSHOT_COUNT=50000
76-
volumes:
77-
- ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd
78-
command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd
79-
healthcheck:
80-
test: ["CMD", "etcdctl", "endpoint", "health"]
81-
interval: 30s
82-
timeout: 20s
83-
retries: 3
66+
# etcd:
67+
# container_name: milvus-etcd
68+
# image: quay.io/coreos/etcd:v3.5.16
69+
# environment:
70+
# - ETCD_AUTO_COMPACTION_MODE=revision
71+
# - ETCD_AUTO_COMPACTION_RETENTION=1000
72+
# - ETCD_QUOTA_BACKEND_BYTES=4294967296
73+
# - ETCD_SNAPSHOT_COUNT=50000
74+
# volumes:
75+
# - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd
76+
# command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd
77+
# healthcheck:
78+
# test: ["CMD", "etcdctl", "endpoint", "health"]
79+
# interval: 30s
80+
# timeout: 20s
81+
# retries: 3
8482

85-
minio:
86-
container_name: milvus-minio
87-
image: minio/minio:RELEASE.2023-03-20T20-16-18Z
88-
environment:
89-
MINIO_ACCESS_KEY: minioadmin
90-
MINIO_SECRET_KEY: minioadmin
91-
ports:
92-
- "9001:9001"
93-
- "9000:9000"
94-
volumes:
95-
- ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/minio:/minio_data
96-
command: minio server /minio_data --console-address ":9001"
97-
healthcheck:
98-
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
99-
interval: 30s
100-
timeout: 20s
101-
retries: 3
83+
# minio:
84+
# container_name: milvus-minio
85+
# image: minio/minio:RELEASE.2023-03-20T20-16-18Z
86+
# environment:
87+
# MINIO_ACCESS_KEY: minioadmin
88+
# MINIO_SECRET_KEY: minioadmin
89+
# ports:
90+
# - "9001:9001"
91+
# - "9000:9000"
92+
# volumes:
93+
# - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/minio:/minio_data
94+
# command: minio server /minio_data --console-address ":9001"
95+
# healthcheck:
96+
# test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
97+
# interval: 30s
98+
# timeout: 20s
99+
# retries: 3
102100

103-
standalone:
104-
container_name: milvus-standalone
105-
image: milvusdb/milvus:v2.5.4
106-
command: ["milvus", "run", "standalone"]
107-
security_opt:
108-
- seccomp:unconfined
109-
environment:
110-
ETCD_ENDPOINTS: etcd:2379
111-
MINIO_ADDRESS: minio:9000
112-
volumes:
113-
- ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus
114-
- ./milvus.yaml:/milvus/configs/milvus.yaml
115-
healthcheck:
116-
test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"]
117-
interval: 30s
118-
start_period: 90s
119-
timeout: 20s
120-
retries: 3
121-
ports:
122-
- "19530:19530"
123-
- "9091:9091"
124-
depends_on:
125-
- "etcd"
126-
- "minio"
101+
# standalone:
102+
# container_name: milvus-standalone
103+
# image: milvusdb/milvus:v2.5.4
104+
# command: ["milvus", "run", "standalone"]
105+
# security_opt:
106+
# - seccomp:unconfined
107+
# environment:
108+
# ETCD_ENDPOINTS: etcd:2379
109+
# MINIO_ADDRESS: minio:9000
110+
# volumes:
111+
# - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus
112+
# - ./milvus.yaml:/milvus/configs/milvus.yaml
113+
# healthcheck:
114+
# test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"]
115+
# interval: 30s
116+
# start_period: 90s
117+
# timeout: 20s
118+
# retries: 3
119+
# ports:
120+
# - "19530:19530"
121+
# - "9091:9091"
122+
# depends_on:
123+
# - "etcd"
124+
# - "minio"
127125

128126
volumes:
129127
sqlite-data:

0 commit comments

Comments
 (0)