From 4af5b62891892bc3ad081e89516dcd0ea3533de7 Mon Sep 17 00:00:00 2001 From: Hien To Date: Wed, 25 Sep 2024 09:45:33 +0700 Subject: [PATCH 1/3] Linux add local installer --- .github/workflows/beta-build.yml | 1 + .github/workflows/nightly-build.yml | 1 + .github/workflows/stable-build.yml | 1 + .../workflows/template-build-linux-x64.yml | 65 +++++++++++++++++-- .github/workflows/template-noti-discord.yaml | 4 +- engine/templates/linux/create_deb_local.sh | 38 +++++++++++ engine/templates/linux/postinst_local | 6 ++ 7 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 engine/templates/linux/create_deb_local.sh create mode 100644 engine/templates/linux/postinst_local diff --git a/.github/workflows/beta-build.yml b/.github/workflows/beta-build.yml index 928e76db0..07f95f2ec 100644 --- a/.github/workflows/beta-build.yml +++ b/.github/workflows/beta-build.yml @@ -92,6 +92,7 @@ jobs: cmake-flags: "-DCORTEX_VARIANT=beta -DCORTEX_CPP_VERSION='v${{ needs.get-update-version.outputs.new_version }}' -DCMAKE_TOOLCHAIN_FILE=/home/runner/actions-runner/_work/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake" channel: beta upload_url: ${{ needs.create-draft-release.outputs.upload_url }} + cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} update_release_draft: needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64] diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 85ce2c27a..5b66bc132 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -98,6 +98,7 @@ jobs: runs-on: ubuntu-20-04 cmake-flags: "-DCORTEX_VARIANT=nightly -DCORTEX_CPP_VERSION='v${{ needs.get-update-version.outputs.new_version }}' -DCMAKE_TOOLCHAIN_FILE=/home/runner/actions-runner/_work/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake" channel: nightly + cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} update-latest-version: runs-on: ubuntu-latest diff --git a/.github/workflows/stable-build.yml b/.github/workflows/stable-build.yml index a54f6ad41..6e477cb6a 100644 --- a/.github/workflows/stable-build.yml +++ b/.github/workflows/stable-build.yml @@ -92,6 +92,7 @@ jobs: cmake-flags: "-DCORTEX_VARIANT=prod -DCORTEX_CPP_VERSION='v${{ needs.get-update-version.outputs.new_version }}' -DCMAKE_TOOLCHAIN_FILE=/home/runner/actions-runner/_work/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake" channel: stable upload_url: ${{ needs.create-draft-release.outputs.upload_url }} + cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} update_release_draft: needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64] diff --git a/.github/workflows/template-build-linux-x64.yml b/.github/workflows/template-build-linux-x64.yml index 1c82591ca..9cefe447e 100644 --- a/.github/workflows/template-build-linux-x64.yml +++ b/.github/workflows/template-build-linux-x64.yml @@ -44,6 +44,11 @@ on: type: string default: 'nightly' description: 'The channel to use for this job' + cortex-llamacpp-version: + required: true + type: string + default: '0.0.0' + description: 'The version of cortex-llamacpp to use for this job' secrets: DELTA_AWS_S3_BUCKET_NAME: required: false @@ -128,11 +133,41 @@ jobs: cd engine make pre-package DESTINATION_BINARY_NAME="${{ steps.set-output-params.outputs.destination_binary_name }}" - - name: Build Installers + - name: Build network Installers shell: bash run: | cd engine make build-installer PACKAGE_NAME="${{ steps.set-output-params.outputs.package_name }}" SOURCE_BINARY_PATH="../../cortex/${{ steps.set-output-params.outputs.destination_binary_name }}" VERSION=${{ inputs.new_version }} DESTINATION_BINARY_NAME="${{ steps.set-output-params.outputs.destination_binary_name }}" DATA_FOLDER_NAME="${{ steps.set-output-params.outputs.data_folder_name }}" CONFIGURATION_FILE_NAME="${{ steps.set-output-params.outputs.configuration_file_name }}" UNINSTALLER_FILE_NAME="${{ steps.set-output-params.outputs.uninstaller_file_name }}" + mv ${{ steps.set-output-params.outputs.package_name }}.deb ${{ steps.set-output-params.outputs.package_name }}-network.deb + + - name: Build local Installers + run: | + mkdir -p engine/templates/linux/dependencies + cd engine/templates/linux/dependencies + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-avx-cuda-11-7.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-avx-cuda-12-0.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-avx.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-avx2-cuda-11-7.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-avx2-cuda-12-0.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-avx2.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-avx512-cuda-11-7.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-avx512-cuda-12-0.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-avx512.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-noavx-cuda-11-7.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-noavx-cuda-12-0.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-noavx.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-linux-amd64-vulkan.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cuda-11-7-linux-amd64.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cuda-12-0-linux-amd64.tar.gz + cd .. + + # Remove network package + ls -al + rm -rf ${{ steps.set-output-params.outputs.package_name }} + rm ${{ steps.set-output-params.outputs.package_name }}.deb + chmod +x create_deb_local.sh + ./create_deb_local.sh ${{ steps.set-output-params.outputs.package_name }} ${{ inputs.new_version }} ../../cortex/${{ steps.set-output-params.outputs.destination_binary_name }} ${{ steps.set-output-params.outputs.destination_binary_name }} ${{ steps.set-output-params.outputs.data_folder_name }} ${{ steps.set-output-params.outputs.configuration_file_name }}; + cp ${{ steps.set-output-params.outputs.package_name }}.deb ../../${{ steps.set-output-params.outputs.package_name }}-local.deb - name: Package run: | @@ -148,8 +183,14 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@v4 with: - name: cortex-${{ inputs.new_version }}-linux-amd64-installer - path: ./engine/${{ steps.set-output-params.outputs.package_name }}.deb + name: cortex-${{ inputs.new_version }}-linux-amd64-network-installer + path: ./engine/${{ steps.set-output-params.outputs.package_name }}-network.deb + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: cortex-${{ inputs.new_version }}-linux-amd64-local-installer + path: ./engine/${{ steps.set-output-params.outputs.package_name }}-local.deb - name: upload to aws s3 if public provider is aws if: inputs.public_provider == 'aws-s3' @@ -157,7 +198,8 @@ jobs: aws s3 cp ./engine/cortex.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/linux-amd64-cortex-nightly.tar.gz aws s3 cp ./engine/cortex.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/linux-amd64/cortex-nightly.tar.gz - aws s3 cp ./engine/${{ steps.set-output-params.outputs.package_name }}.deb s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/linux-amd64/cortex-${{ inputs.new_version }}-linux-amd64-installer.deb + aws s3 cp ./engine/${{ steps.set-output-params.outputs.package_name }}-network.deb s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/linux-amd64/cortex-${{ inputs.new_version }}-linux-amd64-network-installer.deb + aws s3 cp ./engine/${{ steps.set-output-params.outputs.package_name }}-local.deb s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/linux-amd64/cortex-${{ inputs.new_version }}-linux-amd64-local-installer.deb env: AWS_ACCESS_KEY_ID: ${{ secrets.DELTA_AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.DELTA_AWS_SECRET_ACCESS_KEY }} @@ -182,6 +224,17 @@ jobs: uses: actions/upload-release-asset@v1.0.1 with: upload_url: ${{ inputs.upload_url }} - asset_path: ./engine/${{ steps.set-output-params.outputs.package_name }}.deb - asset_name: cortex-${{ inputs.new_version }}-linux-amd64-installer.deb + asset_path: ./engine/${{ steps.set-output-params.outputs.package_name }}-network.deb + asset_name: cortex-${{ inputs.new_version }}-linux-amd64-network-installer.deb + asset_content_type: application/octet-stream + + - name: Upload release assert if public provider is github + if: inputs.public_provider == 'github' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: actions/upload-release-asset@v1.0.1 + with: + upload_url: ${{ inputs.upload_url }} + asset_path: ./engine/${{ steps.set-output-params.outputs.package_name }}-local.deb + asset_name: cortex-${{ inputs.new_version }}-linux-amd64-local-installer.deb asset_content_type: application/octet-stream \ No newline at end of file diff --git a/.github/workflows/template-noti-discord.yaml b/.github/workflows/template-noti-discord.yaml index f86cf7bd0..b77e06eef 100644 --- a/.github/workflows/template-noti-discord.yaml +++ b/.github/workflows/template-noti-discord.yaml @@ -31,7 +31,9 @@ jobs: - Local Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/windows-amd64/cortex-{{ VERSION }}-windows-amd64-local-installer.exe - macOS Intel: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-amd64/cortex-{{ VERSION }}-mac-amd64-installer.pkg - macOS Apple Silicon: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-arm64/cortex-{{ VERSION }}-mac-arm64-installer.pkg - - Linux Deb: https://delta.jan.ai/cortex/v{{ VERSION }}/linux-amd64/cortex-{{ VERSION }}-linux-amd64-installer.deb + - Linux Deb: + - Network Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/linux-amd64/cortex-{{ VERSION }}-linux-amd64-network-installer.deb + - Local Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/linux-amd64/cortex-{{ VERSION }}-linux-amd64-local-installer.deb - Github action run: https://github.com/janhq/cortex.cpp/actions/runs/{{ GITHUB_RUN_ID }} env: DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} \ No newline at end of file diff --git a/engine/templates/linux/create_deb_local.sh b/engine/templates/linux/create_deb_local.sh new file mode 100644 index 000000000..cf9c3cb07 --- /dev/null +++ b/engine/templates/linux/create_deb_local.sh @@ -0,0 +1,38 @@ +PACKAGE_NAME=$1 +VERSION=$2 +SOURCE_BINARY_PATH=$3 +DESTINATION_BINARY_NAME=$4 +DATA_FOLDER_NAME=$5 +CONFIGURATION_FILE_NAME=$6 + +mkdir -p $PACKAGE_NAME/DEBIAN + +mkdir -p $PACKAGE_NAME/usr/bin +cp $SOURCE_BINARY_PATH $PACKAGE_NAME/usr/bin/$DESTINATION_BINARY_NAME + +mkdir -p $PACKAGE_NAME/tmp/$DESTINATION_BINARY_NAME-dependencies +cp dependencies/* $PACKAGE_NAME/tmp/$DESTINATION_BINARY_NAME-dependencies + +export DESTINATION_BINARY_NAME + +cp postinst_local $PACKAGE_NAME/DEBIAN/postinst +sed -i "2s/.*/DESTINATION_BINARY_NAME=$DESTINATION_BINARY_NAME/" $PACKAGE_NAME/DEBIAN/postinst + +cp prerm $PACKAGE_NAME/DEBIAN/prerm +sed -i "3s/.*/DESTINATION_BINARY_NAME=$DESTINATION_BINARY_NAME/" $PACKAGE_NAME/DEBIAN/prerm + +export DATA_FOLDER_NAME CONFIGURATION_FILE_NAME + +cp postrm $PACKAGE_NAME/DEBIAN/postrm +sed -i "3s/.*/DATA_FOLDER_NAME=$DATA_FOLDER_NAME/" $PACKAGE_NAME/DEBIAN/postrm +sed -i "4s/.*/CONFIGURATION_FILE_NAME=$CONFIGURATION_FILE_NAME/" $PACKAGE_NAME/DEBIAN/postrm + +chmod 755 $PACKAGE_NAME/DEBIAN/postinst +chmod 755 $PACKAGE_NAME/DEBIAN/postrm +chmod 755 $PACKAGE_NAME/DEBIAN/prerm + +export PACKAGE_NAME VERSION + +envsubst < control > $PACKAGE_NAME/DEBIAN/control + +dpkg-deb --build $PACKAGE_NAME $PACKAGE_NAME.deb diff --git a/engine/templates/linux/postinst_local b/engine/templates/linux/postinst_local new file mode 100644 index 000000000..9acba5b2e --- /dev/null +++ b/engine/templates/linux/postinst_local @@ -0,0 +1,6 @@ +#!/bin/sh +DESTINATION_BINARY_NAME=cortex +USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} +echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS" +sudo -u $USER_TO_RUN_AS /usr/bin/$DESTINATION_BINARY_NAME engines install cortex.llamacpp -s /tmp/$DESTINATION_BINARY_NAME-dependencies +rm -rf /tmp/$DESTINATION_BINARY_NAME-dependencies From b6fb9acf87be5309f9a3c8c9b7d919ca76ffa436 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 25 Sep 2024 15:03:37 +0700 Subject: [PATCH 2/3] fix: get cuda_driver_version on install engine --- engine/services/engine_service.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/services/engine_service.cc b/engine/services/engine_service.cc index 048495494..7fe275f61 100644 --- a/engine/services/engine_service.cc +++ b/engine/services/engine_service.cc @@ -101,6 +101,7 @@ std::vector EngineService::GetEngineInfoList() const { cpp::result EngineService::InstallEngine( const std::string& engine, const std::string& version, const std::string& src) { + hw_inf_.cuda_driver_version = system_info_utils::GetCudaVersion(); if (!src.empty()) { return UnzipEngine(engine, version, src); From 1f00949f15b3df00aaee0cf672cb19539759ff82 Mon Sep 17 00:00:00 2001 From: Hien To Date: Wed, 25 Sep 2024 16:04:49 +0700 Subject: [PATCH 3/3] Add PATH for nvidia-smi on wsl2 windows --- engine/templates/linux/postinst | 2 +- engine/templates/linux/postinst_local | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/templates/linux/postinst b/engine/templates/linux/postinst index 37debeed5..56e6cbcba 100644 --- a/engine/templates/linux/postinst +++ b/engine/templates/linux/postinst @@ -2,4 +2,4 @@ DESTINATION_BINARY_NAME=cortex USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS" -sudo -u $USER_TO_RUN_AS /usr/bin/$DESTINATION_BINARY_NAME engines install cortex.llamacpp +sudo -u $USER_TO_RUN_AS env PATH=$PATH:/usr/lib/wsl/lib /usr/bin/$DESTINATION_BINARY_NAME engines install cortex.llamacpp diff --git a/engine/templates/linux/postinst_local b/engine/templates/linux/postinst_local index 9acba5b2e..5453552cf 100644 --- a/engine/templates/linux/postinst_local +++ b/engine/templates/linux/postinst_local @@ -2,5 +2,5 @@ DESTINATION_BINARY_NAME=cortex USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS" -sudo -u $USER_TO_RUN_AS /usr/bin/$DESTINATION_BINARY_NAME engines install cortex.llamacpp -s /tmp/$DESTINATION_BINARY_NAME-dependencies +sudo -u $USER_TO_RUN_AS env PATH=$PATH:/usr/lib/wsl/lib /usr/bin/$DESTINATION_BINARY_NAME engines install cortex.llamacpp -s /tmp/$DESTINATION_BINARY_NAME-dependencies rm -rf /tmp/$DESTINATION_BINARY_NAME-dependencies