-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
241 lines (219 loc) · 8.66 KB
/
Copy pathDockerfile
File metadata and controls
241 lines (219 loc) · 8.66 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# syntax=docker/dockerfile:1
ARG ORT_VERSION=1.26.0
ARG VIPS_VERSION=8.18.2
############################################################
# onnxruntime download stage
############################################################
FROM debian:bookworm-slim AS dl-base
RUN apt-get update && \
apt-get install -y --no-install-recommends curl ca-certificates && \
rm -rf /var/lib/apt/lists/*
WORKDIR /opt
FROM dl-base AS ort-cpu
ARG ORT_VERSION
RUN curl -fL https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-${ORT_VERSION}.tgz | tar xz && \
mv onnxruntime-linux-x64-${ORT_VERSION} onnxruntime
FROM dl-base AS ort-cuda12
ARG ORT_VERSION
RUN curl -fL https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-${ORT_VERSION}.tgz | tar xz && \
mv onnxruntime-linux-x64-gpu-${ORT_VERSION} onnxruntime
FROM dl-base AS ort-cuda13
ARG ORT_VERSION
RUN curl -fL https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu_cuda13-${ORT_VERSION}.tgz | tar xz && \
mv onnxruntime-linux-x64-gpu-${ORT_VERSION} onnxruntime
############################################################
# builders
############################################################
FROM rust:1.96-bookworm AS builder-base
WORKDIR /app
COPY . .
ENV SQLX_OFFLINE=true
FROM builder-base AS embed-builder
RUN cargo build -p embed --release
FROM builder-base AS search-builder
RUN apt-get update && \
apt-get install -y --no-install-recommends cmake && \
rm -rf /var/lib/apt/lists/*
RUN rustup target add wasm32-unknown-unknown && \
curl -fL --proto '=https' --tlsv1.2 https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash && \
cargo binstall --locked --no-confirm cargo-leptos
RUN cargo leptos build --release
RUN cargo build -p gateway -F validate-jwt --release
FROM debian:bookworm-slim AS vips-builder
ARG VIPS_VERSION
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential ninja-build meson pkg-config wget ca-certificates \
libglib2.0-dev libexpat1-dev \
libjpeg62-turbo-dev libpng-dev libwebp-dev libtiff-dev \
libgif-dev libexif-dev librsvg2-dev libheif-dev \
&& rm -rf /var/lib/apt/lists/*
RUN wget -q https://github.com/libvips/libvips/releases/download/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.xz \
&& tar xf vips-${VIPS_VERSION}.tar.xz \
&& cd vips-${VIPS_VERSION} \
&& meson setup build --prefix=/usr/local --buildtype=release \
&& ninja -C build \
&& ninja -C build install \
&& ldconfig
FROM rust:1.96-bookworm AS img2webp-builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config clang \
libglib2.0-dev libjpeg62-turbo-dev libpng-dev libwebp-dev \
libtiff-dev libgif-dev libexif-dev librsvg2-dev libheif1 \
&& rm -rf /var/lib/apt/lists/*
COPY --from=vips-builder /usr/local /usr/local
RUN ldconfig
ENV PKG_CONFIG_PATH=/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig
ENV RUSTFLAGS="-L /usr/local/lib/x86_64-linux-gnu -L /usr/local/lib"
WORKDIR /app
COPY . .
RUN cargo build -p img2webp --release
############################################################
# embed runtimes
############################################################
FROM debian:bookworm-slim AS embed-cpu
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=ort-cpu /opt/onnxruntime /opt/onnxruntime
COPY --from=embed-builder /app/target/release/embed /usr/local/bin/embed
WORKDIR /app
RUN useradd -r -u 10001 appuser
USER appuser
ENV ORT_DYLIB_PATH=/opt/onnxruntime/lib/libonnxruntime.so
ENTRYPOINT ["embed"]
FROM nvidia/cuda:12.9.2-cudnn-runtime-ubuntu24.04 AS embed-cuda12
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates cuda-compat-12-9 && \
rm -rf /var/lib/apt/lists/*
COPY --from=ort-cuda12 /opt/onnxruntime /opt/onnxruntime
COPY --from=embed-builder /app/target/release/embed /usr/local/bin/embed
WORKDIR /app
RUN useradd -r -u 10001 appuser
USER appuser
ENV LD_LIBRARY_PATH=/usr/local/cuda/compat:${LD_LIBRARY_PATH} \
ORT_DYLIB_PATH=/opt/onnxruntime/lib/libonnxruntime.so
ENTRYPOINT ["embed"]
FROM nvidia/cuda:13.3.0-cudnn-runtime-ubuntu24.04 AS embed-cuda13
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=ort-cuda13 /opt/onnxruntime /opt/onnxruntime
COPY --from=embed-builder /app/target/release/embed /usr/local/bin/embed
WORKDIR /app
RUN useradd -r -u 10001 appuser
USER appuser
ENV ORT_DYLIB_PATH=/opt/onnxruntime/lib/libonnxruntime.so
ENTRYPOINT ["embed"]
############################################################
# search runtimes
############################################################
FROM debian:bookworm-slim AS search-cpu
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=ort-cpu /opt/onnxruntime /opt/onnxruntime
COPY --from=search-builder /app/target/release/server /usr/local/bin/server
COPY --from=search-builder /app/target/release/gateway /usr/local/bin/gateway
COPY --from=search-builder /app/target/site /site
COPY --from=search-builder /app/target/release/hash.txt /hash.txt
COPY <<'EOF' /usr/local/bin/start.sh
#!/usr/bin/env bash
set -uo pipefail
trap 'kill -TERM $(jobs -p) 2>/dev/null' TERM INT
server "$@" &
gateway &
wait -n # 任一进程退出
code=$?
kill -TERM $(jobs -p) 2>/dev/null
wait
exit $code
EOF
RUN chmod +x /usr/local/bin/start.sh
WORKDIR /app
RUN useradd -r -u 10001 appuser
USER appuser
ENV ORT_DYLIB_PATH=/opt/onnxruntime/lib/libonnxruntime.so \
LEPTOS_SITE_ROOT=/site \
LEPTOS_HASH_FILES=true \
LEPTOS_HASH_FILE_NAME=/hash.txt
ENTRYPOINT ["start.sh"]
FROM nvidia/cuda:12.9.2-cudnn-runtime-ubuntu24.04 AS search-cuda12
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates cuda-compat-12-9 && \
rm -rf /var/lib/apt/lists/*
COPY --from=ort-cuda12 /opt/onnxruntime /opt/onnxruntime
COPY --from=search-builder /app/target/release/server /usr/local/bin/server
COPY --from=search-builder /app/target/release/gateway /usr/local/bin/gateway
COPY --from=search-builder /app/target/site /site
COPY --from=search-builder /app/target/release/hash.txt /hash.txt
COPY <<'EOF' /usr/local/bin/start.sh
#!/usr/bin/env bash
set -uo pipefail
trap 'kill -TERM $(jobs -p) 2>/dev/null' TERM INT
server "$@" &
gateway &
wait -n # any process exits
code=$?
kill -TERM $(jobs -p) 2>/dev/null
wait
exit $code
EOF
RUN chmod +x /usr/local/bin/start.sh
WORKDIR /app
RUN useradd -r -u 10001 appuser
USER appuser
ENV ORT_DYLIB_PATH=/opt/onnxruntime/lib/libonnxruntime.so \
LEPTOS_SITE_ROOT=/site \
LEPTOS_HASH_FILES=true \
LEPTOS_HASH_FILE_NAME=/hash.txt
ENTRYPOINT ["start.sh"]
FROM nvidia/cuda:13.3.0-cudnn-runtime-ubuntu24.04 AS search-cuda13
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=ort-cuda13 /opt/onnxruntime /opt/onnxruntime
COPY --from=search-builder /app/target/release/server /usr/local/bin/server
COPY --from=search-builder /app/target/release/gateway /usr/local/bin/gateway
COPY --from=search-builder /app/target/site /site
COPY --from=search-builder /app/target/release/hash.txt /hash.txt
COPY <<'EOF' /usr/local/bin/start.sh
#!/usr/bin/env bash
set -uo pipefail
trap 'kill -TERM $(jobs -p) 2>/dev/null' TERM INT
server "$@" &
gateway &
wait -n # any process exits
code=$?
kill -TERM $(jobs -p) 2>/dev/null
wait
exit $code
EOF
RUN chmod +x /usr/local/bin/start.sh
WORKDIR /app
RUN useradd -r -u 10001 appuser
USER appuser
ENV ORT_DYLIB_PATH=/opt/onnxruntime/lib/libonnxruntime.so \
LEPTOS_SITE_ROOT=/site \
LEPTOS_HASH_FILES=true \
LEPTOS_HASH_FILE_NAME=/hash.txt
ENTRYPOINT ["start.sh"]
############################################################
# img2webp runtimes
############################################################
FROM debian:bookworm-slim AS img2webp
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libglib2.0-0 libexpat1 \
libjpeg62-turbo libpng16-16 libwebp7 libwebpmux3 libwebpdemux2 \
libtiff6 libgif7 libexif12 librsvg2-2 libheif1 \
&& rm -rf /var/lib/apt/lists/*
COPY --from=vips-builder /usr/local/lib /usr/local/lib
RUN ldconfig
COPY --from=img2webp-builder /app/target/release/img2webp /usr/local/bin/img2webp
WORKDIR /app
RUN useradd -r -u 10001 appuser
USER appuser
ENTRYPOINT ["img2webp"]