ASP Classic blog framework - BrainOrdure
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

186 lignes
6.8KB

  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", "scripts")) {
  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.mdb 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.mdb")) {
  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.Jet.OLEDB.4.0;Data Source=$WEBROOT\db\webdata.mdb;Persist Security Info=False;"
  99. $wc = [regex]::Replace($wc, 'Provider=Microsoft\.(ACE\.OLEDB\.12\.0|Jet\.OLEDB\.4\.0)[^"]+', $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. # Create webdata.mdb if it doesn't exist (use 32-bit cscript — JET 4.0 is 32-bit only)
  107. $mdbPath = "$WEBROOT\db\webdata.mdb"
  108. if (-not (Test-Path $mdbPath)) {
  109. Log "Creating empty webdata.mdb via ADOX (32-bit cscript)..."
  110. $tmpVbs = "C:\Scripts\create_mdb_tmp.vbs"
  111. @"
  112. Dim cat
  113. Set cat = CreateObject("ADOX.Catalog")
  114. cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$mdbPath;"
  115. Set cat = Nothing
  116. WScript.Quit 0
  117. "@ | Out-File -FilePath $tmpVbs -Encoding ASCII
  118. & "C:\Windows\SysWOW64\cscript.exe" "//nologo" $tmpVbs
  119. Remove-Item $tmpVbs -Force -ErrorAction SilentlyContinue
  120. if (Test-Path $mdbPath) {
  121. Log "Created webdata.mdb."
  122. } else {
  123. Log "ERROR: Failed to create webdata.mdb"
  124. exit 1
  125. }
  126. }
  127. # Run database migrations (32-bit cscript required for JET OLEDB)
  128. $migrationsVbs = Join-Path $WEBROOT "scripts\runMigrations.vbs"
  129. if (Test-Path $migrationsVbs) {
  130. Log "Running database migrations..."
  131. $output = & "C:\Windows\SysWOW64\cscript.exe" "//nologo" $migrationsVbs "up" 2>&1
  132. $output | ForEach-Object { Log " [migrate] $_" }
  133. if ($LASTEXITCODE -ne 0) {
  134. Log "ERROR: Migration failed (exit code $LASTEXITCODE)"
  135. exit 1
  136. }
  137. Log "Migrations complete."
  138. }
  139. # Grant IIS_IUSRS write access to db folder
  140. $dbPath = Join-Path $WEBROOT "db"
  141. New-Item -ItemType Directory -Force -Path $dbPath | Out-Null
  142. if (Test-Path $dbPath) {
  143. $acl = Get-Acl $dbPath
  144. $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS_IUSRS", "Modify", "ContainerInherit,ObjectInherit", "None", "Allow")
  145. $acl.SetAccessRule($rule)
  146. Set-Acl $dbPath $acl
  147. Log "Set IIS_IUSRS Modify on db folder."
  148. }
  149. # Recycle app pool
  150. Import-Module WebAdministration -ErrorAction SilentlyContinue
  151. try {
  152. Restart-WebAppPool $APPPOOL
  153. Log "Recycled app pool $APPPOOL."
  154. } catch {
  155. Log "WARNING: Could not recycle app pool: $_"
  156. }
  157. # Cleanup
  158. Remove-Item $tmpDir -Recurse -Force
  159. Remove-Item $zipPath -Force
  160. # Save new commit hash
  161. $latestCommit | Out-File -FilePath $STATEFILE -NoNewline
  162. Log "Deploy complete. Commit: $($latestCommit.Substring(0,8))"

Powered by TurnKey Linux.