-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (57 loc) · 2.41 KB
/
Dockerfile
File metadata and controls
73 lines (57 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Multi-stage Dockerfile for ZnDraw - Optimized for minimal size
#
# Stage 1: Build wheel with correct version
# - SETUPTOOLS_SCM_PRETEND_VERSION overrides dirty version detection
# - hatch_build.py builds frontend during wheel build
#
# Stage 2: Minimal runtime - just pip install the wheel
# ============================================================================
# Stage 1: Build wheel with uv (includes frontend build via hatch_build.py)
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
# Version override for Docker builds (avoids dirty version detection)
# See: https://github.com/pypa/setuptools-scm/issues/77
ARG SETUPTOOLS_SCM_PRETEND_VERSION
ENV SETUPTOOLS_SCM_PRETEND_VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION}
# Install git (for hatch-vcs fallback) and bun (for frontend build)
RUN apt-get update && \
apt-get install -y --no-install-recommends git curl unzip && \
curl -fsSL https://bun.sh/install | bash && \
rm -rf /var/lib/apt/lists/*
ENV PATH="/root/.bun/bin:$PATH"
WORKDIR /build
# Copy source and build wheel
COPY . /src
RUN --mount=type=cache,target=/root/.cache/uv \
cd /src && uv build --wheel --out-dir /build/dist
# ============================================================================
# Stage 2: Minimal runtime image
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS runtime
# Install only runtime dependencies for RDKit Draw module
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libxrender1 \
libxext6 \
libx11-6 \
libexpat1 \
libfreetype6 \
libpng16-16 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create non-root user
RUN groupadd --system --gid 999 appuser && \
useradd --system --gid 999 --uid 999 --create-home appuser && \
mkdir -p /app/data /tmp/zndraw_uploads && \
chown -R appuser:appuser /app /tmp/zndraw_uploads
WORKDIR /app
# Copy wheel and install with all extras
COPY --from=builder /build/dist/*.whl /tmp/
RUN WHEEL=$(ls /tmp/*.whl) && uv pip install --system --no-cache-dir --prerelease explicit "${WHEEL}[full,postgres,mongodb]" && rm /tmp/*.whl
# Set environment
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
ZNDRAW_HOST=0.0.0.0
USER appuser
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000').read()" || exit 1
CMD ["zndraw", "--no-browser"]