Skip to content

Commit

Permalink
Windows add local installer
Browse files Browse the repository at this point in the history
  • Loading branch information
hientominh authored and hiento09 committed Sep 24, 2024
1 parent 77414c6 commit 5fb0fca
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 17 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ jobs:
get-update-version:
uses: ./.github/workflows/template-get-update-version.yml

get-cortex-llamacpp-latest-version:
uses: ./.github/workflows/template-cortex-llamacpp-latest-version.yml

build-macos-x64:
uses: ./.github/workflows/template-build-macos.yml
needs: [get-update-version, set-public-provider]
needs: [get-update-version, set-public-provider, get-cortex-llamacpp-latest-version]
secrets: inherit
with:
ref: ${{ needs.set-public-provider.outputs.ref }}
Expand All @@ -58,7 +61,7 @@ jobs:

build-macos-arm64:
uses: ./.github/workflows/template-build-macos.yml
needs: [get-update-version, set-public-provider]
needs: [get-update-version, set-public-provider, get-cortex-llamacpp-latest-version]
secrets: inherit
with:
ref: ${{ needs.set-public-provider.outputs.ref }}
Expand All @@ -72,7 +75,7 @@ jobs:
build-windows-x64:
uses: ./.github/workflows/template-build-windows-x64.yml
secrets: inherit
needs: [get-update-version, set-public-provider]
needs: [get-update-version, set-public-provider, get-cortex-llamacpp-latest-version]
with:
ref: ${{ needs.set-public-provider.outputs.ref }}
public_provider: ${{ needs.set-public-provider.outputs.public_provider }}
Expand All @@ -82,11 +85,12 @@ jobs:
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
channel: nightly
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}

build-linux-x64:
uses: ./.github/workflows/template-build-linux-x64.yml
secrets: inherit
needs: [get-update-version, set-public-provider]
needs: [get-update-version, set-public-provider, get-cortex-llamacpp-latest-version]
with:
ref: ${{ needs.set-public-provider.outputs.ref }}
public_provider: ${{ needs.set-public-provider.outputs.public_provider }}
Expand All @@ -98,7 +102,7 @@ jobs:
update-latest-version:
runs-on: ubuntu-latest
if: needs.set-public-provider.outputs.public_provider == 'aws-s3'
needs: [get-update-version, set-public-provider, build-linux-x64, build-macos-x64, build-macos-arm64, build-windows-x64]
needs: [get-update-version, set-public-provider, build-linux-x64, build-macos-x64, build-macos-arm64, build-windows-x64, get-cortex-llamacpp-latest-version]
steps:
- name: Update latest version
id: update-latest-version
Expand All @@ -117,7 +121,7 @@ jobs:
AWS_EC2_METADATA_DISABLED: "true"

noti-discord-nightly-and-update-url-readme:
needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64, get-update-version, set-public-provider]
needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, get-cortex-llamacpp-latest-version]
secrets: inherit
if: github.event_name == 'schedule'
uses: ./.github/workflows/template-noti-discord.yaml
Expand All @@ -126,7 +130,7 @@ jobs:
new_version: ${{ needs.get-update-version.outputs.new_version }}

