From d6b6e6814433131f1bb0b6f05b45fe3d59be9f19 Mon Sep 17 00:00:00 2001 From: Nyannyacha Date: Thu, 7 Nov 2024 20:34:22 +0900 Subject: [PATCH] fix(ci): makes share common env vars from dotenv file --- .devcontainer/Dockerfile | 18 ++++-------------- .devcontainer/install.sh | 20 ++++++++++++++++++++ .env | 1 - .github/workflows/ci.yml | 4 ++-- Dockerfile | 9 +++------ scripts/run.sh | 6 +++++- scripts/run_dind.sh | 10 ++++------ scripts/test_indefinitely.sh | 2 +- 8 files changed, 39 insertions(+), 31 deletions(-) create mode 100755 .devcontainer/install.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8f00a59fe..4b297e485 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,28 +1,18 @@ FROM mcr.microsoft.com/devcontainers/rust:dev-1-bookworm ARG TARGETPLATFORM -ARG ONNXRUNTIME_VERSION -ARG DENO_VERSION RUN apt-get update && apt-get install -y build-essential cmake libclang-dev lldb \ nodejs npm hyperfine +COPY .env /tmp/.env +COPY .devcontainer/install.sh /tmp/install.sh COPY scripts/install_onnx.sh /tmp/install_onnx.sh COPY scripts/download_models.sh /tmp/download_models.sh WORKDIR /tmp -RUN ./install_onnx.sh $ONNXRUNTIME_VERSION $TARGETPLATFORM /usr/local/bin/libonnxruntime.so -RUN ./download_models.sh -RUN mkdir -p /etc/sb_ai && cp -r /tmp/models /etc/sb_ai/models -ENV ORT_DYLIB_PATH=/usr/local/bin/libonnxruntime.so ENV SB_AI_MODELS_DIR=/etc/sb_ai/models - -# Ollama -RUN curl -fsSL https://ollama.com/install.sh | sh - -# Deno ENV DENO_INSTALL=/deno -RUN mkdir -p /deno \ - && curl -fsSL https://deno.land/install.sh | bash -s -- v$DENO_VERSION \ - && chown -R vscode /deno + +RUN /tmp/install.sh $TARGETPLATFORM diff --git a/.devcontainer/install.sh b/.devcontainer/install.sh new file mode 100755 index 000000000..440793570 --- /dev/null +++ b/.devcontainer/install.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -e + +TARGETPLATFORM=$1 + +export $(grep -v '^#' /tmp/.env | xargs) + +# ONNX Runtime +/tmp/install_onnx.sh $ONNXRUNTIME_VERSION $TARGETPLATFORM /tmp/onnxruntime +mv /tmp/onnxruntime/lib/libonnxruntime.so* /usr/lib +/tmp/download_models.sh +mkdir -p /etc/sb_ai && cp -r /tmp/models /etc/sb_ai/models + +# Ollama +curl -fsSL https://ollama.com/install.sh | sh + +# Deno +mkdir -p /deno +curl -fsSL https://deno.land/install.sh | bash -s -- v$DENO_VERSION +chown -R vscode /deno \ No newline at end of file diff --git a/.env b/.env index 6d06ccca0..ffb5ba486 100644 --- a/.env +++ b/.env @@ -1,4 +1,3 @@ -GIT_V_TAG=0.1.0 ONNXRUNTIME_VERSION=1.19.2 DENO_VERSION=1.45.2 EDGE_RUNTIME_PORT=9998 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a5a207fc..9194d7e1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ env: CARGO_NET_RETRY: 10 CARGO_TERM_COLOR: always RUSTUP_MAX_RETRIES: 10 - ORT_DYLIB_PATH: /usr/local/bin/onnxruntime/lib/libonnxruntime.so + ORT_DYLIB_PATH: /usr/local/lib/onnxruntime/lib/libonnxruntime.so jobs: cargo-fmt: @@ -54,5 +54,5 @@ jobs: with: envFile: ".env" - name: Install ONNX Runtime Library - run: ./scripts/install_onnx.sh ${{ env.ONNXRUNTIME_VERSION }} x64 /usr/local/bin/onnxruntime + run: ./scripts/install_onnx.sh ${{ env.ONNXRUNTIME_VERSION }} x64 /usr/local/lib/onnxruntime - run: ./scripts/test.sh diff --git a/Dockerfile b/Dockerfile index e58b52564..f2962b709 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,8 @@ FROM rust:1.79.0-bookworm as builder ARG TARGETPLATFORM -ARG GIT_V_TAG ARG ONNXRUNTIME_VERSION +ARG GIT_V_TAG ARG PROFILE=release ARG FEATURES @@ -36,8 +36,6 @@ RUN apt-get remove -y perl && apt-get autoremove -y COPY --from=builder /root/edge-runtime /usr/local/bin/edge-runtime COPY --from=builder /root/edge-runtime.debug /usr/local/bin/edge-runtime.debug -ENV ORT_DYLIB_PATH=/usr/local/bin/onnxruntime/lib/libonnxruntime.so - # ONNX Runtime provider # Application runtime with ONNX @@ -60,10 +58,9 @@ FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 as edge-runtime-cuda COPY --from=edge-runtime-base /usr/local/bin/edge-runtime /usr/local/bin/edge-runtime COPY --from=builder /root/edge-runtime.debug /usr/local/bin/edge-runtime.debug -COPY --from=ort-cuda /root/onnxruntime /usr/local/bin/onnxruntime +COPY --from=ort-cuda /root/onnxruntime/lib/libonnxruntime.so* /usr/lib COPY --from=preload-models /usr/src/edge-runtime/models /etc/sb_ai/models -ENV ORT_DYLIB_PATH=/usr/local/bin/onnxruntime/lib/libonnxruntime.so ENV NVIDIA_VISIBLE_DEVICES=all ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility @@ -72,7 +69,7 @@ ENTRYPOINT ["edge-runtime"] # Base FROM edge-runtime-base as edge-runtime -COPY --from=ort /root/onnxruntime /usr/local/bin/onnxruntime +COPY --from=ort /root/onnxruntime/lib/libonnxruntime.so* /usr/lib COPY --from=preload-models /usr/src/edge-runtime/models /etc/sb_ai/models ENTRYPOINT ["edge-runtime"] diff --git a/scripts/run.sh b/scripts/run.sh index a5bcf27c9..0093f0f43 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash +set -e -export $(grep -v '^#' ../.env | xargs) +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "$SCRIPT") + +export $(grep -v '^#' $SCRIPTPATH/../.env | xargs) # --features cli/tracing cargo build --features cli/tracing && \ diff --git a/scripts/run_dind.sh b/scripts/run_dind.sh index 0fe67835b..0f772b84b 100755 --- a/scripts/run_dind.sh +++ b/scripts/run_dind.sh @@ -1,23 +1,23 @@ #!/usr/bin/env bash +set -e FEATURES=cli/tracing RUST_BACKTRACE=full -PWD=$(pwd) PROFILE=${1:-dind} SCRIPT=$(readlink -f "$0") SCRIPTPATH=$(dirname "$SCRIPT") -cd "$SCRIPTPATH" +export $(grep -v '^#' $SCRIPTPATH/../.env | xargs) docker build \ -t edge_runtime \ - --env-file ../.env \ + --build-arg GIT_V_TAG=$GIT_V_TAG \ + --build-arg ONNXRUNTIME_VERSION=$ONNXRUNTIME_VERSION \ --build-arg PROFILE=$PROFILE \ --build-arg FEATURES=$FEATURES \ "$SCRIPTPATH/.." -export $(grep -v '^#' ../.env | xargs) docker run \ --privileged \ --rm \ @@ -34,5 +34,3 @@ docker run \ --main-service ./examples/main \ --event-worker ./examples/event-manager \ --static "./examples/**/*.bin" - -cd $PWD diff --git a/scripts/test_indefinitely.sh b/scripts/test_indefinitely.sh index dcdeefa66..45dd598a9 100755 --- a/scripts/test_indefinitely.sh +++ b/scripts/test_indefinitely.sh @@ -14,4 +14,4 @@ while true; do fi echo "Tests passed. Running again..." -done \ No newline at end of file +done