ASP Classic blog framework - BrainOrdure
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

151 wiersze
5.6KB

  1. # deploy-aspblogbrainordure-test.ps1
  2. # Polls Gitea for new commits on master; deploys ASPBlogBrainOrdure to test site if changed
  3. # Scheduled Task: ASPBlogBrainOrdure-Test-Deploy (every 5 minutes)
  4. $GITEA = "https://onefortheroadgit.sytes.net"
  5. $REPO = "dcovington/ASPBlogBrainOrdure"
  6. $TOKEN = "bac7c4befba3f0428e8786020cddb5e9595a6838"
  7. $WEBROOT = "C:\inetpub\wwwroot\aspblogbrainordure-test"
  8. $APPPOOL = "aspblogbrainordure-test"
  9. $STATEFILE = "C:\Scripts\.aspblog-last-commit"
  10. $LOGFILE = "C:\Scripts\aspblog-deploy.log"
  11. function Log($msg) {
  12. $ts = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
  13. "$ts $msg" | Out-File -Append -FilePath $LOGFILE
  14. Write-Host "$ts $msg"
  15. }
  16. # SSL bypass for self-signed cert
  17. Add-Type -TypeDefinition "using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAll : ICertificatePolicy { public bool CheckValidationResult(ServicePoint sp, X509Certificate cert, WebRequest req, int problem) { return true; } }"
  18. [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAll
  19. [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
  20. Log "Checking for new commits on $REPO master..."
  21. # Get current master commit hash
  22. try {
  23. $headers = @{ "Authorization" = "token $TOKEN" }
  24. $branchUrl = "$GITEA/api/v1/repos/$REPO/branches/master"
  25. $resp = Invoke-WebRequest -Uri $branchUrl -Headers $headers -UseBasicParsing
  26. $branch = $resp.Content | ConvertFrom-Json
  27. $latestCommit = $branch.commit.id
  28. } catch {
  29. Log "ERROR fetching branch info: $_"
  30. exit 1
  31. }
  32. # Compare with last deployed commit
  33. $lastCommit = ""
  34. if (Test-Path $STATEFILE) { $lastCommit = (Get-Content $STATEFILE -Raw).Trim() }
  35. if ($latestCommit -eq $lastCommit) {
  36. Log "No changes (commit $($latestCommit.Substring(0,8))). Nothing to do."
  37. exit 0
  38. }
  39. Log "New commit detected: $($latestCommit.Substring(0,8)). Deploying..."
  40. # Download archive
  41. $archiveUrl = "$GITEA/api/v1/repos/$REPO/archive/master.zip"
  42. $zipPath = "C:\Scripts\aspblog-deploy.zip"
  43. try {
  44. $wc = New-Object System.Net.WebClient
  45. $wc.Headers.Add("Authorization", "token $TOKEN")
  46. $wc.DownloadFile($archiveUrl, $zipPath)
  47. Log "Downloaded archive."
  48. } catch {
  49. Log "ERROR downloading archive: $_"
  50. exit 1
  51. }
  52. # Extract to temp folder
  53. $tmpDir = "C:\Scripts\aspblog-tmp"
  54. if (Test-Path $tmpDir) { Remove-Item $tmpDir -Recurse -Force }
  55. New-Item -ItemType Directory -Path $tmpDir | Out-Null
  56. Add-Type -AssemblyName System.IO.Compression.FileSystem
  57. [System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $tmpDir)
  58. # Find the extracted subfolder (Gitea puts files in a subfolder)
  59. $extracted = Get-ChildItem $tmpDir -Directory | Select-Object -First 1
  60. if (-not $extracted) { Log "ERROR: No directory found in archive."; exit 1 }
  61. $srcPath = $extracted.FullName
  62. Log "Extracted to $srcPath"
  63. # Deploy structure mirrors the repo layout:
  64. # IIS serves from $WEBROOT\public\ (Default.asp lives here)
  65. # core\, app\, db\ go alongside public\ so ../core/ includes resolve correctly
  66. $publicDst = Join-Path $WEBROOT "public"
  67. New-Item -ItemType Directory -Force -Path $publicDst | Out-Null
  68. foreach ($folder in @("public", "core", "app")) {
  69. $folderSrc = Join-Path $srcPath $folder
  70. $folderDst = Join-Path $WEBROOT $folder
  71. if (Test-Path $folderSrc) {
  72. if (Test-Path $folderDst) { Remove-Item $folderDst -Recurse -Force }
  73. Copy-Item $folderSrc $WEBROOT -Recurse -Force
  74. Log "Copied $folder/."
  75. }
  76. }
  77. # Only update db/ if webdata.accdb doesn't exist yet (preserve live data)
  78. $dbSrc = Join-Path $srcPath "db"
  79. $dbDst = Join-Path $WEBROOT "db"
  80. if (Test-Path $dbSrc) {
  81. if (-not (Test-Path "$dbDst\webdata.accdb")) {
  82. if (Test-Path $dbDst) { Remove-Item $dbDst -Recurse -Force }
  83. Copy-Item $dbSrc $WEBROOT -Recurse -Force
  84. Log "Copied db/ (first deploy)."
  85. } else {
  86. # Only copy migration files, not the live database
  87. $migSrc = Join-Path $dbSrc "migrations"
  88. if (Test-Path $migSrc) {
  89. Copy-Item "$migSrc\*" "$dbDst\migrations\" -Recurse -Force
  90. Log "Updated db/migrations/."
  91. }
  92. }
  93. }
  94. # Update web.config ConnectionString to point to correct DB path
  95. $webConfigPath = Join-Path $publicDst "web.config"
  96. if (Test-Path $webConfigPath) {
  97. $wc = [System.IO.File]::ReadAllText($webConfigPath)
  98. $newConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$WEBROOT\db\webdata.accdb;Persist Security Info=False;"
  99. $wc = [regex]::Replace($wc, 'Provider=Microsoft\.ACE\.OLEDB[^"]+', $newConn)
  100. if ($wc -notmatch 'enableParentPaths') {
  101. $wc = $wc -replace '<system.webServer>', '<system.webServer><asp enableParentPaths="true" />'
  102. }
  103. [System.IO.File]::WriteAllText($webConfigPath, $wc)
  104. Log "Updated web.config."
  105. }
  106. # Grant IIS_IUSRS write access to db folder
  107. $dbPath = Join-Path $WEBROOT "db"
  108. New-Item -ItemType Directory -Force -Path $dbPath | Out-Null
  109. if (Test-Path $dbPath) {
  110. $acl = Get-Acl $dbPath
  111. $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS_IUSRS", "Modify", "ContainerInherit,ObjectInherit", "None", "Allow")
  112. $acl.SetAccessRule($rule)
  113. Set-Acl $dbPath $acl
  114. Log "Set IIS_IUSRS Modify on db folder."
  115. }
  116. # Recycle app pool
  117. Import-Module WebAdministration -ErrorAction SilentlyContinue
  118. try {
  119. Restart-WebAppPool $APPPOOL
  120. Log "Recycled app pool $APPPOOL."
  121. } catch {
  122. Log "WARNING: Could not recycle app pool: $_"
  123. }
  124. # Cleanup
  125. Remove-Item $tmpDir -Recurse -Force
  126. Remove-Item $zipPath -Force
  127. # Save new commit hash
  128. $latestCommit | Out-File -FilePath $STATEFILE -NoNewline
  129. Log "Deploy complete. Commit: $($latestCommit.Substring(0,8))"

Powered by TurnKey Linux.