| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- # tihao-ai demo deployment script.
- # Builds the Angular app with the /dev/tihao-ai/ prefix, uploads it to Huawei OBS,
- # grants public-read, then refreshes the CDN directory.
- $ErrorActionPreference = "Stop"
- Set-StrictMode -Version Latest
- $ProjectName = "tihao-ai"
- $BasePath = "/dev/$ProjectName/"
- $BucketPath = "obs://nova-cloud/dev/$ProjectName"
- $PublicUrl = "https://app.fmode.cn/dev/$ProjectName/"
- $DistPath = Join-Path $PSScriptRoot "dist\$ProjectName\browser"
- # Tool paths.
- $OBSUTIL = "E:\obsutil_windows_amd64_5.7.9\obsutil.exe"
- $HCLOUD = "E:\huaweicloud-cli-windows-amd64\hcloud.exe"
- # Same deployment target as E:\workspace\apig-pay\deploy.ps1.
- # Credentials are read from environment variables so they are not committed to git.
- $ObsAccessKey = $env:TIHAO_OBS_ACCESS_KEY
- $ObsSecretKey = $env:TIHAO_OBS_SECRET_KEY
- $ObsEndpoint = if ($env:TIHAO_OBS_ENDPOINT) { $env:TIHAO_OBS_ENDPOINT } else { "obs.cn-south-1.myhuaweicloud.com" }
- $CdnAccessKey = $env:TIHAO_CDN_ACCESS_KEY
- $CdnSecretKey = $env:TIHAO_CDN_SECRET_KEY
- $CdnRegion = if ($env:TIHAO_CDN_REGION) { $env:TIHAO_CDN_REGION } else { "cn-north-1" }
- if (-not $ObsAccessKey -or -not $ObsSecretKey -or -not $CdnAccessKey -or -not $CdnSecretKey) {
- 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."
- }
- if (-not (Test-Path -LiteralPath $OBSUTIL)) {
- throw "obsutil not found: $OBSUTIL"
- }
- if (-not (Test-Path -LiteralPath $HCLOUD)) {
- throw "hcloud not found: $HCLOUD"
- }
- Push-Location $PSScriptRoot
- try {
- Write-Host "Building $ProjectName with base href $BasePath"
- & .\node_modules\.bin\ng.cmd build "--base-href=$BasePath"
- if (-not (Test-Path -LiteralPath $DistPath)) {
- throw "Build output not found: $DistPath"
- }
- Write-Host "Removing old OBS files: $BucketPath"
- & $OBSUTIL rm $BucketPath -r -f "-i=$ObsAccessKey" "-k=$ObsSecretKey" "-e=$ObsEndpoint"
- Write-Host "Syncing build output to OBS: $DistPath -> $BucketPath"
- & $OBSUTIL sync $DistPath $BucketPath "-i=$ObsAccessKey" "-k=$ObsSecretKey" "-e=$ObsEndpoint" "-acl=public-read"
- Write-Host "Applying public-read ACL"
- & $OBSUTIL chattri $BucketPath -r -f "-i=$ObsAccessKey" "-k=$ObsSecretKey" "-e=$ObsEndpoint" "-acl=public-read"
- Write-Host "Refreshing CDN directory: $PublicUrl"
- & $HCLOUD CDN CreateRefreshTasks/v2 "--cli-region=$CdnRegion" "--refresh_task.urls.1=$PublicUrl" "--refresh_task.type=directory" "--cli-access-key=$CdnAccessKey" "--cli-secret-key=$CdnSecretKey"
- Write-Host "Deployment complete: $PublicUrl"
- } finally {
- Pop-Location
- }
|