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

Commit 8f62efc

Browse files
committed
Add support for remote servers
Signed-off-by: Elton Stoneman <elton@sixeyed.com>
1 parent 97f75f8 commit 8f62efc

File tree

5 files changed

+84
-52
lines changed

5 files changed

+84
-52
lines changed

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 $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-
}
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 6 | 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
}

Functions/Private/Artifacts/IIS/Generate_IIS.ps1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ function ProcessDirectory([System.Text.StringBuilder] $DirectoryBuilder,
5757
$null = $CopyBuilder.AppendLine($copy)
5858

5959
$fullSourcePath = $SourcePath
60-
if ($Mount) {
60+
if ($global:SourceType -eq [SourceType]::Image -or
61+
$global:SourceType -eq [SourceType]::Remote) {
6162
$fullSourcePath = $MountPath + $targetPath
6263
}
6364
Copy-Item $fullSourcePath $ManifestPath -Recurse -Force
@@ -99,7 +100,6 @@ if ($Artifact.Status -eq 'Present') {
99100
$null = $ResultBuilder.AppendLine('')
100101
}
101102

102-
$null = $ResultBuilder.AppendLine('')
103103
for ($i=0;$i -lt $Artifact.Websites.Count;$i++) {
104104
$Site = $Artifact.Websites[$i]
105105
$include = IncludePath($Site.Name)
@@ -206,5 +206,4 @@ if ($Artifact.Status -eq 'Present') {
206206

207207
return $ResultBuilder.ToString()
208208

209-
}
210-
209+
}

Functions/Private/Artifacts/IIS/GetManifestFromApplicationHost.ps1

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,35 @@ if (Test-Path -Path $ApplicationHostPath) {
104104
Name = $Handler.name
105105
Path = $Handler.path
106106
Verb = $Handler.verb
107-
}) | Out-Null
107+
Processor = $Handler.scriptProcessor
108+
}) | Out-Null
108109
}
109-
if ($Handler.path.Contains('.aspx')) {
110+
if ($Handler.Path.Contains('.aspx')) {
110111
$AspNetInstalled = $true
111112
}
112113
}
113114

114115
#feature selection not valid for 2008 and below:
115116
if ([decimal]$ImageWindowsVersion -gt 6.1) {
116-
if ($Mount) {
117-
$WindowsFeatures = Get-WindowsOptionalFeature -Path $MountPath
118-
}
119-
else {
120-
$WindowsFeatures = Get-WindowsOptionalFeature -Online
121-
}
117+
if ($global:SourceType -eq [SourceType]::Image) {
118+
$WindowsFeatures = Get-WindowsOptionalFeature -Path $MountPath
119+
}
120+
elseif ($global:SourceType -eq [SourceType]::Local) {
121+
$WindowsFeatures = Get-WindowsOptionalFeature -Online
122+
}
123+
if ($WindowsFeatures) {
122124
$IIS = $WindowsFeatures.Where{$_.FeatureName -eq 'IIS-WebServer'}
123125
$EnabledFeatures = $WindowsFeatures.Where{$_.State -eq 'Enabled'}
124126
$FeaturesToExport = $EnabledFeatures.Where{$_.FeatureName -match 'IIS'-or
125-
$_.FeatureName -match 'ASPNET' -or
126-
$_.FeatureName -match 'Asp-Net' -and
127-
$_.FeatureName -NotMatch 'Management'} | Sort-Object FeatureName | Select-Object -ExpandProperty FeatureName
128-
127+
$_.FeatureName -match 'ASPNET' -or
128+
$_.FeatureName -match 'Asp-Net' -and
129+
$_.FeatureName -NotMatch 'Management'} | Sort-Object FeatureName | Select-Object -ExpandProperty FeatureName
130+
129131
$ManifestResult.FeatureName = $FeaturesToExport -join ';'
130132
if ($ManifestResult.FeatureName -like '*ASPNET*' -or $ManifestResult.FeatureName -like '*Asp-Net*'){
131-
$AspNetInstalled = $true
132-
}
133+
$AspNetInstalled = $true
134+
}
135+
}
133136
}
134137

135138
$ManifestResult.Status = 'Present'
@@ -142,10 +145,7 @@ if (Test-Path -Path $ApplicationHostPath) {
142145

143146
if ($AspNetInstalled -eq $true){
144147
$ManifestResult.AspNetStatus = 'Present'
145-
}
146-
147-
#TODO
148-
$ManifestResult.AspNet35Status = 'Absent'
148+
}
149149
}
150150

151151
return $ManifestResult

Functions/Public/ConvertTo/ConvertTo-Dockerfile.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@
9191
[Switch] $Force,
9292

9393
[Parameter(Mandatory = $false)]
94-
[Switch] $Local
94+
[Switch] $Local,
95+
96+
[Parameter(Mandatory = $false)]
97+
[string] $RemotePath
9598
)
9699

97100
# TODO - validat eLOcal & ImagePath
@@ -108,13 +111,22 @@
108111
}
109112

110113
# load the source - local drive, or VHD
114+
$global:SourceType = [SourceType]::Local
111115
if ($Local) {
112116
$MountPath = $env:SystemDrive
113117
$version = [Environment]::OSVersion.Version
114118
$ImageWindowsVersion = "$($version.Major).$($version.Minor)"
115119
Write-Verbose -Message "Using local drive: $MountPath"
116120
}
117-
else {
121+
elseif ($RemotePath) {
122+
$global:SourceType = [SourceType]::Remote
123+
$MountPath = $RemotePath
124+
$version = (Get-ItemProperty -Path "$RemotePath\windows\system32\hal.dll").VersionInfo.ProductVersion
125+
$ImageWindowsVersion = $version.Substring(0, $version.IndexOf('.', $version.IndexOf('.')+1))
126+
Write-Verbose -Message "Using remote drive: $RemotePath"
127+
}
128+
elseif ($ImagePath) {
129+
$global:SourceType = [SourceType]::Image
118130
# Verify the image type before proceeding
119131
$ImageType = GetImageType -Path $ImagePath
120132
Write-Verbose -Message ('Image type is: {0}' -f $ImageType)
@@ -134,6 +146,9 @@
134146
$info = Get-WindowsImage -Index 1 -ImagePath $ImagePath
135147
$ImageWindowsVersion = "$($info.MajorVersion).$($info.MinorVersion)"
136148
}
149+
else {
150+
throw "Source not specified. One of -Local, -ImagePath or -RemotePath is required."
151+
}
137152

138153
Write-Verbose -Message ('Starting conversion process')
139154
try {

Image2Docker.psm1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ enum ImageType {
66
WIM
77
}
88

9+
enum SourceType {
10+
Image
11+
Local
12+
Remote
13+
}
14+
915
### Obtain the module path
1016
$ModulePath = $ExecutionContext.SessionState.Module.ModuleBase
1117

0 commit comments

Comments
 (0)