Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

# Build artifacts
target/
docker/server/target/

# Git
.git/
.gitignore

# IDE
.idea/
.vscode/
*.swp
*.swo

# Python virtual environments
.venv/
venv/
__pycache__/

# Model files (will be downloaded or mounted)
*.onnx
*.pt
*.pth
*.safetensors

# Test images
*.jpg
*.jpeg
*.png
*.bmp
*.gif
*.webp

# Logs and temp files
*.log
runs/
assets/

# Documentation
docs/
*.md
!README.md

# CI/CD
.github/

# Cargo lock for workspace (server has its own)
Cargo.lock

# Misc
.DS_Store
*.bak

# Generated by Cargo
# will have compiled files and executables
debug
target

# tests and examples
tests
examples
63 changes: 63 additions & 0 deletions docker/Dockerfile-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

FROM ubuntu:questing-20251029 AS builder

WORKDIR /usr/src/app

# Install build dependencies + Rust (minimal set)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
build-essential \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Install latest stable Rust via rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Copy the entire project
COPY . .

# Build the CLI
# - release mode
# - no default features (disables video/GUI)
# - enable annotate + xnnpack (for saving output and CPU optimization)
RUN cargo build --release --bin ultralytics-inference --no-default-features --features annotate,xnnpack

# Runtime stage - Ubuntu 25.10 (rootless)
FROM ubuntu:questing-20251029

# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
libssl3t64 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*

# Create non-root user for security
RUN groupadd --gid 65532 inference \
&& useradd --uid 65532 --gid inference --shell /bin/bash --create-home inference

WORKDIR /app

# Copy the binary
COPY --from=builder /usr/src/app/target/release/ultralytics-inference /usr/local/bin/ultralytics-inference

# Copy ONNX Runtime shared libraries
COPY --from=builder /usr/src/app/target/release/libonnxruntime*.so* /usr/lib/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ HIGH: COPY --from=builder .../target/release/libonnxruntime*.so* /usr/lib/ assumes ONNX Runtime shared libs are present under target/release/. If the build produces no matching files (feature changes, different linking strategy, etc.), the Docker build will fail at this step. Consider making the presence of these libs explicit (e.g., copying from a known output dir/artifact) or ensuring the build always emits them.


# Download default model
RUN curl -L -o /app/yolo11n.onnx https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.onnx

# Set ownership and switch to non-root user
RUN chown -R inference:inference /app
USER inference

# Set working directory for the user
WORKDIR /app

# Set the entrypoint
ENTRYPOINT ["ultralytics-inference"]
65 changes: 65 additions & 0 deletions docker/Dockerfile-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

FROM ubuntu:questing-20251029 AS builder

# Install build dependencies + Rust (image-only)
RUN apt-get update && apt-get install -y \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ HIGH: Builder stage installs curl but not ca-certificates. rustup download uses TLS and may fail in minimal images without CA roots. Add ca-certificates to the builder stage deps to make the build more robust.

curl \
build-essential \
pkg-config \
libssl-dev \
libclang-dev \
clang \
&& rm -rf /var/lib/apt/lists/*

# Install latest stable Rust via rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /usr/src/app

# Copy the entire workspace
COPY . .

# Move to server directory and build
WORKDIR /usr/src/app/docker/server

# Build the server (image-only: annotate + xnnpack)
RUN cargo build --release

# Runtime stage - Ubuntu 25.10
FROM ubuntu:questing-20251029

RUN apt-get update && apt-get install -y \
curl \
ca-certificates \
libssl3t64 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*

# Create non-root user for security (using high UID/GID to avoid conflicts)
RUN groupadd --gid 65532 inference \
&& useradd --uid 65532 --gid inference --shell /bin/bash --create-home inference

WORKDIR /app

# Copy the server binary
COPY --from=builder /usr/src/app/docker/server/target/release/ultralytics-inference-server /usr/local/bin/ultralytics-inference-server

# Copy ONNX Runtime shared libraries
COPY --from=builder /usr/src/app/docker/server/target/release/libonnxruntime*.so* /usr/lib/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ HIGH: Same concern as the CLI image: copying libonnxruntime*.so* from docker/server/target/release/ will fail the Docker build if no files match. It would be safer to copy from a deterministic location or ensure the server build step always produces these shared libs.


# Download default model
RUN curl -L -o /app/yolo11n.onnx https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.onnx

# Set ownership and switch to non-root user
RUN chown -R inference:inference /app
USER inference

# Set working directory
WORKDIR /app

# Expose the port (3000 as per main.rs)
EXPOSE 3000

CMD ["ultralytics-inference-server"]
33 changes: 33 additions & 0 deletions docker/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

[package]
name = "ultralytics-inference-server"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = { version = "0.8.8", features = ["multipart"] }
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
image = "0.25"
tracing = "0.1"
tracing-subscriber = "0.3"

# OpenAPI documentation
utoipa = { version = "5", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "9", features = ["axum"] }

# Local dependency to the main inference library
ultralytics-inference = { path = "../../", default-features = false, features = [
"annotate",
"xnnpack",
] }

[features]
default = []
# Video support (adds FFmpeg dependency - larger image)
video = ["ultralytics-inference/video"]
# GPU acceleration features (passed through to ultralytics-inference)
cuda = ["ultralytics-inference/cuda"]
tensorrt = ["ultralytics-inference/tensorrt"]
nvidia = ["cuda", "tensorrt"]
Loading
Loading