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

Commit 05435ce

Browse files
author
Mano Marks
authored
Merge pull request #27 from sixeyed/master
Generate ASP.NET setup in IIS artifact
2 parents e82494c + f867ca2 commit 05435ce

18 files changed

+129
-538
lines changed

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Contributing to Image2Docker ##
2+
3+
Thank you so much for your interest in contributing to the Image2Docker tool ("i2d2"). Docker has open source in its DNA, and has always worked closely with the community.
4+
5+
Just a few quick things to be aware of before you get started.
6+
7+
We welcome issues and [signed pull requests](https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work) for either adding new features, or fixing a problem with an existing feature.
8+
9+
Anything you contribute will be under an Apache license. Docker will choose which PRs to accept and reject. Anything posted here may be forked by anyone on GitHub.
10+
11+
We will be following the lightweight version of the Docker contribution policies and procedures as explained in
12+
- [Docker documentation](https://docs.docker.com)
13+
- The [Docker engine repo](https://github.com/docker/docker/blob/master/CONTRIBUTING.md).
14+
15+
This largely boils down to [signing your PRs](https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work), following the Docker [trademark guidelines](https://www.docker.com/trademark-guidelines), and following the community guidelines.

Functions/Private/Artifacts/Apache/Generate_Apache.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ if ($Artifact.Status -eq 'Present') {
2323
$Result = '
2424
LABEL Description="Apache" Vendor="Docker Inc." Version="2.4.23"
2525
26-
RUN powershell.exe -ExecutionPolicy Bypass -Command 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 \
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; `
2929
Remove-Item -Path $env:TEMP\Apache.zip
3030
31-
ENTRYPOINT ["c:\apache\apache24\bin\httpd.exe", "-w"]'
31+
ENTRYPOINT ["c:\apache\apache24\bin\httpd.exe", "-w"]'
3232

3333
Write-Verbose -Message ('Artifact is present: {0}. Adding text to Dockerfile {1}.' -f $ArtifactName, $Result)
3434
}

Functions/Private/Artifacts/DHCPServer/Generate_DHCPServer.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ $Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
2020
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2121

2222
if ($Artifact.Status -eq 'Present') {
23-
$Result = 'RUN powershell.exe -ExecutionPolicy Bypass -Command Enable-WindowsOptionalFeature -Online -FeatureName DHCPServer'
23+
$Result =
24+
'RUN Enable-WindowsOptionalFeature -Online -FeatureName DHCPServer
25+
26+
EXPOSE 67 2535
27+
28+
CMD /Wait-Service.ps1 -ServiceName DHCPServer -AllowServiceRestart'
2429
}
2530

2631
Write-Output -InputObject $Result

Functions/Private/Artifacts/DNSServer/Generate_DNSServer.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ $Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
2020
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2121

2222
if ($Artifact.Status -eq 'Enabled') {
23-
$Result = 'RUN powershell.exe -ExecutionPolicy Bypass -Command Enable-WindowsOptionalFeature -Online -FeatureName DNS-Server-Full-Role'
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'
2429
}
2530

2631
Write-Output -InputObject $Result

Functions/Private/Artifacts/IIS/Discover_IIS.ps1

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ The path where the Windows image was mounted to.
88
99
.PARAMETER OutputPath
1010
The filesystem path where the discovery manifest will be emitted.
11+
12+
.PARAMETER ArtifactParam
13+
Optional - one or more Website names to include in the output.
1114
#>
1215
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess",'')]
1316
[CmdletBinding()]
1417
param (
1518
[Parameter(Mandatory = $true)]
1619
[string] $MountPath,
20+
1721
[Parameter(Mandatory = $true)]
18-
[string] $OutputPath
22+
[string] $OutputPath,
23+
24+
[Parameter(Mandatory = $false)]
25+
[string[]] $ArtifactParam
1926
)
2027

2128
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
@@ -31,12 +38,12 @@ $ManifestResult = @{
3138
}
3239

3340
$WindowsFeatures = Get-WindowsOptionalFeature -Path $MountPath
34-
3541
$IIS = $WindowsFeatures.Where{$_.FeatureName -eq 'IIS-WebServer'}
36-
3742
$EnabledFeatures = $WindowsFeatures.Where{$_.State -eq 'Enabled'}
38-
39-
$FeaturesToExport = $EnabledFeatures.Where{$_.FeatureName -match 'IIS'} | Sort-Object FeatureName | Select-Object -ExpandProperty FeatureName
43+
$FeaturesToExport = $EnabledFeatures.Where{$_.FeatureName -match 'IIS'-or
44+
$_.FeatureName -match 'ASPNET' -or
45+
$_.FeatureName -match 'Asp-Net' -and
46+
$_.FeatureName -NotMatch 'Management'} | Sort-Object FeatureName | Select-Object -ExpandProperty FeatureName
4047

4148
if ($IIS.State -eq 'Enabled') {
4249

@@ -47,6 +54,9 @@ if ($IIS.State -eq 'Enabled') {
4754
$applicationDefaults = $AllSites.applicationDefaults
4855
$virtualDirectoryDefaults = $AllSites.virtualDirectoryDefaults
4956
$sites = $AllSites.site
57+
if ($ArtifactParam) {
58+
$sites = $sites.where{$_.name -in $ArtifactParam }
59+
}
5060
$Websites = New-Object System.Collections.ArrayList
5161
ForEach ($site in $sites) {
5262
$Websites.add([PSCustomObject]@{
@@ -91,16 +101,24 @@ if ($IIS.State -eq 'Enabled') {
91101
$ManifestResult.SiteDefaults = $siteDefaults
92102
$ManifestResult.ApplicationDefaults = $applicationDefaults
93103
$ManifestResult.VirtualDirectoryDefaults = $virtualDirectoryDefaults
104+
105+
if ($ManifestResult.FeatureName -like '*ASPNET*' -or $ManifestResult.FeatureName -like '*Asp-Net*'){
106+
Write-Verbose -Message 'ASP.NET is present on the system'
107+
$ManifestResult.AspNetStatus = 'Present'
108+
}
109+
else {
110+
Write-Verbose -Message 'ASP.NET is NOT present on the system'
111+
$ManifestResult.AspNetStatus = 'Absent'
112+
}
94113
}
95114
else {
96115
Write-Verbose -Message 'IIS service is NOT present on the system'
97116
$ManifestResult.Status = 'Absent'
117+
$ManifestResult.AspNetStatus = 'Absent'
98118
}
99119

100120
### Write the result to the manifest file
101121
$ManifestResult | ConvertTo-Json -Depth 3 | Set-Content -Path $Manifest
102122

103123
Write-Verbose -Message ('Finished discovering {0} artifact' -f $ArtifactName)
104-
}
105-
106-
124+
}

Functions/Private/Artifacts/IIS/Generate_IIS.ps1

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ Generates Dockerfile contents for Internet Information Services (IIS) feature
55
66
.PARAMETER ManifestPath
77
The 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()]
1215
param (
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

Functions/Private/Artifacts/MSMQ/Discover_MSMQ.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ $Manifest = '{0}\{1}.json' -f $OutputPath, $ArtifactName
2727
### Create a HashTable to store the results (this will get persisted to JSON)
2828
$ManifestResult = @{
2929
Name = 'MSMQ'
30+
FeatureName = ''
3031
Status = ''
3132
}
3233

33-
$MSMQ = Get-WindowsOptionalFeature -FeatureName MSMQ-Server -Path $MountPath
34-
35-
if ($MSMQ.State -eq 'Enabled') {
34+
$MsmqFeatures = Get-WindowsOptionalFeature -FeatureName MSMQ* -Path $MountPath
35+
$EnabledFeatures = $MsmqFeatures.Where{$_.State -eq 'Enabled'}
36+
if ($EnabledFeatures.Count -gt 0) {
3637
Write-Verbose -Message 'MSMQ service is present'
3738
$ManifestResult.Status = 'Present'
39+
$FeaturesToExport = $enabledFeatures | Sort-Object FeatureName | Select-Object -ExpandProperty FeatureName
40+
$ManifestResult.FeatureName = $FeaturesToExport -join ';'
3841
}
3942
else {
4043
Write-Verbose -Message 'MSMQ service was not found'

Functions/Private/Artifacts/MSMQ/Generate_MSMQ.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ $Manifest = '{0}\{1}.json' -f $ManifestPath, $ArtifactName
2020
$Artifact = Get-Content -Path $Manifest -Raw | ConvertFrom-Json
2121

2222
if ($Artifact.Status -eq 'Present') {
23-
$Result = '
24-
RUN powershell.exe -ExecutionPolicy Bypass -Command Enable-WindowsOptionalFeature -Online -FeatureName MSMQ-Server
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'
2528

26-
ENTRYPOINT ["ping", "8.8.8.8", "-t"]'
2729
Write-Output -InputObject $Result
2830
}
2931

0 commit comments

Comments
 (0)