Skip to content

Commit af44e97

Browse files
committed
update: Dockerfile
1 parent eddba8c commit af44e97

File tree

2 files changed

+78
-25
lines changed

2 files changed

+78
-25
lines changed

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# .dockerignore
2+
.git
3+
.gitignore
4+
**/__pycache__/
5+
**/*.pyc
6+
build/
7+
dist/
8+
*.egg-info/
9+
*.whl
10+
*.tar.gz
11+
tests/
12+
notebooks/
13+
data/
14+
examples/
15+
.tmp/
16+
.DS_Store
17+
sandbox/
18+
.pytest_cache/
19+
.ruff_cache/

Dockerfile

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,79 @@
1-
# docker build -t ghcr.io/pyprophet/pyprophet:3.0.2 .
1+
# docker build --no-cache -t ghcr.io/pyprophet/pyprophet:3.0.2 .
22
# docker push ghcr.io/pyprophet/pyprophet:3.0.2
33

4-
# PyProphet Dockerfile (Ubuntu 24.04 + venv)
5-
FROM ubuntu:24.04
6-
7-
ENV DEBIAN_FRONTEND=noninteractive \
8-
PYTHONUNBUFFERED=1
4+
# ---------- builder: create venv and install ----------
5+
FROM ubuntu:24.04 AS builder
6+
ENV DEBIAN_FRONTEND=noninteractive PYTHONUNBUFFERED=1
97

8+
# System Python + toolchain for building wheels (builder only)
109
RUN apt-get update && apt-get install -y --no-install-recommends \
1110
ca-certificates python3 python3-pip python3-dev python3-venv \
12-
build-essential git \
13-
# --- runtime libs needed by pyopenms ---
14-
libglib2.0-0 \
15-
libgomp1 \
16-
# these are rarely needed, but harmless and useful if pyopenms/OpenMS is present
17-
libxerces-c3.2 \
18-
zlib1g \
19-
libbz2-1.0 \
20-
libsqlite3-0 \
21-
&& rm -rf /var/lib/apt/lists/*
22-
23-
# venv
11+
build-essential git curl && \
12+
rm -rf /var/lib/apt/lists/*
13+
14+
# Virtualenv (avoid PEP 668 issues)
2415
RUN python3 -m venv /opt/venv
2516
ENV VIRTUAL_ENV=/opt/venv
2617
ENV PATH="/opt/venv/bin:${PATH}"
2718

28-
# toolchain (pins optional)
19+
# Upgrade pip and install toolchain/runtime deps
20+
# Pins chosen to have manylinux wheels for Python 3.12
2921
RUN python -m pip install --no-cache-dir --upgrade pip && \
30-
python -m pip install --no-cache-dir "numpy==1.26.4" "cython==0.29.36" duckdb seaborn psutil
22+
python -m pip install --no-cache-dir --prefer-binary \
23+
"numpy==1.26.4" "cython==0.29.36" "scipy==1.12.*" \
24+
duckdb seaborn psutil
25+
26+
# Bring in the PyProphet source tree
27+
WORKDIR /src
28+
COPY pyproject.toml setup.py requirements.txt README* LICENSE* ./
29+
COPY pyprophet ./pyprophet
30+
31+
# Ensure setuptools/wheel are present (and avoid latest setuptools breaking flags)
32+
RUN python -m pip install --no-cache-dir "setuptools<75" wheel
3133

32-
# install PyProphet
33-
ADD . /pyprophet
34-
WORKDIR /pyprophet
35-
RUN pip install .
34+
# --- force-build the Cython extension before installing ---
35+
# This compiles pyprophet/scoring/_optimized.pyx into a .so in-place.
36+
RUN python setup.py build_ext --inplace
37+
38+
# Install PyProphet into the venv (reuse prebuilt wheels, no isolation)
39+
RUN pip install --no-cache-dir --no-build-isolation .
40+
41+
# Verify the optimized module is importable (fail-fast if not)
42+
RUN python - <<'PY'
43+
import importlib, sys
44+
m = importlib.import_module('pyprophet.scoring._optimized')
45+
print("Found optimized extension:", m.__file__)
46+
PY
3647

37-
# warm up duckdb sqlite_scanner (optional)
48+
# Pre-install DuckDB sqlite_scanner extension (as requested)
3849
RUN python - <<'PY'
3950
import duckdb
4051
con = duckdb.connect()
4152
con.execute("INSTALL 'sqlite_scanner'")
4253
con.execute("LOAD 'sqlite_scanner'")
54+
print("duckdb sqlite_scanner installed & loadable")
4355
PY
4456

57+
# Optional: trim pyc/caches
58+
RUN python -m compileall -q "${VIRTUAL_ENV}" || true && \
59+
find "${VIRTUAL_ENV}" -type d -name "__pycache__" -prune -exec rm -rf {} + && \
60+
find "${VIRTUAL_ENV}" -type f -name "*.pyc" -delete
61+
62+
# ---------- runtime: only the venv + runtime libs ----------
63+
FROM ubuntu:24.04 AS runtime
64+
ENV DEBIAN_FRONTEND=noninteractive PYTHONUNBUFFERED=1
65+
66+
# Minimal native libs needed by pyopenms/pyprophet (safe superset)
67+
RUN apt-get update && apt-get install -y --no-install-recommends \
68+
ca-certificates python3 \
69+
libglib2.0-0 libgomp1 \
70+
libxerces-c3.2 zlib1g libbz2-1.0 libsqlite3-0 \
71+
&& rm -rf /var/lib/apt/lists/*
72+
73+
# Bring the venv
74+
COPY --from=builder /opt/venv /opt/venv
75+
ENV VIRTUAL_ENV=/opt/venv
76+
ENV PATH="/opt/venv/bin:${PATH}"
77+
78+
# Default workdir
4579
WORKDIR /data/

0 commit comments

Comments
 (0)