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

Commit 684a958

Browse files
authored
Merge pull request #44 from sixeyed/master
Version 1.8.0
2 parents 68304c5 + 4fb818f commit 684a958

27 files changed

+771
-269
lines changed

Functions/Private/Artifacts/AddRemovePrograms/Generate_AddRemovePrograms.ps1

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ The filesystem path where the JSON manifests are stored.
88
#>
99
[CmdletBinding()]
1010
param (
11+
[Parameter(Mandatory = $true)]
12+
[string] $MountPath,
13+
1114
[Parameter(Mandatory = $true)]
1215
[string] $ManifestPath
1316
)
1417

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

20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
20+
Write-Verbose -Message ('Generating Dockerfile result for {0} component' -f (Split-Path -Path $PSScriptRoot -Leaf))
21+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
2122

22-
$Result = ''
23-
foreach ($Item in $Artifact) {
24-
$Result += '# {0} {1}' -f $Item, "`r`n"
25-
}
23+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2624

27-
Write-Output -InputObject $Result
25+
$ResultBuilder = GetDockerfileBuilder
26+
foreach ($Item in $Artifact) {
27+
$null = $ResultBuilder.AppendLine("# $Item")
28+
}
2829

30+
return $ResultBuilder.ToString()
2931
}
3032

Functions/Private/Artifacts/AllWindowsFeatures/Generate_AllWindowsFeatures.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ The filesystem path where the JSON manifests are stored.
88
#>
99
[CmdletBinding()]
1010
param (
11+
[Parameter(Mandatory = $true)]
12+
[string] $MountPath,
13+
1114
[Parameter(Mandatory = $true)]
1215
[string] $ManifestPath
1316
)
1417

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
16-
17-
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
18-
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
19-
20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
21-
22-
$Result =''
18+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
2319

24-
$FeatureNames = $Artifact.FeatureName.replace(';',',')
20+
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
21+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
2522

26-
$Result += "RUN powershell.exe -ExecutionPolicy Bypass -Command Enable-WindowsOptionalFeature -Online -FeatureName $FeatureNames -All `r`n"
23+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
24+
$FeatureNames = $Artifact.FeatureName.replace(';',',')
2725

26+
$ResultBuilder = GetDockerfileBuilder
27+
$null = $ResultBuilder.AppendLine("RUN Enable-WindowsOptionalFeature -Online -FeatureName $FeatureNames -All")
2828

29-
Write-Output -InputObject $Result
29+
return $ResultBuilder.ToString()
3030
}
3131

Functions/Private/Artifacts/Apache/Generate_Apache.ps1

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,34 @@ The filesystem path where the JSON manifests are stored.
88
#>
99
[CmdletBinding()]
1010
param (
11+
[Parameter(Mandatory = $true)]
12+
[string] $MountPath,
13+
1114
[Parameter(Mandatory = $true)]
1215
[string] $ManifestPath
1316
)
1417

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
18+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
1619

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

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

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-
}
25+
$ResultBuilder = GetDockerfileBuilder
26+
if ($Artifact.Status -eq 'Present') {
27+
$null = $ResultBuilder.AppendLine('LABEL Description="Apache" Vendor="Docker Inc." Version="2.4.23"')
28+
29+
$null = $ResultBuilder.AppendLine('RUN mkdir $env:SystemDrive\Apache; ``')
30+
$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; ``')
31+
$null = $ResultBuilder.AppendLine(' Expand-Archive -Path $env:TEMP\apache.zip -DestinationPath c:\apache; ``')
32+
$null = $ResultBuilder.AppendLine(' Remove-Item -Path $env:TEMP\Apache.zip')
33+
34+
$null = $ResultBuilder.AppendLine('ENTRYPOINT ["c:\apache\apache24\bin\httpd.exe", "-w"]')
35+
36+
Write-Verbose -Message ('Artifact is present: {0}. Adding text to Dockerfile {1}.' -f $ArtifactName, $Result)
37+
}
3538

36-
Write-Output -InputObject $Result
39+
return $ResultBuilder.ToString()
3740
}
3841

Functions/Private/Artifacts/DHCPServer/Generate_DHCPServer.ps1

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@ The filesystem path where the JSON manifests are stored.
88
#>
99
[CmdletBinding()]
1010
param (
11+
[Parameter(Mandatory = $true)]
12+
[string] $MountPath,
13+
1114
[Parameter(Mandatory = $true)]
1215
[string] $ManifestPath
1316
)
1417

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

20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
20+
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
21+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
2122

22-
if ($Artifact.Status -eq 'Present') {
23-
$Result =
24-
'RUN Enable-WindowsOptionalFeature -Online -FeatureName DHCPServer
23+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2524

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

31-
Write-Output -InputObject $Result
32+
return $ResultBuilder.ToString()
3233
}
3334

Functions/Private/Artifacts/DNSServer/Generate_DNSServer.ps1

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ The filesystem path where the JSON manifests are stored.
88
#>
99
[CmdletBinding()]
1010
param (
11+
[Parameter(Mandatory = $true)]
12+
[string] $MountPath,
13+
1114
[Parameter(Mandatory = $true)]
1215
[string] $ManifestPath
1316
)
1417

