From 0a8a814f049950374f15157e4ef8764aeac9427a Mon Sep 17 00:00:00 2001 From: Hien To Date: Wed, 25 Sep 2024 15:04:26 +0700 Subject: [PATCH] Macos add local installer --- .github/workflows/beta-build.yml | 2 + .github/workflows/nightly-build.yml | 2 + .github/workflows/stable-build.yml | 2 + .github/workflows/template-build-macos.yml | 67 +++++++++++++++++--- .github/workflows/template-noti-discord.yaml | 8 ++- engine/templates/macos/create_pkg_local.sh | 28 ++++++++ engine/templates/macos/postinstall_local | 17 +++++ 7 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 engine/templates/macos/create_pkg_local.sh create mode 100644 engine/templates/macos/postinstall_local diff --git a/.github/workflows/beta-build.yml b/.github/workflows/beta-build.yml index 928e76db0..54c1a2390 100644 --- a/.github/workflows/beta-build.yml +++ b/.github/workflows/beta-build.yml @@ -49,6 +49,7 @@ jobs: channel: beta arch: amd64 upload_url: ${{ needs.create-draft-release.outputs.upload_url }} + cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} build-macos-arm64: uses: ./.github/workflows/template-build-macos.yml @@ -63,6 +64,7 @@ jobs: channel: beta arch: arm64 upload_url: ${{ needs.create-draft-release.outputs.upload_url }} + cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} build-windows-x64: uses: ./.github/workflows/template-build-windows-x64.yml diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 85ce2c27a..c110d427f 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -58,6 +58,7 @@ jobs: cmake-flags: "-DCORTEX_VARIANT=nightly -DCORTEX_CPP_VERSION='v${{ needs.get-update-version.outputs.new_version }}' -DCMAKE_TOOLCHAIN_FILE=/Users/runner/work/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake" channel: nightly arch: amd64 + cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} build-macos-arm64: uses: ./.github/workflows/template-build-macos.yml @@ -71,6 +72,7 @@ jobs: cmake-flags: "-DCORTEX_VARIANT=nightly -DCORTEX_CPP_VERSION='v${{ needs.get-update-version.outputs.new_version }}' -DMAC_ARM64=ON -DCMAKE_TOOLCHAIN_FILE=/Users/runner/work/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake" channel: nightly arch: arm64 + cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} build-windows-x64: uses: ./.github/workflows/template-build-windows-x64.yml diff --git a/.github/workflows/stable-build.yml b/.github/workflows/stable-build.yml index a54f6ad41..0932448f3 100644 --- a/.github/workflows/stable-build.yml +++ b/.github/workflows/stable-build.yml @@ -49,6 +49,7 @@ jobs: channel: stable arch: amd64 upload_url: ${{ needs.create-draft-release.outputs.upload_url }} + cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} build-macos-arm64: uses: ./.github/workflows/template-build-macos.yml @@ -63,6 +64,7 @@ jobs: channel: stable arch: arm64 upload_url: ${{ needs.create-draft-release.outputs.upload_url }} + cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} build-windows-x64: uses: ./.github/workflows/template-build-windows-x64.yml diff --git a/.github/workflows/template-build-macos.yml b/.github/workflows/template-build-macos.yml index e754bdf85..e865c0648 100644 --- a/.github/workflows/template-build-macos.yml +++ b/.github/workflows/template-build-macos.yml @@ -49,6 +49,11 @@ on: type: string default: 'arm64' description: 'The architecture 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 @@ -78,7 +83,7 @@ on: required: false jobs: - build-mac-x64: + build-mac: runs-on: ${{ inputs.runs-on }} permissions: contents: write @@ -169,7 +174,7 @@ jobs: QUILL_NOTARY_ISSUER: ${{ secrets.NOTARY_ISSUER }} QUILL_NOTARY_KEY: "/tmp/notary-key.p8" - - name: Build Installers + - name: Build network Installers shell: bash run: | cd engine @@ -185,8 +190,34 @@ jobs: productbuild --synthesize --package Distribution.pkg Distribution.xml sed -i '' 's/require-scripts="false"/require-scripts="true"/' Distribution.xml cat Distribution.xml - productbuild --distribution Distribution.xml --sign "Developer ID Installer: ${{ secrets.DEVELOPER_ID }}" --package-path . ${{ steps.set-output-params.outputs.package_name }}.pkg - xcrun notarytool submit ${{ steps.set-output-params.outputs.package_name }}.pkg --apple-id ${{ secrets.APPLE_ID }} --password ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} --team-id ${{ secrets.APPLE_TEAM_ID }} --wait + productbuild --distribution Distribution.xml --sign "Developer ID Installer: ${{ secrets.DEVELOPER_ID }}" --package-path . ${{ steps.set-output-params.outputs.package_name }}-network.pkg + xcrun notarytool submit ${{ steps.set-output-params.outputs.package_name }}-network.pkg --apple-id ${{ secrets.APPLE_ID }} --password ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} --team-id ${{ secrets.APPLE_TEAM_ID }} --wait + + - name: Build local Installers + shell: bash + run: | + mkdir -p engine/templates/macos/Scripts/dependencies + cd engine/templates/macos/Scripts/dependencies + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-mac-amd64.tar.gz + wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-mac-arm64.tar.gz + + cd ../../ + chmod +x create_pkg_local.sh + ./create_pkg_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 }} ${{ steps.set-output-params.outputs.uninstaller_file_name }} + cp ${{ steps.set-output-params.outputs.package_name }}.pkg ../../ + + - name: Codesign and notary for macos installer + run: | + cd engine + productsign --sign "Developer ID Installer: ${{ secrets.DEVELOPER_ID }}" ${{ steps.set-output-params.outputs.package_name }}.pkg ${{ steps.set-output-params.outputs.package_name }}$-signed.pkg + rm ${{ steps.set-output-params.outputs.package_name }}.pkg + mv ${{ steps.set-output-params.outputs.package_name }}$-signed.pkg Distribution.pkg + productbuild --synthesize --package Distribution.pkg Distribution.xml + sed -i '' 's/require-scripts="false"/require-scripts="true"/' Distribution.xml + cat Distribution.xml + productbuild --distribution Distribution.xml --sign "Developer ID Installer: ${{ secrets.DEVELOPER_ID }}" --package-path . ${{ steps.set-output-params.outputs.package_name }}-local.pkg + xcrun notarytool submit ${{ steps.set-output-params.outputs.package_name }}-local.pkg --apple-id ${{ secrets.APPLE_ID }} --password ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} --team-id ${{ secrets.APPLE_TEAM_ID }} --wait + - name: Package run: | @@ -202,8 +233,14 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@v4 with: - name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-installer - path: ./engine/${{ steps.set-output-params.outputs.package_name }}.pkg + name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-network-installer + path: ./engine/${{ steps.set-output-params.outputs.package_name }}-network.pkg + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-local-installer + path: ./engine/${{ steps.set-output-params.outputs.package_name }}-local.pkg - name: upload to aws s3 if public provider is aws if: inputs.public_provider == 'aws-s3' @@ -211,7 +248,8 @@ jobs: aws s3 cp ./engine/cortex.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/mac-${{ inputs.arch}}-cortex-nightly.tar.gz aws s3 cp ./engine/cortex.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/mac-${{ inputs.arch}}/cortex-nightly.tar.gz - aws s3 cp ./engine/${{ steps.set-output-params.outputs.package_name }}.pkg s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/mac-${{ inputs.arch}}/cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-installer.pkg + aws s3 cp ./engine/${{ steps.set-output-params.outputs.package_name }}-network.pkg s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/mac-${{ inputs.arch}}/cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-network-installer.pkg + aws s3 cp ./engine/${{ steps.set-output-params.outputs.package_name }}-local.pkg s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/mac-${{ inputs.arch}}/cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-local-installer.pkg env: AWS_ACCESS_KEY_ID: ${{ secrets.DELTA_AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.DELTA_AWS_SECRET_ACCESS_KEY }} @@ -236,6 +274,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 }}.pkg - asset_name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-installer.pkg + asset_path: ./engine/${{ steps.set-output-params.outputs.package_name }}-network.pkg + asset_name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-network-installer.pkg + 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.pkg + asset_name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-local-installer.pkg asset_content_type: application/octet-stream diff --git a/.github/workflows/template-noti-discord.yaml b/.github/workflows/template-noti-discord.yaml index f86cf7bd0..9e779f373 100644 --- a/.github/workflows/template-noti-discord.yaml +++ b/.github/workflows/template-noti-discord.yaml @@ -29,8 +29,12 @@ jobs: - Windows: - Network Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/windows-amd64/cortex-{{ VERSION }}-windows-amd64-network-installer.exe - 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 + - macOS Intel: + - Network Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-amd64/cortex-{{ VERSION }}-mac-amd64-network-installer.pkg + - Local Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-amd64/cortex-{{ VERSION }}-mac-amd64-local-installer.pkg + - macOS Apple Silicon: + - Network Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-arm64/cortex-{{ VERSION }}-mac-arm64-network-installer.pkg + - Local Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-arm64/cortex-{{ VERSION }}-mac-arm64-local-installer.pkg - Linux Deb: https://delta.jan.ai/cortex/v{{ VERSION }}/linux-amd64/cortex-{{ VERSION }}-linux-amd64-installer.deb - Github action run: https://github.com/janhq/cortex.cpp/actions/runs/{{ GITHUB_RUN_ID }} env: diff --git a/engine/templates/macos/create_pkg_local.sh b/engine/templates/macos/create_pkg_local.sh new file mode 100644 index 000000000..5ef16db30 --- /dev/null +++ b/engine/templates/macos/create_pkg_local.sh @@ -0,0 +1,28 @@ +PACKAGE_NAME=$1 +VERSION=$2 +SOURCE_BINARY_PATH=$3 +DESTINATION_BINARY_NAME=$4 +DATA_FOLDER_NAME=$5 +CONFIGURATION_FILE_NAME=$6 +UNINSTALLER_FILE_NAME=$7 + +mkdir installer +mkdir Scripts + +cp $SOURCE_BINARY_PATH installer/$DESTINATION_BINARY_NAME + +export DESTINATION_BINARY_NAME +cp postinstall_local Scripts/postinstall +sed -i '' "3s/.*/DESTINATION_BINARY_NAME=$DESTINATION_BINARY_NAME/" Scripts/postinstall +sed -i '' "4s/.*/DATA_FOLDER_NAME=$DATA_FOLDER_NAME/" Scripts/postinstall +sed -i '' "5s/.*/CONFIGURATION_FILE_NAME=$CONFIGURATION_FILE_NAME/" Scripts/postinstall +chmod +x Scripts/postinstall + +export DATA_FOLDER_NAME CONFIGURATION_FILE_NAME UNINSTALLER_FILE_NAME +cp cortex-uninstall.sh installer/$UNINSTALLER_FILE_NAME +sed -i '' "2s/.*/DESTINATION_BINARY_NAME=$DESTINATION_BINARY_NAME/" installer/$UNINSTALLER_FILE_NAME +sed -i '' "3s/.*/DATA_FOLDER_NAME=$DATA_FOLDER_NAME/" installer/$UNINSTALLER_FILE_NAME +sed -i '' "4s/.*/CONFIGURATION_FILE_NAME=$CONFIGURATION_FILE_NAME/" installer/$UNINSTALLER_FILE_NAME +sed -i '' "5s/.*/UNINSTALLER_FILE_NAME=$UNINSTALLER_FILE_NAME/" installer/$UNINSTALLER_FILE_NAME + +pkgbuild --identifier ai.cortexcpp.pkg --version $VERSION --scripts Scripts --install-location /usr/local/bin --root ./installer ${PACKAGE_NAME}.pkg diff --git a/engine/templates/macos/postinstall_local b/engine/templates/macos/postinstall_local new file mode 100644 index 000000000..f2ea8e454 --- /dev/null +++ b/engine/templates/macos/postinstall_local @@ -0,0 +1,17 @@ +#!/usr/bin/env sh +set -e +DESTINATION_BINARY_NAME=cortex +DATA_FOLDER_NAME=.cortex +CONFIGURATION_FILE_NAME=.cortexrc + +USER_TO_RUN_AS=$(stat -f "%Su" /dev/console) + +echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS" +sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME engines install cortex.llamacpp -s ./dependencies + +sudo chown -R $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$DATA_FOLDER_NAME" +sudo chown $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$CONFIGURATION_FILE_NAME" + +rm -rf ./dependencies + +exit 0 \ No newline at end of file