deploy.ps1 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # tihao-ai demo deployment script.
  2. # Builds the Angular app with the /dev/tihao-ai/ prefix, uploads it to Huawei OBS,
  3. # grants public-read, then refreshes the CDN directory.
  4. $ErrorActionPreference = "Stop"
  5. Set-StrictMode -Version Latest
  6. $ProjectName = "tihao-ai"
  7. $BasePath = "/dev/$ProjectName/"
  8. $BucketPath = "obs://nova-cloud/dev/$ProjectName"
  9. $PublicUrl = "https://app.fmode.cn/dev/$ProjectName/"
  10. $DistPath = Join-Path $PSScriptRoot "dist\$ProjectName\browser"
  11. # Tool paths.
  12. $OBSUTIL = "E:\obsutil_windows_amd64_5.7.9\obsutil.exe"
  13. $HCLOUD = "E:\huaweicloud-cli-windows-amd64\hcloud.exe"
  14. # Same deployment target as E:\workspace\apig-pay\deploy.ps1.
  15. # Credentials are read from environment variables so they are not committed to git.
  16. $ObsAccessKey = $env:TIHAO_OBS_ACCESS_KEY
  17. $ObsSecretKey = $env:TIHAO_OBS_SECRET_KEY
  18. $ObsEndpoint = if ($env:TIHAO_OBS_ENDPOINT) { $env:TIHAO_OBS_ENDPOINT } else { "obs.cn-south-1.myhuaweicloud.com" }
  19. $CdnAccessKey = $env:TIHAO_CDN_ACCESS_KEY
  20. $CdnSecretKey = $env:TIHAO_CDN_SECRET_KEY
  21. $CdnRegion = if ($env:TIHAO_CDN_REGION) { $env:TIHAO_CDN_REGION } else { "cn-north-1" }
  22. if (-not $ObsAccessKey -or -not $ObsSecretKey -or -not $CdnAccessKey -or -not $CdnSecretKey) {
  23. throw "Missing deployment credentials. Set TIHAO_OBS_ACCESS_KEY, TIHAO_OBS_SECRET_KEY, TIHAO_CDN_ACCESS_KEY, and TIHAO_CDN_SECRET_KEY before running this script."
  24. }
  25. if (-not (Test-Path -LiteralPath $OBSUTIL)) {
  26. throw "obsutil not found: $OBSUTIL"
  27. }
  28. if (-not (Test-Path -LiteralPath $HCLOUD)) {
  29. throw "hcloud not found: $HCLOUD"
  30. }
  31. Push-Location $PSScriptRoot
  32. try {
  33. Write-Host "Building $ProjectName with base href $BasePath"
  34. & .\node_modules\.bin\ng.cmd build "--base-href=$BasePath"
  35. if (-not (Test-Path -LiteralPath $DistPath)) {
  36. throw "Build output not found: $DistPath"
  37. }
  38. Write-Host "Removing old OBS files: $BucketPath"
  39. & $OBSUTIL rm $BucketPath -r -f "-i=$ObsAccessKey" "-k=$ObsSecretKey" "-e=$ObsEndpoint"
  40. Write-Host "Syncing build output to OBS: $DistPath -> $BucketPath"
  41. & $OBSUTIL sync $DistPath $BucketPath "-i=$ObsAccessKey" "-k=$ObsSecretKey" "-e=$ObsEndpoint" "-acl=public-read"
  42. Write-Host "Applying public-read ACL"
  43. & $OBSUTIL chattri $BucketPath -r -f "-i=$ObsAccessKey" "-k=$ObsSecretKey" "-e=$ObsEndpoint" "-acl=public-read"
  44. Write-Host "Refreshing CDN directory: $PublicUrl"
  45. & $HCLOUD CDN CreateRefreshTasks/v2 "--cli-region=$CdnRegion" "--refresh_task.urls.1=$PublicUrl" "--refresh_task.type=directory" "--cli-access-key=$CdnAccessKey" "--cli-secret-key=$CdnSecretKey"
  46. Write-Host "Deployment complete: $PublicUrl"
  47. } finally {
  48. Pop-Location
  49. }