15-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
16-
17-
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
18-
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
19-
20-
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
21-
22-
if ($Artifact.Status -eq 'Enabled') {
23-
$Result =
24-
'RUN Enable-WindowsOptionalFeature -Online -FeatureName DNS-Server-Full-Role
18+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
2519

26-
EXPOSE 53
20+
Write-Verbose -Message ('Generating result for {0} component' -f $ArtifactName)
21+
$Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
2722

28-
CMD /Wait-Service.ps1 -ServiceName DNS -AllowServiceRestart'
29-
}
23+
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
3024

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

32+
return $ResultBuilder.ToString()
33+
}

Functions/Private/Artifacts/IIS/Discover_IIS.ps1

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,56 @@ param (
2828
[string[]] $ArtifactParam
2929
)
3030

31-
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
32-
Write-Verbose -Message ('Started discovering {0} artifact' -f $ArtifactName)
31+
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
32+
Write-Verbose -Message ('Started discovering {0} artifact' -f $ArtifactName)
3333

34-
### Path to the manifest
35-
$Manifest = '{0}\{1}.json' -f $OutputPath, $ArtifactName
34+
### Path to the manifest
35+
$Manifest = '{0}\{1}.json' -f $OutputPath, $ArtifactName
3636

37-
### Create a HashTable to store the results (this will get persisted to JSON)
38-
$ManifestResult = @{
39-
FeatureName = ''
40-
Status = ''
41-
}
37+
### Create a HashTable to store the results (this will get persisted to JSON)
38+
$ManifestResult = @{
39+
FeatureName = ''
40+
Status = ''
41+
}
42+
43+
# Windows 5.2 -> Server 2003; use MetaBase discovery for IIS 6:
44+
if ($ImageWindowsVersion -eq '5.2') {
45+
Write-Verbose -Message "Checking IIS MetaBase config for Windows Version: $ImageWindowsVersion"
46+
$ManifestResult = GetManifestFromMetabase -OutputPath $OutputPath -MountPath $MountPath -ImageWindowsVersion $ImageWindowsVersion -ArtifactParam $ArtifactParam
47+
}
48+
else {
49+
# Use Application Host discovery for IIS 7 onwards:
50+
Write-Verbose -Message "Checking IIS ApplicationHost config for Windows Version: $ImageWindowsVersion"
51+
$ManifestResult = GetManifestFromApplicationHost -OutputPath $OutputPath -MountPath $MountPath -ImageWindowsVersion $ImageWindowsVersion -ArtifactParam $ArtifactParam
52+
}
4253

43-
# Windows 5.2 -> Server 2003; use MetaBase discovery for IIS 6:
44-
if ($ImageWindowsVersion -eq '5.2') {
45-
Write-Verbose -Message "Checking IIS MetaBase config for Windows Version: $ImageWindowsVersion"
46-
$ManifestResult = GetManifestFromMetabase -OutputPath $OutputPath -MountPath $Mount.Path -ImageWindowsVersion $ImageWindowsVersion -ArtifactParam $ArtifactParam
47-
}
48-
else {
49-
# Use Application Host discovery for IIS 7 onwards:
50-
Write-Verbose -Message "Checking IIS ApplicationHost config for Windows Version: $ImageWindowsVersion"
51-
$ManifestResult = GetManifestFromApplicationHost -OutputPath $OutputPath -MountPath $Mount.Path -ImageWindowsVersion $ImageWindowsVersion -ArtifactParam $ArtifactParam
52-
}
54+
# ASP.NET 3.5 apps use the 2.0 runtime so there's no 3.5 reference in config.
55+
# Instead check for existence of the 3.5 framework:
56+
if (Test-Path "$MountPath\Windows\Microsoft.NET\Framework*\v3.5") {
57+
$ManifestResult.AspNet35Status = 'Present'
58+
}
5359

54-
if ($ManifestResult.Status -eq 'Present'){
55-
Write-Verbose -Message 'IIS service is present on the system'
60+
if ($ManifestResult.Status -eq 'Present'){
61+
Write-Verbose -Message 'IIS service is present on the system'
62+
}
63+
else {
64+
Write-Verbose -Message 'IIS service is NOT present on the system'
65+
}
5666
if ($ManifestResult.AspNetStatus -eq 'Present'){
5767
Write-Verbose -Message 'ASP.NET is present on the system'
5868
}
5969
else {
6070
Write-Verbose -Message 'ASP.NET is NOT present on the system'
6171
}
62-
}
63-
else {
64-
Write-Verbose -Message 'IIS service is NOT present on the system'
65-
}
72+
if ($ManifestResult.AspNet35Status -eq 'Present'){
73+
Write-Verbose -Message '.NET 3.5 is present on the system'
74+
}
75+
else {
76+
Write-Verbose -Message '.NET 3.5 is NOT present on the system'
77+
}
6678

67-
### Write the result to the manifest file
68-
$ManifestResult | ConvertTo-Json -Depth 3 | Set-Content -Path $Manifest
79+
### Write the result to the manifest file
80+
$ManifestResult | ConvertTo-Json -Depth 6 | Set-Content -Path $Manifest
6981

70-
Write-Verbose -Message ('Finished discovering {0} artifact' -f $ArtifactName)
82+
Write-Verbose -Message ('Finished discovering {0} artifact' -f $ArtifactName)
7183
}

0 commit comments

Comments
 (0)