Skip to content
This repository was archived by the owner on Mar 11, 2020. It is now read-only.

Commit 7dff54b

Browse files
committed
IIS - copy files only for included sites
Signed-off-by: Elton Stoneman <elton@sixeyed.com>
1 parent b496b47 commit 7dff54b

File tree

14 files changed

+156
-141
lines changed

14 files changed

+156
-141
lines changed

Functions/Private/Artifacts/AddRemovePrograms/Generate_AddRemovePrograms.ps1

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@ param (
1212
[string] $ManifestPath
1313
)
1414

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
15+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
1616

17-
Write-Verbose -Message ('Generating Dockerfile result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
18-
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
17+
Write-Verbose -Message ('Generating Dockerfile result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
18+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
1919

20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
20+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2121

22-
$Result = ''
23-
foreach ($Item in $Artifact) {
24-
$Result += '# {0} {1}' -f $Item, "`r`n"
25-
}
26-
27-
Write-Output -InputObject $Result
22+
$ResultBuilder = GetDockerfileBuilder
23+
foreach ($Item in $Artifact) {
24+
$null = $ResultBuilder.AppendLine("# $Item")
25+
}
2826

27+
return $ResultBuilder.ToString()
2928
}
3029

Functions/Private/Artifacts/AllWindowsFeatures/Generate_AllWindowsFeatures.ps1

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@ param (
1212
[string] $ManifestPath
1313
)
1414

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
15+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
1616

17-
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
18-
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
17+
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
18+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
1919

20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
20+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
21+
$FeatureNames = $Artifact.FeatureName.replace(';',',')
2122

22-
$Result =''
23+
$ResultBuilder = GetDockerfileBuilder
24+
$null = $ResultBuilder.AppendLine("RUN Enable-WindowsOptionalFeature -Online -FeatureName $FeatureNames -All")
2325

24-
$FeatureNames = $Artifact.FeatureName.replace(';',',')
25-
26-
$Result += "RUN powershell.exe -ExecutionPolicy Bypass -Command Enable-WindowsOptionalFeature -Online -FeatureName $FeatureNames -All `r`n"
27-
28-
29-
Write-Output -InputObject $Result
26+
return $ResultBuilder.ToString()
3027
}
3128

Functions/Private/Artifacts/Apache/Generate_Apache.ps1

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ param (
1212
[string] $ManifestPath
1313
)
1414

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
15+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
1616

