-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
99 lines (71 loc) · 2.27 KB
/
Dockerfile
File metadata and controls
99 lines (71 loc) · 2.27 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
# Stage 1: Frontend builder
FROM node:22-slim AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm ci
COPY frontend/ ./
RUN npm test
RUN npm run build
# Stage 2: Rust builder
FROM ubuntu:24.04 AS builder
ENV DEBIAN_FRONTEND=noninteractive
# Install build dependencies
RUN apt-get update && apt-get install -y \
curl \
build-essential \
cmake \
pkg-config \
libssl-dev \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
WORKDIR /app
# Enable hardware-specific optimizations (build machine must match runtime machine)
ENV RUSTFLAGS="-C target-cpu=native"
# Copy dependency files first to cache dependencies
COPY Cargo.toml Cargo.lock ./
# Create a dummy main.rs to build dependencies
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
RUN rm -rf src
# Copy source code
COPY . .
# Build the application
# We need to touch the main file to ensure a rebuild
RUN touch src/main.rs
RUN cargo test
RUN cargo build --release
# Find the downloaded onnxruntime library (libonnxruntime.so*)
# It is typically in target/release/build/ort-.../out/
RUN find target/release/build -name "libonnxruntime*.so*" -type f -exec cp {} /app/ \;
# Stage 3: Runtime
FROM ubuntu:24.04
WORKDIR /app
# Install runtime dependencies (OpenSSL, etc.)
RUN apt-get update && apt-get install -y \
libssl3 \
ca-certificates \
ffmpeg \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy the binary
COPY --from=builder /app/target/release/gallerynet /app/gallerynet
# Copy the ONNX Runtime library
COPY --from=builder /app/libonnxruntime*.so* /app/
# Copy assets (model)
COPY assets /app/assets
# Copy the built frontend
COPY --from=frontend-builder /app/frontend/dist /app/frontend/dist
# Copy the entrypoint script
COPY docker-entrypoint.sh /app/
RUN sed -i 's/\r$//' /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh
# Set library path so the app finds onnxruntime
ENV LD_LIBRARY_PATH=/app
# Authentication — set GALLERY_PASSWORD to enable login protection
# Leave empty or unset to run without authentication
ENV GALLERY_PASSWORD=""
EXPOSE 3000
CMD ["./docker-entrypoint.sh"]