noti-discord-manual:
needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64, get-update-version, set-public-provider]
needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, get-cortex-llamacpp-latest-version]
secrets: inherit
if: github.event_name == 'workflow_dispatch' && github.event.inputs.public_provider == 'aws-s3'
uses: ./.github/workflows/template-noti-discord.yaml
Expand Down
81 changes: 71 additions & 10 deletions .github/workflows/template-build-windows-x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
MINIO_BUCKET_NAME:
required: false
Expand Down Expand Up @@ -104,6 +109,7 @@ jobs:
echo "::set-output name=configuration_file_name::.cortexrc"
echo "::set-output name=uninstaller_file_name::cortex-uninstall.sh"
echo "::set-output name=iss_file_name::installer.iss"
echo "::set-output name=local_iss_file_name::local-installer.iss"
fi
# Set output for beta channel
Expand All @@ -114,6 +120,7 @@ jobs:
echo "::set-output name=configuration_file_name::.cortexrc-beta"
echo "::set-output name=uninstaller_file_name::cortex-beta-uninstall.sh"
echo "::set-output name=iss_file_name::installer-beta.iss"
echo "::set-output name=local_iss_file_name::local-installer-beta.iss"
fi
# Set output for nightly channel
Expand All @@ -124,14 +131,15 @@ jobs:
echo "::set-output name=configuration_file_name::.cortexrc-nightly"
echo "::set-output name=uninstaller_file_name::cortex-nightly-uninstall.sh"
echo "::set-output name=iss_file_name::installer-nightly.iss"
echo "::set-output name=local_iss_file_name::local-installer-nightly.iss"
fi
- name: Install jq
uses: dcarbone/[email protected]

- name: Install dependencies on Windows
run: |
choco install make pkgconfiglite ccache awscli 7zip ninja -y
choco install make pkgconfiglite ccache awscli 7zip ninja wget -y
dotnet tool install --global AzureSignTool
- name: Download ccache from s3
Expand Down Expand Up @@ -171,30 +179,65 @@ jobs:
run: |
cd engine/templates/windows
sed -i "s/AppVersion=1.0/AppVersion=${{ inputs.new_version }}/g" ${{ steps.set-output-params.outputs.iss_file_name }}
sed -i "s/AppVersion=1.0/AppVersion=${{ inputs.new_version }}/g" ${{ steps.set-output-params.outputs.local_iss_file_name }}
cat ${{ steps.set-output-params.outputs.iss_file_name }}
cp ${{ steps.set-output-params.outputs.iss_file_name }} ../../../
cp ${{ steps.set-output-params.outputs.local_iss_file_name }} ../../../
ls ../../../
- name: Build Installers
- name: Build network Installers
shell: bash
run: |
cd engine
make build-installer PACKAGE_NAME=${{ steps.set-output-params.outputs.package_name }} VERSION=${{ inputs.new_version }} DESTINATION_BINARY_NAME="${{ steps.set-output-params.outputs.destination_binary_name }}"
ls ../
- name: Build local Installers
shell: powershell
run: |
mkdir dependencies
cd dependencies
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-avx-cuda-11-7.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-avx-cuda-12-0.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-avx.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-avx2-cuda-11-7.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-avx2-cuda-12-0.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-avx2.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-avx512-cuda-11-7.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-avx512-cuda-12-0.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-avx512.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-noavx-cuda-11-7.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-noavx-cuda-12-0.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-noavx.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-windows-amd64-vulkan.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cuda-11-7-windows-amd64.tar.gz
wget.exe https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cuda-12-0-windows-amd64.tar.gz
- name: Enable long paths
run: |
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /f
- name: Compile .ISS to .EXE Installer
- name: Compile .ISS to .EXE network Installer
uses: nadeemjazmawe/[email protected]
with:
filepath: ./${{ steps.set-output-params.outputs.iss_file_name }}

- name: Codesign for windows installer
- name: Codesign for windows network installer
shell: pwsh
run: |
~\.dotnet\tools\azuresigntool.exe sign -kvu ${{ secrets.AZURE_KEY_VAULT_URI }} -kvi ${{ secrets.AZURE_CLIENT_ID }} -kvt ${{ secrets.AZURE_TENANT_ID }} -kvs ${{ secrets.AZURE_CLIENT_SECRET }} -kvc ${{ secrets.AZURE_CERT_NAME }} -tr http://timestamp.globalsign.com/tsa/r6advanced1 -v ".\setup.exe"
mv .\setup.exe .\network-setup.exe
- name: Compile .ISS to .EXE local Installer
uses: nadeemjazmawe/[email protected]
with:
filepath: ./${{ steps.set-output-params.outputs.local_iss_file_name }}

