-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
80 lines (64 loc) · 2.54 KB
/
Copy pathDockerfile
File metadata and controls
80 lines (64 loc) · 2.54 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
# Manager image: Kubernetes controller with bundled ONNX Runtime and Chronos-2 ONNX model.
#
# Prerequisites:
# make download-chronos-onnx # downloads models/chronos-2-onnx/model.onnx (~457MB)
#
# Build:
# make docker-build
# docker build -t controller:latest .
#
# Run locally (requires kubeconfig):
# docker run --rm \
# -v "$HOME/.kube/config:/etc/kubeconfig:ro" \
# -e KUBECONFIG=/etc/kubeconfig \
# controller:latest \
# --leader-elect
#
# Environment (forecast flags also accept CLI equivalents):
# MODEL_PATH Path to model.onnx (default: /models/chronos-2-onnx/model.onnx)
# FORECAST_MODEL_FAMILY timesfm | chronos2 (optional; auto-discovered when unset)
# ONNX_RUNTIME_LIB_PATH libonnxruntime.so (default: /opt/onnxruntime/lib/libonnxruntime.so)
# ONNX_RUNTIME_API_VERSION ORT C API version for purego (default: 23)
# syntax=docker/dockerfile:1
ARG GO_VERSION=1.26.4
ARG ONNXRUNTIME_VERSION=1.24.4
FROM golang:${GO_VERSION}-bookworm AS builder
ARG TARGETOS=linux
ARG TARGETARCH=amd64
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY api/ api/
COPY cmd/ cmd/
COPY internal/ internal/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath -ldflags="-s -w" -o /out/manager cmd/main.go
FROM debian:bookworm-slim AS ort
ARG ONNXRUNTIME_VERSION
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl \
&& curl -fsSL \
"https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}.tgz" \
| tar -xz -C /opt \
&& mv "/opt/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}" /opt/onnxruntime \
&& apt-get purge -y curl \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
FROM debian:bookworm-slim AS manager
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libstdc++6 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
COPY --from=ort /opt/onnxruntime/lib/ /opt/onnxruntime/lib/
COPY --from=builder /out/manager /manager
COPY models/chronos-2-onnx/model.onnx /models/chronos-2-onnx/model.onnx
RUN useradd -r -u 65532 -g users -d /nonexistent -s /usr/sbin/nologin manager \
&& chown -R 65532:users /models \
&& chmod -R a+rX /opt/onnxruntime
USER 65532:65532
ENV LD_LIBRARY_PATH=/opt/onnxruntime/lib \
ONNX_RUNTIME_LIB_PATH=/opt/onnxruntime/lib/libonnxruntime.so \
ONNX_RUNTIME_API_VERSION=23 \
MODEL_PATH=/models/chronos-2-onnx/model.onnx
ENTRYPOINT ["/manager"]
CMD ["--leader-elect"]