diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..5a69859 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 71e4004..115ead4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -88,6 +90,9 @@ jobs: - build: win os: windows-latest rust: stable + - build: linux + os: linux-latest + rust: stable steps: - name: Checkout repository @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f7a879a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM debian:trixie-slim + +LABEL maintainer="xnorpx@outlook.com" +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"] diff --git a/src/cli.rs b/src/cli.rs index 1e1d460..7691c48 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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, diff --git a/src/lib.rs b/src/lib.rs index 2d169e0..9e21334 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,17 +100,24 @@ pub fn get_object_classes(yaml_file: Option) -> anyhow::Result 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(