- name: Codesign for windows network installer
shell: pwsh
run: |
~\.dotnet\tools\azuresigntool.exe sign -kvu ${{ secrets.AZURE_KEY_VAULT_URI }} -kvi ${{ secrets.AZURE_CLIENT_ID }} -kvt ${{ secrets.AZURE_TENANT_ID }} -kvs ${{ secrets.AZURE_CLIENT_SECRET }} -kvc ${{ secrets.AZURE_CERT_NAME }} -tr http://timestamp.globalsign.com/tsa/r6advanced1 -v ".\setup.exe"
mv .\setup.exe .\local-setup.exe
- name: Package
run: |
Expand All @@ -207,11 +250,17 @@ jobs:
name: cortex-${{ inputs.new_version }}-windows-amd64
path: ./engine/cortex

- name: Upload Artifact
- name: Upload Artifact network installer
uses: actions/upload-artifact@v4
with:
name: cortex-${{ inputs.new_version }}-windows-amd64-installer
path: ./setup.exe
name: cortex-${{ inputs.new_version }}-windows-amd64-network-installer
path: ./network-setup.exe

- name: Upload Artifact local installer
uses: actions/upload-artifact@v4
with:
name: cortex-${{ inputs.new_version }}-windows-amd64-local-installer
path: ./local-setup.exe

- name: upload to aws s3 if public provider is aws
if: inputs.public_provider == 'aws-s3'
Expand All @@ -221,7 +270,8 @@ jobs:
aws s3 cp ./engine/cortex.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/windows-amd64-cortex-nightly.tar.gz
aws s3 cp ./engine/cortex.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/windows-amd64/cortex-nightly.tar.gz
aws s3 cp ./setup.exe s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/windows-amd64/cortex-${{ inputs.new_version }}-windows-amd64-installer.exe
aws s3 cp ./network-setup.exe s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/windows-amd64/cortex-${{ inputs.new_version }}-windows-amd64-network-installer.exe
aws s3 cp ./local-setup.exe s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/windows-amd64/cortex-${{ inputs.new_version }}-windows-amd64-local-installer.exe
env:
AWS_ACCESS_KEY_ID: ${{ secrets.DELTA_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DELTA_AWS_SECRET_ACCESS_KEY }}
Expand All @@ -246,6 +296,17 @@ jobs:
uses: actions/[email protected]
with:
upload_url: ${{ inputs.upload_url }}
asset_path: ./setup.exe
asset_name: cortex-${{ inputs.new_version }}-windows-amd64-installer.exe
asset_path: ./network-setup.exe
asset_name: cortex-${{ inputs.new_version }}-windows-amd64-network-installer.exe
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/[email protected]
with:
upload_url: ${{ inputs.upload_url }}
asset_path: ./local-setup.exe
asset_name: cortex-${{ inputs.new_version }}-windows-amd64-local-installer.exe
asset_content_type: application/octet-stream
47 changes: 47 additions & 0 deletions .github/workflows/template-cortex-llamacpp-latest-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: get-cortex-llamacpp-latest-version
on:
workflow_call:
outputs:
cortex_llamacpp_latest_version:
description: 'The latest version of cortex.llamacpp engines'
value: ${{ jobs.get-cortex-llamacpp-latest-version.outputs.new_version }}

jobs:
get-cortex-llamacpp-latest-version:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.version_update.outputs.new_version }}
steps:
- name: Install jq
uses: dcarbone/[email protected]

