diff --git a/scripts/deploy-iis-git.ps1 b/scripts/deploy-iis-git.ps1 index 82b6aeb..d739445 100644 --- a/scripts/deploy-iis-git.ps1 +++ b/scripts/deploy-iis-git.ps1 @@ -14,9 +14,9 @@ [CmdletBinding()] param( [ValidatePattern('^[A-Za-z0-9_. -]+$')] - [string]$SiteName = 'PostcardMojo', + [string]$SiteName = 'postcardmojo.com', [ValidatePattern('^[A-Za-z0-9_. -]+$')] - [string]$AppPoolName = 'PostcardMojo', + [string]$AppPoolName = 'postcardmojo.com', [string]$DeployRoot = 'C:\inetpub\postcardmojo', [string]$BindingIpAddress = '192.168.1.115', [ValidateRange(1, 65535)] @@ -38,6 +38,7 @@ param( [switch]$AllowAnyBranch, [switch]$AllowDirty, [switch]$RunMigrations, + [switch]$AdoptExisting, [switch]$SkipSmokeTest, [Alias('HostPreflightOnly', 'RemotePreflightOnly')] [switch]$PreflightOnly, @@ -199,6 +200,7 @@ if ($ReleaseId -notmatch '^[A-Za-z0-9._-]+$') { throw 'ReleaseId contains unsupp if ($Rollback -and [string]::IsNullOrWhiteSpace($RollbackTo)) { throw '-Rollback requires -RollbackTo.' } if ((-not $Rollback) -and -not [string]::IsNullOrWhiteSpace($RollbackTo)) { throw '-RollbackTo requires -Rollback.' } if ($RunMigrations -and $Rollback) { throw '-RunMigrations is not valid during rollback.' } +if ($AdoptExisting -and $Rollback) { throw '-AdoptExisting is not valid during rollback.' } if (($PreflightOnly -or $LocalPreflightOnly) -and $Rollback) { throw 'Preflight modes cannot be combined with -Rollback.' } @@ -257,6 +259,7 @@ try { Add-RemoteArgument $remoteArguments '-ExpectedSha256' $sha256 } if ($RunMigrations) { $remoteArguments.Add('-RunMigrations') } + if ($AdoptExisting) { $remoteArguments.Add('-AdoptExisting') } if ($SkipSmokeTest) { $remoteArguments.Add('-SkipSmokeTest') } $remoteScript = $remoteArguments -join ' ' diff --git a/scripts/install-iis-release.ps1 b/scripts/install-iis-release.ps1 index e754b31..bef4b5a 100644 --- a/scripts/install-iis-release.ps1 +++ b/scripts/install-iis-release.ps1 @@ -13,9 +13,9 @@ [CmdletBinding(DefaultParameterSetName = 'Deploy')] param( [ValidatePattern('^[A-Za-z0-9_. -]+$')] - [string]$SiteName = 'PostcardMojo', + [string]$SiteName = 'postcardmojo.com', [ValidatePattern('^[A-Za-z0-9_. -]+$')] - [string]$AppPoolName = 'PostcardMojo', + [string]$AppPoolName = 'postcardmojo.com', [string]$DeployRoot = 'C:\inetpub\postcardmojo', [string]$BindingIpAddress = '192.168.1.115', [ValidateRange(1, 65535)] @@ -39,6 +39,7 @@ param( [string]$ExpectedSha256 = '', [switch]$RunMigrations, [switch]$SkipSmokeTest, + [switch]$AdoptExisting, [switch]$PreflightOnly, [switch]$DryRun ) @@ -204,14 +205,19 @@ function Get-TargetState { } $physicalPath = Get-NormalizedPath $site.physicalPath $releasesRoot = Join-Path $DeployRoot 'releases' - if (-not (Test-PathUnderRoot -Path $physicalPath -Root $releasesRoot) -or - -not $physicalPath.EndsWith('\public', [StringComparison]::OrdinalIgnoreCase)) { - throw "Existing target physicalPath is outside this pipeline's release public directories: $physicalPath" + $managedPath = (Test-PathUnderRoot -Path $physicalPath -Root $releasesRoot) -and + $physicalPath.EndsWith('\public', [StringComparison]::OrdinalIgnoreCase) + if (-not $managedPath -and -not $AdoptExisting) { + throw "Existing target physicalPath is outside this pipeline's release public directories: $physicalPath. Pass -AdoptExisting for a one-time adoption of this site." } if (-not (Test-Path -LiteralPath $physicalPath -PathType Container)) { throw "Existing target physicalPath does not exist: $physicalPath" } - Assert-ReleaseLayout -ReleasePath (Split-Path -Parent $physicalPath) + if ($managedPath) { + Assert-ReleaseLayout -ReleasePath (Split-Path -Parent $physicalPath) + } else { + Write-Warning "Adopting existing site at unmanaged path $physicalPath; its first release will be switched in by this deployment." + } $parentPaths = (Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Location $SiteName -Filter 'system.webServer/asp' -Name 'enableParentPaths').Value return [pscustomobject]@{ Exists = $true; Site = $site; PhysicalPath = $physicalPath; ParentPaths = [bool]$parentPaths @@ -292,6 +298,7 @@ if ($env:OS -ne 'Windows_NT') { throw 'This script must run on Windows.' } Assert-Administrator Import-Module WebAdministration -ErrorAction Stop Assert-DeploymentInputs +if ($AdoptExisting -and $PSCmdlet.ParameterSetName -eq 'Rollback') { throw '-AdoptExisting is not valid during rollback.' } $DeployRoot = Get-NormalizedPath $DeployRoot Assert-DeployRoot -Path $DeployRoot if (-not [string]::IsNullOrWhiteSpace($InitialWebConfigPath)) {