No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

116 líneas
4.3KB

  1. <#
  2. Deploys the Purple Envelope Orders Site to the production IIS server.
  3. Flow:
  4. 1. Build a release locally (scripts\build-release.ps1) - a clean file tree with the
  5. production web.config swapped in, and dev-only files excluded via .gitattributes.
  6. 2. Zip it and scp the zip to the remote host.
  7. 3. scp scripts\deploy-iis-remote-apply.ps1 to the remote host and run it over ssh - it
  8. wipes the deploy directory, extracts the new release, points IIS at it, runs
  9. migrations, and restarts the site/app pool. The database and error log live outside
  10. the deploy directory, so the wipe never touches them.
  11. 4. Smoke-test a few routes over HTTPS from this machine.
  12. Usage:
  13. powershell -File scripts\deploy-iis.ps1
  14. powershell -File scripts\deploy-iis.ps1 -Ref master
  15. Remote target defaults to the "ssh user@host" line in scripts\deployinfo.txt (gitignored,
  16. not committed - create it locally, e.g.: ssh daniel_admin@kci-uluto-web).
  17. #>
  18. param(
  19. [string]$Ref = 'HEAD',
  20. [string]$RemoteTarget = '',
  21. [int]$RemotePort = 22,
  22. [string]$RemoteDir = 'C:\inetpub\wwwroot\Purple_Envelop_Order_Site',
  23. [string]$SiteName = 'PurpleEnvelopes',
  24. [string]$AppPool = 'PurpleEnvelopes',
  25. [string]$DbPath = 'C:\inetpub\data\webdata.accdb',
  26. [string]$BaseUrl = 'https://pe.kentcommunications.com/',
  27. [switch]$RunMigrations = $true,
  28. [string]$SshExe = 'ssh',
  29. [string]$ScpExe = 'scp'
  30. )
  31. $ErrorActionPreference = 'Stop'
  32. $repoRoot = Split-Path $PSScriptRoot -Parent
  33. function Ensure-Command {
  34. param([string]$Name)
  35. if(!(Get-Command $Name -ErrorAction SilentlyContinue)){
  36. throw "$Name not found on PATH"
  37. }
  38. }
  39. function Get-DefaultRemoteTarget {
  40. $infoPath = Join-Path $PSScriptRoot 'deployinfo.txt'
  41. if(!(Test-Path $infoPath)){ return '' }
  42. $sshLine = Get-Content $infoPath | Where-Object { $_ -match '^\s*ssh\s+' } | Select-Object -First 1
  43. if([string]::IsNullOrWhiteSpace($sshLine)){ return '' }
  44. return ($sshLine -replace '^\s*ssh\s+', '').Trim()
  45. }
  46. if([string]::IsNullOrWhiteSpace($RemoteTarget)){
  47. $RemoteTarget = Get-DefaultRemoteTarget
  48. }
  49. if([string]::IsNullOrWhiteSpace($RemoteTarget)){
  50. throw 'No -RemoteTarget given and scripts\deployinfo.txt not found. Create scripts\deployinfo.txt with a line like: ssh user@host'
  51. }
  52. Ensure-Command $SshExe
  53. Ensure-Command $ScpExe
  54. Ensure-Command git
  55. # --- 1. Build ---
  56. $outDir = Join-Path $repoRoot ('dist\release_' + (Get-Date -Format 'yyyyMMdd_HHmmss'))
  57. & (Join-Path $PSScriptRoot 'build-release.ps1') -Ref $Ref -OutDir $outDir
  58. if($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne $null){ throw 'build-release.ps1 failed' }
  59. # --- 2. Zip and ship it ---
  60. $zipName = 'release_' + (Get-Date -Format 'yyyyMMdd_HHmmss') + '.zip'
  61. $localZip = Join-Path (Split-Path $outDir -Parent) $zipName
  62. Compress-Archive -Path (Join-Path $outDir '*') -DestinationPath $localZip -Force
  63. $remoteZip = 'C:\Windows\Temp\' + $zipName
  64. $remoteApplyScript = Join-Path $PSScriptRoot 'deploy-iis-remote-apply.ps1'
  65. $remoteApplyDest = 'C:\Windows\Temp\deploy-iis-remote-apply.ps1'
  66. Write-Host "Copying release to $RemoteTarget"
  67. & $ScpExe -P $RemotePort $localZip "${RemoteTarget}:$remoteZip"
  68. if($LASTEXITCODE -ne 0){ throw 'scp of release zip failed' }
  69. & $ScpExe -P $RemotePort $remoteApplyScript "${RemoteTarget}:$remoteApplyDest"
  70. if($LASTEXITCODE -ne 0){ throw 'scp of remote-apply script failed' }
  71. # --- 3. Apply on the remote host ---
  72. $remoteCommandParts = @(
  73. 'powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass',
  74. '-File', ('"' + $remoteApplyDest + '"'),
  75. '-ZipPath', ('"' + $remoteZip + '"'),
  76. '-RemoteDir', ('"' + $RemoteDir + '"'),
  77. '-SiteName', ('"' + $SiteName + '"'),
  78. '-AppPool', ('"' + $AppPool + '"'),
  79. '-DbPath', ('"' + $DbPath + '"')
  80. )
  81. if($RunMigrations){ $remoteCommandParts += '-RunMigrations' }
  82. Write-Host "Applying release on $RemoteTarget"
  83. & $SshExe -p $RemotePort $RemoteTarget ($remoteCommandParts -join ' ')
  84. if($LASTEXITCODE -ne 0){ throw 'remote apply failed' }
  85. # --- 4. Local cleanup ---
  86. Remove-Item $localZip -ErrorAction SilentlyContinue
  87. Remove-Item -Recurse -Force $outDir -ErrorAction SilentlyContinue
  88. # --- 5. Smoke test ---
  89. Write-Host 'Smoke testing...'
  90. $paths = @('/', '/request-order', '/404')
  91. foreach($path in $paths){
  92. $url = $BaseUrl.TrimEnd('/') + $path
  93. $response = Invoke-WebRequest -UseBasicParsing -Uri $url -TimeoutSec 30
  94. Write-Host ("OK " + $path + ' -> ' + $response.StatusCode)
  95. }
  96. Write-Host 'Deploy complete.'

Powered by TurnKey Linux.