@@ -5,13 +5,19 @@ Generates Dockerfile contents for Internet Information Services (IIS) feature
55
66. PARAMETER ManifestPath
77The filesystem path where the JSON manifests are stored.
8+
9+ . PARAMETER ArtifactParam
10+ Optional - one or more Website names to include in the output.
811#>
912[Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSShouldProcess" , ' ' )]
1013[Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSUseDeclaredVarsMoreThanAssignments" , ' ' )]
1114[CmdletBinding ()]
1215param (
1316 [Parameter (Mandatory = $true )]
14- [string ] $ManifestPath
17+ [string ] $ManifestPath ,
18+
19+ [Parameter (Mandatory = $false )]
20+ [string []] $ArtifactParam
1521)
1622
1723$ArtifactName = Split-Path - Path $PSScriptRoot - Leaf
@@ -25,40 +31,51 @@ if ($Artifact.Status -eq 'Present') {
2531 Write-Verbose (' Copying {0} configuration files' -f $ArtifactName )
2632 $ConfigPath = $MountPath + " \" + " Windows\System32\inetsrv\config"
2733 Copy-Item $ConfigPath $ManifestPath - Recurse
28- $Result = " RUN Enable-WindowsOptionalFeature -Online -FeatureName $ ( $Artifact.FeatureName.Replace (' ;' , ' ,' )) ; `` "
29- $EndOfLine = " `r`n "
30- $Add = " `r`n "
31- $Expose = ' EXPOSE '
32- $ExposePorts = New-Object System.Collections.ArrayList
33- $ExposeText = ' '
34- [int ]$SiteCount = $Artifact.Websites.Count ;
35- for ($i = 0 ;$i -lt $SiteCount ;$i ++ ) {
36- Write-Verbose - Message (' Creating new website for {0} site' -f $Artifact.Websites [$i ].Name)
37- $SitePath = $MountPath + $Artifact.Websites [$i ].PhysicalPath
38- $Result += $EndOfLine
39- $Result += ' New-Item -Path {0} -ItemType directory -Force; `' -f $Artifact.Websites [$i ].PhysicalPath
40- $Result += $EndOfLine
41- $Result += ' New-Website -Name '' {0}'' -PhysicalPath "{1}" -Port {2} -Force; `' -f ($Artifact.Websites [$i ].Name -replace " '" , " ''" ), $Artifact.Websites [$i ].PhysicalPath, $Artifact.Websites [$i ].binding.bindingInformation.split(' :' )[-2 ]
42- $ExposePorts.Add ($Artifact.Websites [$i ].binding.bindingInformation.split(' :' )[-2 ]) | Out-Null
43- Write-Verbose - Message (' Copying files for {0} site' -f $Artifact.Websites [$i ].Name)
44- Copy-Item $SitePath $ManifestPath - Recurse
45- $Add += " ADD {0} {1}`r`n " -f (Split-Path $Artifact.Websites [$i ].PhysicalPath - Leaf), ($Artifact.Websites [$i ].PhysicalPath -Replace " \\" , " /" )
34+
35+ $ResultBuilder = New-Object System.Text.StringBuilder
36+
37+ Write-Verbose - Message (' Writing instruction to install IIS' )
38+ $null = $ResultBuilder.AppendLine (' # Install Windows features for IIS' )
39+ $null = $ResultBuilder.Append (' RUN Add-WindowsFeature Web-server' )
40+ if ($Artifact.AspNetStatus -eq ' Present' ) {
41+ Write-Verbose - Message (' Writing instruction to install ASP.NET' )
42+ $null = $ResultBuilder.Append (' , NET-Framework-45-ASPNET, Web-Asp-Net45' )
4643 }
44+ $null = $ResultBuilder.AppendLine (' ' )
45+ $null = $ResultBuilder.AppendLine (" RUN Enable-WindowsOptionalFeature -Online -FeatureName $ ( $Artifact.FeatureName.Replace (' ;' , ' ,' )) " )
4746
48- $Result += $EndOfLine
49- # ## Add IIS HTTP handlers to the Dockerfile
50- foreach ($HttpHandler in $Artifact.HttpHandlers ) {
51- $Result += ' New-WebHandler -Name "{0}" -Path "{1}" -Verb "{2}" `' -f $HttpHandler.Name , $HttpHandler.Path , $HttpHandler.Verb
52- $Result += $EndOfLine
53- }
54- $Add += " ADD config Windows/System32/inetsrv/"
47+ if ($Artifact.HttpHandlers.Count > 0 ) {
48+ Write-Verbose - Message (' Writing instruction to add HTTP handlers' )
49+ $null = $ResultBuilder.Append (' RUN ' )
50+ foreach ($HttpHandler in $Artifact.HttpHandlers ) {
51+ $null = $ResultBuilder.AppendLine (' New-WebHandler -Name "{0}" -Path "{1}" -Verb "{2}" `' -f $HttpHandler.Name , $HttpHandler.Path , $HttpHandler.Verb )
52+ }
53+ }
54+ $null = $ResultBuilder.AppendLine (' ' )
5555
56- $ExposeText += $EndOfLine
57- $ExposePorts.ForEach {$ExposeText += " $Expose $_ $EndOfLine " }
58- $endOutput = ($Result + $Add + $ExposeText )
59- Write-Output $endOutput - NoEnumerate
60-
56+ for ($i = 0 ;$i -lt $Artifact.Websites.Count ;$i ++ ) {
57+ $Site = $Artifact.Websites [$i ]
58+ Write-Verbose - Message (' Writing instruction to copy files for {0} site' -f $Site.Name )
59+ $null = $ResultBuilder.AppendLine (" # Set up website: $ ( $Site.Name ) " )
60+ $SitePath = $MountPath + $Site.PhysicalPath
61+ Copy-Item $SitePath $ManifestPath - Recurse
62+ $copy = " COPY {0} {1}" -f (Split-Path $Site.PhysicalPath - Leaf), ($Site.PhysicalPath -Replace " \\" , " /" )
63+ $null = $ResultBuilder.AppendLine ($copy )
64+
65+ Write-Verbose - Message (' Writing instruction to create site {0}' -f $Site.Name )
66+ $newSite = ' RUN New-Website -Name '' {0}'' -PhysicalPath "C:{1}" -Port {2} -Force' -f ($Site.Name -replace " '" , " ''" ), $Site.PhysicalPath , $Site.binding.bindingInformation.split (' :' )[-2 ]
67+ $null = $ResultBuilder.AppendLine ($newSite )
68+
69+ Write-Verbose - Message (' Writing instruction to expose port for site {0}' -f $Site.Name )
70+ $null = $ResultBuilder.AppendLine (" EXPOSE $ ( $Site.binding.bindingInformation.split (' :' )[-2 ]) " )
71+ $null = $ResultBuilder.AppendLine (' ' )
72+ }
73+
74+ $null = $ResultBuilder.AppendLine (' CMD /Wait-Service.ps1 -ServiceName W3SVC -AllowServiceRestart' )
6175}
6276
77+
78+ Write-Output $ResultBuilder.ToString () - NoEnumerate
79+
6380}
6481
0 commit comments