17-
Write-Verbose -Message ('Generating result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
18-
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
17+
Write-Verbose -Message ('Generating result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
18+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
1919

20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
20+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2121

22-
if ($Artifact.Status -eq 'Present') {
23-
$Result = '
24-
LABEL Description="Apache" Vendor="Docker Inc." Version="2.4.23"
25-
26-
RUN mkdir $env:SystemDrive\Apache; `
27-
Invoke-WebRequest -Uri https://www.apachelounge.com/download/VC14/binaries/httpd-2.4.23-win64-VC14.zip -OutFile $env:TEMP\apache.zip; `
28-
Expand-Archive -Path $env:TEMP\apache.zip -DestinationPath c:\apache; `
29-
Remove-Item -Path $env:TEMP\Apache.zip
30-
31-
ENTRYPOINT ["c:\apache\apache24\bin\httpd.exe", "-w"]'
32-
33-
Write-Verbose -Message ('Artifact is present: {0}. Adding text to Dockerfile {1}.' -f $ArtifactName, $Result)
34-
}
22+
$ResultBuilder = GetDockerfileBuilder
23+
if ($Artifact.Status -eq 'Present') {
24+
$null = $ResultBuilder.AppendLine('LABEL Description="Apache" Vendor="Docker Inc." Version="2.4.23"')
25+
26+
$null = $ResultBuilder.AppendLine('RUN mkdir $env:SystemDrive\Apache; ``')
27+
$null = $ResultBuilder.AppendLine(' Invoke-WebRequest -Uri https://www.apachelounge.com/download/VC14/binaries/httpd-2.4.23-win64-VC14.zip -OutFile $env:TEMP\apache.zip; ``')
28+
$null = $ResultBuilder.AppendLine(' Expand-Archive -Path $env:TEMP\apache.zip -DestinationPath c:\apache; ``')
29+
$null = $ResultBuilder.AppendLine(' Remove-Item -Path $env:TEMP\Apache.zip')
30+
31+
$null = $ResultBuilder.AppendLine('ENTRYPOINT ["c:\apache\apache24\bin\httpd.exe", "-w"]')
32+
33+
Write-Verbose -Message ('Artifact is present: {0}. Adding text to Dockerfile {1}.' -f $ArtifactName, $Result)
34+
}
3535

36-
Write-Output -InputObject $Result
36+
return $ResultBuilder.ToString()
3737
}
3838

Functions/Private/Artifacts/DHCPServer/Generate_DHCPServer.ps1

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@ param (
1212
[string] $ManifestPath
1313
)
1414

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
15+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
1616

17-
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
18-
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
17+
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
18+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
1919

20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
20+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2121

22-
if ($Artifact.Status -eq 'Present') {
23-
$Result =
24-
'RUN Enable-WindowsOptionalFeature -Online -FeatureName DHCPServer
22+
$ResultBuilder = GetDockerfileBuilder
23+
if ($Artifact.Status -eq 'Present') {
24+
$null = $ResultBuilder.AppendLine('RUN Enable-WindowsOptionalFeature -Online -FeatureName DHCPServer')
25+
$null = $ResultBuilder.AppendLine('EXPOSE 67 2535')
26+
$null = $ResultBuilder.AppendLine('CMD /Wait-Service.ps1 -ServiceName DHCPServer -AllowServiceRestart')
27+
}
2528

26-
EXPOSE 67 2535
27-
28-
CMD /Wait-Service.ps1 -ServiceName DHCPServer -AllowServiceRestart'
29-
}
30-
31-
Write-Output -InputObject $Result
29+
return $ResultBuilder.ToString()
3230
}
3331

Functions/Private/Artifacts/DNSServer/Generate_DNSServer.ps1

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ param (
1212
[string] $ManifestPath
1313
)
1414

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
15+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
1616

17-
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
18-
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
17+
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
18+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
1919

20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
20+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2121

22-
if ($Artifact.Status -eq 'Enabled') {
23-
$Result =
24-
'RUN Enable-WindowsOptionalFeature -Online -FeatureName DNS-Server-Full-Role
25-
26-
EXPOSE 53
27-
28-
CMD /Wait-Service.ps1 -ServiceName DNS -AllowServiceRestart'
29-
}
30-
31-
Write-Output -InputObject $Result
32-
}
22+
$ResultBuilder = GetDockerfileBuilder
23+
if ($Artifact.Status -eq 'Enabled') {
24+
$null = $ResultBuilder.AppendLine('RUN Enable-WindowsOptionalFeature -Online -FeatureName DNS-Server-Full-Role')
25+
$null = $ResultBuilder.AppendLine('EXPOSE 53')
26+
$null = $ResultBuilder.AppendLine('CMD /Wait-Service.ps1 -ServiceName DNS -AllowServiceRestart')
27+
}
3328

29+
return $ResultBuilder.ToString()
30+
}

Functions/Private/Artifacts/IIS/Generate_IIS.ps1

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,35 @@ function IncludePath([string[]] $pathParts) {
3636
return $false
3737
}
3838

39+
function ProcessDirectory([System.Text.StringBuilder] $DirectoryBuilder,
40+
[System.Text.StringBuilder] $CopyBuilder,
41+
[string] $SourcePath,
42+
[bool] $FirstDirectory) {
43+
Write-Verbose "Processing source directory: $SourcePath"
44+
if ($FirstDirectory -eq $true) {
45+
$newPath = "RUN New-Item -Path 'C:$SourcePath' -Type Directory -Force; ``"
46+
}
47+
else {
48+
$newPath = " New-Item -Path 'C:$SourcePath' -Type Directory -Force; ``"
49+
}
50+
$null = $DirectoryBuilder.AppendLine($newPath)
51+
52+
$copy = 'COPY ["{0}", "{1}"]' -f (Split-Path $SourcePath -Leaf),($sourcePath -Replace "\\","/")
53+
$null = $CopyBuilder.AppendLine($copy)
54+
55+
$fullSourcePath = $Mount.Path + $SourcePath
56+
Copy-Item $fullSourcePath $ManifestPath -Recurse -Force
57+
}
58+
3959
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
4060

4161
Write-Verbose -Message ('Generating result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
4262
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
43-
$ResultBuilder = New-Object System.Text.StringBuilder
63+
$ResultBuilder = GetDockerfileBuilder
4464

4565
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
4666

47-
if ($Artifact.Status -eq 'Present') {
48-
$DockerfileTemplate = 'Dockerfile-IIS.template'
67+
if ($Artifact.Status -eq 'Present') {
4968
Write-Verbose ('Copying {0} configuration files' -f $ArtifactName)
5069
$ConfigPath = $Mount.Path + "\" + "Windows\System32\inetsrv\config"
5170
if (Test-Path -Path $ConfigPath) {
@@ -57,8 +76,7 @@ if ($Artifact.Status -eq 'Present') {
5776
if ($Artifact.AspNet35Status -eq 'Present') {
5877
$DockerfileTemplate = 'Dockerfile-ASPNET-35.template'
5978
}
60-
$Dockerfile = Get-Content -Raw -Path "$ModulePath\Resources\$DockerfileTemplate"
61-
$null = $ResultBuilder.AppendLine($Dockerfile.Trim())
79+
$ResultBuilder = GetDockerfileBuilder($DockerfileTemplate)
6280

6381
if ($Artifact.FeatureName.length -gt 0) {
6482
$null = $ResultBuilder.AppendLine("RUN Enable-WindowsOptionalFeature -Online -FeatureName $($Artifact.FeatureName.Replace(';',','))")
@@ -99,19 +117,16 @@ if ($Artifact.Status -eq 'Present') {
99117

100118
Write-Verbose -Message ('Writing instruction to create site {0}' -f $Site.Name)
101119

102-
# create empty paths for all the site directories
120+
# process the main site path
103121
$DirectoryBuilder = New-Object System.Text.StringBuilder
104122
$CopyBuilder = New-Object System.Text.StringBuilder
105-
$newPath = "RUN New-Item -Path 'C:$($mainVirtualDir.PhysicalPath)' -Type Directory; ``"
106-
$null = $DirectoryBuilder.AppendLine($newPath)
123+
ProcessDirectory -DirectoryBuilder $DirectoryBuilder -CopyBuilder $CopyBuilder -SourcePath $mainVirtualDir.PhysicalPath -FirstDirectory $true
107124

108125
# creating the website creates the default app & vdir underneath it
109126
$sourcePath = $mainVirtualDir.PhysicalPath
110127
$newSite = "RUN New-Website -Name '$($Site.Name)' -PhysicalPath 'C:$sourcePath' -Port $($mainBinding.BindingInformation.split(':')[-2]) -Force; ``"
111128
$AppBuilder = New-Object System.Text.StringBuilder
112129
$null = $AppBuilder.AppendLine($newSite)
113-
$copy = "COPY {0} {1}" -f (Split-Path $sourcePath -Leaf),($sourcePath -Replace "\\","/")
114-
$null = $CopyBuilder.AppendLine($copy)
115130

116131
# now create additional apps and vdirs
117132
ForEach ($application in $Site.Applications) {
@@ -129,12 +144,8 @@ if ($Artifact.Status -eq 'Present') {
129144
$sourcePath = $appVirtualDir.PhysicalPath
130145
$newApp = " New-WebApplication -Name '$appName' -Site '$($Site.Name)' -PhysicalPath 'C:$sourcePath' -Force; ``"
131146
$null = $AppBuilder.AppendLine($newApp)
132-
if ($sourcePath -ne $mainVirtualDir.PhysicalPath) {
133-
$newPath = " New-Item -Path 'C:$sourcePath' -Type Directory -Force; ``"
134-
$null = $DirectoryBuilder.AppendLine($newPath)
135-
136-
$copy = "COPY {0} {1}" -f (Split-Path $sourcePath -Leaf),($sourcePath -Replace "\\","/")
137-
$null = $CopyBuilder.AppendLine($copy)
147+
if ($sourcePath -ne $mainVirtualDir.PhysicalPath) {
148+
ProcessDirectory -DirectoryBuilder $DirectoryBuilder -CopyBuilder $CopyBuilder -SourcePath $sourcePath
138149
}
139150
}
140151

@@ -160,11 +171,7 @@ if ($Artifact.Status -eq 'Present') {
160171
$null = $AppBuilder.AppendLine($newDir)
161172

162173
if ($sourcePath -ne $mainVirtualDir.PhysicalPath) {
163-
$newPath = " New-Item -Path 'C:$sourcePath' -Type Directory -Force; ``"
164-
$null = $DirectoryBuilder.AppendLine($newPath)
165-
166-
$copy = "COPY {0} {1}" -f (Split-Path $sourcePath -Leaf),($sourcePath -Replace "\\","/")
167-
$null = $CopyBuilder.AppendLine($copy)
174+
ProcessDirectory -DirectoryBuilder $DirectoryBuilder -CopyBuilder $CopyBuilder -SourcePath $sourcePath
168175
}
169176
}
170177
}
@@ -187,7 +194,7 @@ if ($Artifact.Status -eq 'Present') {
187194
}
188195

189196

190-
Write-Output $ResultBuilder.ToString() -NoEnumerate
197+
return $ResultBuilder.ToString()
191198

192199
}
193200

Functions/Private/Artifacts/MSMQ/Generate_MSMQ.ps1

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,19 @@ param (
1212
[string] $ManifestPath
1313
)
1414

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
15+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
1616

17-
Write-Verbose -Message ('Generating result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
18-
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
17+
Write-Verbose -Message ('Generating result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
18+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
1919

20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
20+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2121

22-
if ($Artifact.Status -eq 'Present') {
23-
$Result = "RUN Enable-WindowsOptionalFeature -Online -FeatureName $($Artifact.FeatureName.Replace(';',',')) ;"
24-
$Result += [System.Environment]::NewLine
25-
$Result += 'EXPOSE 135 389 1801
26-
27-
CMD /Wait-Service.ps1 -ServiceName MSMQ -AllowServiceRestart'
28-
29-
Write-Output -InputObject $Result
30-
}
31-
32-
33-
}
22+
$ResultBuilder = GetDockerfileBuilder
23+
if ($Artifact.Status -eq 'Present') {
24+
$null = $ResultBuilder.AppendLine("RUN Enable-WindowsOptionalFeature -Online -FeatureName $($Artifact.FeatureName.Replace(';',',')) ;")
25+
$null = $ResultBuilder.AppendLine('EXPOSE 135 389 1801')
26+
$null = $ResultBuilder.AppendLine('CMD /Wait-Service.ps1 -ServiceName MSMQ -AllowServiceRestart')
27+
}
3428

29+
return $ResultBuilder.ToString()
30+
}

Functions/Private/Artifacts/SQLServer/Generate_SQLServer.ps1

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,23 @@ param (
1212
[string] $ManifestPath
1313
)
1414

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
15+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
1616

17-
Write-Verbose -Message ('Generating result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
18-
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
17+
Write-Verbose -Message ('Generating result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
18+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
1919

20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
20+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2121

22-
if ($Artifact.Status -eq 'Present') {
23-
$Result = '
24-
### NOTE: You will need to set up a SQL Server answer file for each instance
25-
RUN powershell.exe -ExecutionPolicy Bypass -Command \
26-
'
27-
$SetupTemplate = 'setup.exe /INSTANCENAME={0} /IACCEPTSQLSERVERLICENSETERMS /QS /CONFIGURATIONFILE=sqlserver.ini; \{1}'
22+
$ResultBuilder = GetDockerfileBuilder
23+
if ($Artifact.Status -eq 'Present') {
24+
$null = $ResultBuilder.AppendLine('### NOTE: You will need to set up a SQL Server answer file for each instance')
2825

29-
foreach ($SqlInstance in $Artifact.SqlInstances) {
30-
$Result += $SetupTemplate -f $SqlInstance.Name, "`r`n"
31-
}
32-
33-
Write-Output -InputObject $Result
34-
}
26+
$SetupTemplate = 'RUN setup.exe /INSTANCENAME={0} /IACCEPTSQLSERVERLICENSETERMS /QS /CONFIGURATIONFILE=sqlserver.ini; \{1}'
3527

28+
foreach ($SqlInstance in $Artifact.SqlInstances) {
29+
$null = $ResultBuilder.AppendLine($SetupTemplate -f $SqlInstance.Name)
30+
}
31+
}
3632

37-
}
38-
33+
return $ResultBuilder.ToString()
34+
}

Functions/Private/GenerateDockerfile.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
)
2626

2727
Write-Verbose -Message ('Generating Dockerfile based on discovered artifacts in :{0}' -f $Mount.Path)
28-
$Dockerfile = ''
2928

30-
if (! $ArtifactParam) {
31-
$Dockerfile = & "Generate_$Artifact" -ManifestPath $ArtifactPath
32-
}
33-
else {
34-
$Dockerfile = & "Generate_$Artifact" -ManifestPath $ArtifactPath -ArtifactParam $ArtifactParam
35-
}
29+
$Dockerfile = ''
30+
if (! $ArtifactParam) {
31+
$Dockerfile = & "Generate_$Artifact" -ManifestPath $ArtifactPath
32+
}
33+
else {
34+
$Dockerfile = & "Generate_$Artifact" -ManifestPath $ArtifactPath -ArtifactParam $ArtifactParam
35+
}
3636

3737
$DockerfilePath = '{0}\Dockerfile' -f $ArtifactPath
3838
Set-Content -Path $DockerfilePath -Value $Dockerfile.Trim()

0 commit comments

Comments
 (0)