-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (46 loc) Β· 2.38 KB
/
Copy pathDockerfile
File metadata and controls
63 lines (46 loc) Β· 2.38 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
# Multi-stage build β small final image, single layer for the runtime.
# Targets: linux/amd64 (default), linux/arm64 (built in CI via buildx).
#
# docker build -t kairu .
# docker run --rm -p 8000:8000 kairu serve --host 0.0.0.0 --port 8000
ARG PYTHON_VERSION=3.11
# βββ builder ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
FROM python:${PYTHON_VERSION}-slim AS builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /build
# Install build deps. We do not need apt packages β kairu is pure Python +
# numpy wheels β but we keep this stage isolated so the runtime image stays slim.
RUN pip install --upgrade pip wheel build
COPY pyproject.toml README.md ./
COPY kairu ./kairu
# Build the wheel into /build/dist
RUN python -m build --wheel --outdir /build/dist
# βββ runtime ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
FROM python:${PYTHON_VERSION}-slim AS runtime
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PORT=8000
# Non-root user. The container exposes HTTP only β no need for root.
RUN groupadd --system --gid 1001 kairu \
&& useradd --system --gid kairu --uid 1001 --create-home --shell /usr/sbin/nologin kairu
WORKDIR /app
COPY --from=builder /build/dist/*.whl /tmp/
# Server + Redis extras pulled in (the redis client is small and the entrypoint
# accepts --redis URL flags β having the lib available is a strict win).
RUN pip install --no-cache-dir /tmp/kairu-*.whl 'kairu[server,redis]' \
&& rm /tmp/kairu-*.whl \
&& python -c "import kairu; print('kairu', kairu.__version__)"
USER kairu
EXPOSE 8000
# Default: serve mock model on 0.0.0.0:8000. Override with `docker run` args.
ENTRYPOINT ["kairu"]
CMD ["serve", "--host", "0.0.0.0", "--port", "8000", "--model", "mock"]
HEALTHCHECK --interval=15s --timeout=3s --start-period=5s --retries=3 \
CMD python -c "import urllib.request,sys; \
sys.exit(0) if urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=2).status == 200 else sys.exit(1)" \
|| exit 1