- name: Update app version based on latest release tag with build number
id: version_update
run: |
# Function to get the latest release tag
get_latest_tag() {
local retries=0
local max_retries=3
local tag
while [ $retries -lt $max_retries ]; do
tag=$(curl -s https://api.github.com/repos/janhq/cortex.llamacpp/releases/latest | jq -r .tag_name)
if [ -n "$tag" ] && [ "$tag" != "null" ]; then
echo $tag
return
else
let retries++
echo "Retrying... ($retries/$max_retries)"
sleep 2
fi
done
echo "Failed to fetch latest tag after $max_retries attempts."
exit 1
}
# Get the latest release tag from GitHub API
LATEST_TAG=$(get_latest_tag)
# Remove the 'v' and append the build number to the version
new_version="${LATEST_TAG#v}"
echo "New version: $new_version"
echo "::set-output name=new_version::$new_version"
108 changes: 108 additions & 0 deletions engine/templates/windows/local-installer-nightly.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
; Define the application name, version, and other details
[Setup]
AppName=cortexcpp-nightly
AppVersion=1.0
DefaultDirName={localappdata}\cortexcpp-nightly
DefaultGroupName=cortexcpp-nightly
OutputDir=.
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
PrivilegesRequired=lowest
AllowNoIcons=yes

; Define the languages section
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

; Define the files to be installed
[Files]
Source: "cortex-nightly.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "msvcp140.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "vcruntime140.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "vcruntime140_1.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "dependencies\*"; DestDir: "{tmp}\dependencies"; Flags: ignoreversion recursesubdirs

; Define the icons to be created
[Icons]
Name: "{group}\cortexcpp-nightly"; Filename: "{app}\cortex-nightly.exe"

; Define the uninstall run section to execute commands before uninstallation
[UninstallRun]
Filename: "{app}\cortex-nightly.exe"; Parameters: "stop"; StatusMsg: "Stopping cortexcpp-nightly service..."; Flags: runhidden

; Combine all Pascal scripting code in one [Code] section
[Code]
procedure AddToUserPathAndInstallEngines;
var
ExpandedAppDir: String;
TempFolder: String;
CmdLine, CortexInstallCmd: String;
ResultCode: Integer;
begin
ExpandedAppDir := ExpandConstant('{app}');
TempFolder := ExpandConstant('{tmp}\dependencies'); // Path to the extracted dependencies folder
// Add {app} to PATH
CmdLine := Format('setx PATH "%s;%%PATH%%"', [ExpandedAppDir]);
Exec('cmd.exe', '/C ' + CmdLine, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
// Update status message for installing engines
WizardForm.StatusLabel.Caption := 'Installing engines from offline package...';
WizardForm.StatusLabel.Update;
// Run the installation command with the -s option pointing to TempFolder
CortexInstallCmd := Format('"%s\cortex-nightly.exe" engines install cortex.llamacpp -s "%s"', [ExpandedAppDir, TempFolder]);
Exec('cmd.exe', '/C ' + CortexInstallCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
// Clear the status message after completion
WizardForm.StatusLabel.Caption := '';
WizardForm.StatusLabel.Update;
// Remove the temp folder after the installation is complete
DelTree(ExpandConstant('{tmp}\dependencies'), True, True, True);
end;
procedure DeleteCurrentUserCortexFolderAndConfig;
var
UserCortexFolder: String;
UserCortexConfig: String;
ShouldDelete: Integer;
begin
UserCortexFolder := ExpandConstant('{%USERPROFILE}\cortexcpp-nightly');
UserCortexConfig := ExpandConstant('{%USERPROFILE}\.cortexrc-nightly');
if DirExists(UserCortexFolder) or FileExists(UserCortexConfig) then
begin
ShouldDelete := MsgBox('Do you want to delete the application data in cortexcpp-nightly and the .cortexrc-nightly config file (this will remove all user data)?', mbConfirmation, MB_YESNO);
if ShouldDelete = idYes then
begin
if DirExists(UserCortexFolder) then
begin
DelTree(UserCortexFolder, True, True, True);
end;
if FileExists(UserCortexConfig) then
begin
DeleteFile(UserCortexConfig);
end;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
AddToUserPathAndInstallEngines;
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usPostUninstall then
begin
DeleteCurrentUserCortexFolderAndConfig;
end;
end;

0 comments on commit 5fb0fca

Please sign in to comment.