Skip to content

Commit

Permalink
Add docker image for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
xnorpx committed Jan 4, 2025
1 parent 4b6da0b commit c454ce9
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 12 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build and Publish Docker Image

on:
workflow_run:
workflows: ["release"]
types:
- completed

jobs:
build:
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable

- name: Build blue_onyx binaries
run: |
cargo build --release --bin blue_onyx
cargo build --release --bin blue_onyx_download_models
- name: Download models
run: |
./target/release/blue_onyx_download_models /tmp/models
./target/release/blue_onyx_download_models /tmp/models custom-model
- name: Prepare Docker context
run: |
mkdir docker-context
cp ./target/release/blue_onyx docker-context/
cp ./target/release/libonnxruntime.so docker-context/
cp -r /tmp/models docker-context/models
cp ./Dockerfile docker-context/
- name: Get blue_onyx version
id: get_version
run: |
VERSION=$(./target/release/blue_onyx --version | awk '{print $2}')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: docker-context
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/blue_onyx:latest
ghcr.io/${{ github.repository_owner }}/blue_onyx:${{ env.VERSION }}
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
"version": "${{ env.VERSION }}",
"windows": "blue_onyx-${{ env.VERSION }}-win.zip",
"windows_sha256": "blue_onyx-${{ env.VERSION }}-win.zip.sha256"
"linux": "blue_onyx-${{ env.VERSION }}-linux.zip",
"linux_sha256": "blue_onyx-${{ env.VERSION }}-linux.zip.sha256"
}
EOF
- name: Upload version.json
Expand Down Expand Up @@ -88,6 +90,9 @@ jobs:
- build: win
os: windows-latest
rust: stable
- build: linux
os: linux-latest
rust: stable

steps:
- name: Checkout repository
Expand All @@ -107,7 +112,7 @@ jobs:
if [ "${{ matrix.os }}" = "windows-latest" ]; then
BIN="target/release/blue_onyx.exe target/release/onnxruntime.dll target/release/DirectML.dll target/release/test_blue_onyx.exe target/release/blue_onyx_benchmark.exe target/release/blue_onyx_service.exe target/release/blue_onyx_download_models.exe"
else
BIN="target/release/blue_onyx"
BIN="target/release/blue_onyx target/release/libonnxruntime.so target/release/test_blue_onyx target/release/blue_onyx_benchmark target/release/blue_onyx_download_models"
fi
echo "BIN=$BIN" >> $GITHUB_ENV
Expand Down
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM debian:trixie-slim

LABEL maintainer="[email protected]"
LABEL description="Blue Onyx docker container"

ENV TARGET_FOLDER=/models

# Install dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends openssl && \
rm -rf /var/lib/apt/lists/*

# Create non-root user
RUN useradd --create-home --no-log-init blueonyx

# Set working directory
WORKDIR /app

# Copy application files and set ownership
COPY --chown=blueonyx:blueonyx blue_onyx libonnxruntime.so ./

# Copy model files and set ownership
COPY --chown=blueonyx:blueonyx models/* ./

# Switch to non-root user
USER blueonyx

# Expose port
EXPOSE 32168

# Define entrypoint
ENTRYPOINT ["./blue_onyx"]
20 changes: 18 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,28 @@ pub struct Cli {
/// Force using CPU for inference
#[clap(long, default_value_t = false)]
pub force_cpu: bool,
/// Intra thread parallelism max is cpu cores - 1
/// Intra thread parallelism max is CPU cores - 1.
/// On Windows, you can use high thread counts, but if you use too high
/// thread count on Linux, you will get a BIG performance hit.
/// So default is 1, then you can increase it if you want to test the
/// performance.
#[cfg(target_os = "windows")]
#[clap(long, default_value_t = 192)]
pub intra_threads: usize,
/// Inter thread parallelism max is cpu cores - 1
#[cfg(not(target_os = "windows"))]
#[clap(long, default_value_t = 2)]
pub intra_threads: usize,
/// Inter thread parallelism max is CPU cores - 1.
/// On Windows, you can use high thread counts, but if you use too high
/// thread count on Linux, you will get a BIG performance hit.
/// So default is 2, then you can increase it if you want to test the
/// performance.
#[cfg(target_os = "windows")]
#[clap(long, default_value_t = 192)]
pub inter_threads: usize,
#[cfg(not(target_os = "windows"))]
#[clap(long, default_value_t = 2)]
pub inter_threads: usize,
/// Optional path to save the processed images
#[clap(long)]
pub save_image_path: Option<PathBuf>,
Expand Down
25 changes: 16 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,24 @@ pub fn get_object_classes(yaml_file: Option<PathBuf>) -> anyhow::Result<Vec<Stri
}

pub fn direct_ml_available() -> bool {
if let Ok(exe_path) = std::env::current_exe() {
let exe_dir = exe_path.parent().unwrap();
let direct_ml_path = exe_dir.join("DirectML.dll");
let direct_ml_available = direct_ml_path.exists();
if !direct_ml_available {
warn!("DirectML.dll not found in the same directory as the executable");
#[cfg(not(windows))]
{
false
}
#[cfg(windows)]
{
if let Ok(exe_path) = std::env::current_exe() {
let exe_dir = exe_path.parent().unwrap();
let direct_ml_path = exe_dir.join("DirectML.dll");
let direct_ml_available = direct_ml_path.exists();
if !direct_ml_available {
warn!("DirectML.dll not found in the same directory as the executable");
}
return direct_ml_available;
}
return direct_ml_available;
warn!("Failed to get current executable path");
false
}
warn!("Failed to get current executable path");
false
}

pub fn init_logging(
Expand Down

0 comments on commit c454ce9

Please sign in to comment.