-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.infer
More file actions
152 lines (127 loc) · 4.85 KB
/
Copy pathDockerfile.infer
File metadata and controls
152 lines (127 loc) · 4.85 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# ==============================================================================
# Nikola Inference — Lightweight Docker Image
# v0.2.5: Inference-only runner (no autonomy/training/SIE stack)
#
# GPU build (default):
# docker build -f Dockerfile.infer -t nikola-infer:latest .
# docker run --gpus all -p 8080:8080 nikola-infer:latest --serve
#
# CPU-only build:
# docker build -f Dockerfile.infer \
# --build-arg BUILDER_IMAGE=ubuntu:24.04 \
# --build-arg RUNTIME_IMAGE=ubuntu:24.04 \
# --build-arg CUDA_ARCH="" \
# -t nikola-infer:cpu .
#
# ~60% smaller than the full image (no ZMQ, no training, no security stack).
# ==============================================================================
ARG CUDA_VERSION=12.6.3
ARG UBUNTU_VERSION=24.04
ARG ORT_VERSION=1.21.1
ARG CMAKE_BUILD_TYPE=Release
ARG CUDA_ARCH=86
ARG BUILDER_IMAGE=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION}
ARG RUNTIME_IMAGE=nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION}
# ==============================================================================
# Stage 1: Builder
# ==============================================================================
FROM ${BUILDER_IMAGE} AS builder
ARG CMAKE_BUILD_TYPE
ARG ORT_VERSION
ARG CUDA_ARCH
ARG TARGETARCH
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
ninja-build \
git \
pkg-config \
libeigen3-dev \
libprotobuf-dev \
protobuf-compiler \
libzmq3-dev \
libczmq-dev \
libcurl4-openssl-dev \
liblmdb-dev \
libsodium-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# cppzmq (required by nikola_core)
RUN git clone --depth 1 --branch v4.10.0 \
https://github.com/zeromq/cppzmq.git /tmp/cppzmq && \
cd /tmp/cppzmq && mkdir build && cd build && \
cmake .. -DCPPZMQ_BUILD_TESTS=OFF -G Ninja && \
ninja install && rm -rf /tmp/cppzmq
# Catch2 v3
RUN git clone --depth 1 --branch v3.4.0 \
https://github.com/catchorg/Catch2.git /tmp/catch2 && \
cd /tmp/catch2 && mkdir build && cd build && \
cmake .. -DBUILD_TESTING=OFF -G Ninja && \
ninja install && rm -rf /tmp/catch2
# ONNX Runtime
RUN mkdir -p /opt/onnxruntime && \
apt-get update && apt-get install -y --no-install-recommends wget && \
wget -q "https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-${ORT_VERSION}.tgz" \
-O /tmp/ort.tgz && \
tar xzf /tmp/ort.tgz -C /opt/onnxruntime --strip-components=1 && \
rm /tmp/ort.tgz && \
rm -rf /var/lib/apt/lists/*
WORKDIR /build/nikola
COPY . .
# Build — only nikola-infer target (faster build, smaller binary)
RUN mkdir -p build && cd build && \
CMAKE_ARGS="-G Ninja \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-DORT_ROOT=/opt/onnxruntime \
-DNIKOLA_ORT_MODEL_PATH=/build/nikola/models/bert-tiny-onnx/model.onnx \
-DNIKOLA_ORT_TOKENIZER_PATH=/build/nikola/models/bert-tiny-onnx \
-DNIKOLA_BUILD_TESTS=OFF" && \
if [ -n "${CUDA_ARCH}" ]; then \
CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCH}"; \
fi && \
cmake .. ${CMAKE_ARGS} && \
ninja nikola_infer -j$(nproc)
# ==============================================================================
# Stage 2: Runtime — inference only
# ==============================================================================
FROM ${RUNTIME_IMAGE} AS runtime
ENV DEBIAN_FRONTEND=noninteractive
# Minimal runtime deps (no ZMQ — inference server uses raw HTTP)
RUN apt-get update && apt-get install -y --no-install-recommends \
libprotobuf-lite32t64 \
libzmq5 \
libcurl4t64 \
liblmdb0 \
libsodium23 \
libssl3t64 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# Non-root user
RUN groupadd -r nikola && useradd -r -g nikola -m -s /bin/bash nikola
# Directory structure
RUN mkdir -p /opt/nikola/bin \
/opt/nikola/lib \
/opt/nikola/models \
/data/nikola/checkpoints && \
chown -R nikola:nikola /data/nikola
# Copy only the inference binary
COPY --from=builder /build/nikola/build/nikola-infer /opt/nikola/bin/
# Copy ONNX Runtime shared libs
COPY --from=builder /opt/onnxruntime/lib/libonnxruntime*.so* /opt/nikola/lib/
# Copy BERT-tiny model
COPY --from=builder /build/nikola/models/ /opt/nikola/models/
# Environment
ENV LD_LIBRARY_PATH="/opt/nikola/lib:${LD_LIBRARY_PATH}"
ENV PATH="/opt/nikola/bin:${PATH}"
ENV NIKOLA_ORT_MODEL_PATH="/opt/nikola/models/bert-tiny-onnx/model.onnx"
ENV NIKOLA_ORT_TOKENIZER_PATH="/opt/nikola/models/bert-tiny-onnx"
# HTTP API port
EXPOSE 8080
# Health check via HTTP endpoint
HEALTHCHECK --interval=10s --timeout=3s --retries=3 --start-period=15s \
CMD curl -sf http://localhost:8080/v1/health || exit 1
USER nikola
WORKDIR /data/nikola
ENTRYPOINT ["nikola-infer"]
CMD ["--serve", "--port", "8080"]