This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Generate_IIS.ps1
62 lines (52 loc) · 2.61 KB
/
Generate_IIS.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Function Generate_IIS {
<#
.SYNOPSIS
Generates Dockerfile contents for Internet Information Services (IIS) feature
.PARAMETER ManifestPath
The filesystem path where the JSON manifests are stored.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $ManifestPath
)
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
Write-Verbose -Message ('Generating result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
if ($Artifact.Status -eq 'Present') {
Write-Verbose ('Copying {0} configuration files' -f $ArtifactName)
$ConfigPath = $MountPath + "\" + "Windows\System32\inetsrv\config"
Copy-Item $ConfigPath $ManifestPath -Recurse
$Result = "RUN Enable-WindowsOptionalFeature -Online -FeatureName $($Artifact.FeatureName.Replace(';',',')) ; ``"
$EndOfLine = "`r`n"
$Add = "`r`n"
$Expose = 'EXPOSE '
$ExposePorts = New-Object System.Collections.ArrayList
$ExposeText = ''
[int]$SiteCount = $Artifact.Websites.Count;
for ($i=0;$i -lt $SiteCount;$i++) {
Write-Verbose -Message ('Creating new website for {0} site' -f $Artifact.Websites[$i].Name)
$SitePath = $MountPath + $Artifact.Websites[$i].PhysicalPath
$Result += $EndOfLine
$Result += 'New-Item -Path {0} -ItemType directory -Force; `' -f $Artifact.Websites[$i].PhysicalPath
$Result += $EndOfLine
$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]
$ExposePorts.Add($Artifact.Websites[$i].binding.bindingInformation.split(':')[-2]) | Out-Null
Write-Verbose -Message ('Copying files for {0} site' -f $Artifact.Websites[$i].Name)
Copy-Item $SitePath $ManifestPath -Recurse
$Add += "ADD {0} {1}`r`n" -f (Split-Path $Artifact.Websites[$i].PhysicalPath -Leaf),($Artifact.Websites[$i].PhysicalPath -Replace "\\","/")
}
$Result += $EndOfLine
### Add IIS HTTP handlers to the Dockerfile
foreach ($HttpHandler in $Artifact.HttpHandlers) {
$Result += 'New-WebHandler -Name "{0}" -Path "{1}" -Verb "{2}" `' -f $HttpHandler.Name, $HttpHandler.Path, $HttpHandler.Verb
$Result += $EndOfLine
}
$Add += "ADD config Windows/System32/inetsrv/"
$ExposeText += $EndOfLine
$ExposePorts.ForEach{$ExposeText += "$Expose $_ $EndOfLine" }
$endOutput = ($Result + $Add + $ExposeText)
Write-Output $endOutput -NoEnumerate
}
}