install.ps1 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Set error handling
  2. $ErrorActionPreference = "Stop"
  3. # Get the root directory and third_party directory
  4. $ROOT_DIR = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent | Split-Path -Parent | Split-Path -Parent -Resolve
  5. # Include the common functions
  6. . "$ROOT_DIR/hack/lib/windows/init.ps1"
  7. function Install-Dependency {
  8. pip install uv
  9. if ($LASTEXITCODE -ne 0) {
  10. GPUStack.Log.Fatal "failed to install uv."
  11. }
  12. uv sync
  13. if ($LASTEXITCODE -ne 0) {
  14. GPUStack.Log.Fatal "failed run uv sync."
  15. }
  16. uv run pre-commit install
  17. if ($LASTEXITCODE -ne 0) {
  18. GPUStack.Log.Fatal "failed run pre-commint install."
  19. }
  20. }
  21. function Get-UI {
  22. $defaultTag = "latest"
  23. $uiPath = Join-Path -Path $ROOT_DIR -ChildPath "gpustack/ui"
  24. $tmpPath = Join-Path -Path $uiPath -ChildPath "tmp"
  25. $tmpUIPath = Join-Path -Path $tmpPath -ChildPath "ui"
  26. $tag = "latest"
  27. if ($GIT_VERSION -ne "v0.0.0") {
  28. $tag = $GIT_VERSION
  29. }
  30. $null = Remove-Item -Recurse -Force $uiPath -ErrorAction Ignore
  31. $null = New-Item -ItemType Directory -Path $tmpUIPath
  32. GPUStack.Log.Info "downloading '$tag' UI assets"
  33. try {
  34. $tmpFile = "$tmpPath/ui.tar.gz"
  35. $url = "https://gpustack-ui-1303613262.cos.accelerate.myqcloud.com/releases/$tag.tar.gz"
  36. DownloadWithRetries -url $url -outFile $tmpFile -maxRetries 3
  37. # For git action's bug, can't use tar directly.
  38. # https://github.com/julia-actions/setup-julia/issues/205
  39. & "$env:WINDIR/System32/tar" -xzf "$tmpPath/ui.tar.gz" -C "$tmpUIPath"
  40. }
  41. catch {
  42. GPUStack.Log.Fatal "failed to download '$tag' UI archive: $($_.Exception.Message)"
  43. if (-eq $tag $defaultTag) {
  44. return
  45. }
  46. GPUStack.Log.Warn "failed to download '$tag' UI archive, fallback to '$defaultTag' UI archive"
  47. try {
  48. $tmpFile = "$tmpPath/ui.tar.gz"
  49. $url = "https://gpustack-ui-1303613262.cos.accelerate.myqcloud.com/releases/$defaultTag.tar.gz"
  50. DownloadWithRetries -url $url -outFile $tmpFile -maxRetries 3
  51. tar -xzf $tmpFile -C "$tmpUIPath"
  52. }
  53. catch {
  54. GPUStack.Log.Fatal "failed to download '$defaultTag' UI archive: : $($_.Exception.Message)"
  55. }
  56. }
  57. Copy-Item -Path "$tmpUIPath/dist/*" -Destination $uiPath -Recurse
  58. Remove-Item -Recurse -Force $tmpUIPath -ErrorAction Ignore
  59. }
  60. function DownloadWithRetries {
  61. param (
  62. [string]$url,
  63. [string]$outFile,
  64. [int]$maxRetries = 3
  65. )
  66. for ($i = 1; $i -le $maxRetries; $i++) {
  67. try {
  68. GPUStack.Log.Info "Attempting to download from $url (Attempt $i of $maxRetries)"
  69. Invoke-WebRequest -Uri $url -OutFile $outFile -ErrorAction Stop
  70. return
  71. }
  72. catch {
  73. GPUStack.Log.Warn "Download attempt $i failed: $($_.Exception.Message)"
  74. if ($i -eq $maxRetries) {
  75. throw $_
  76. }
  77. }
  78. }
  79. }
  80. #
  81. # main
  82. #
  83. GPUStack.Log.Info "+++ DEPENDENCIES +++"
  84. try {
  85. Install-Dependency
  86. Get-UI
  87. }
  88. catch {
  89. GPUStack.Log.Fatal "failed to download dependencies: $($_.Exception.Message)"
  90. }
  91. GPUStack.Log.Info "-- DEPENDENCIES ---"