-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: β¨ Add Dockerfiles and configuration for inference server and CLI #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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/ | ||
|
|
||
| # 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"] | ||
| 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 \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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/ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| # 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"] | ||
| 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"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COPY --from=builder .../target/release/libonnxruntime*.so* /usr/lib/assumes ONNX Runtime shared libs are present undertarget/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.