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

Commit

Permalink
Module Overhaul + Added Arguement Completion
Browse files Browse the repository at this point in the history
Small Simplifaction in arguement completers
  • Loading branch information
kilasuit committed Dec 2, 2016
1 parent 1adbe3f commit 43a89cd
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 15 deletions.
24 changes: 24 additions & 0 deletions Completers/Artifacts.Completion.ps1
@@ -0,0 +1,24 @@

function Completion_Artifact {

param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

Function Get-Artifacts {
$artifacts = Get-ChildItem -Path $modulepath\Functions\Private\Artifacts -Directory | Select-Object -ExpandProperty BaseName
$artifacts
}

### Create fresh completion results for Artifacts
Get-Artifacts | Where-Object { $PSItem -match $wordToComplete } | ForEach-Object {
$CompletionText = $PSItem;
$ToolTip = $PSItem;
$ListItemText = $PSItem;
$CompletionResultType = [System.Management.Automation.CompletionResultType]::ParameterValue;

New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList @($CompletionText, $ListItemText, $CompletionResultType, $ToolTip);
}

}

Microsoft.PowerShell.Core\Register-ArgumentCompleter -CommandName ConvertTo-DockerFile -ParameterName Artifact -ScriptBlock $Function:Completion_Artifact

@@ -1,3 +1,4 @@
function Discover_AddRemovePrograms {
<#
.SYNOPSIS
Scans for Add/Remove Programs entries
Expand Down Expand Up @@ -64,3 +65,6 @@ Write-Verbose -Message 'Finished unmounting the registry hive'
### Write out the discovery results to the manifest file
$SoftwareList | ConvertTo-Json | Set-Content -Path $ManifestPath
Write-Verbose -Message ('Finished discovery for {0} artifact' -f (Split-Path -Path $PSScriptRoot -Leaf))

}

@@ -1,3 +1,4 @@
function Generate_AddRemovePrograms {
<#
.SYNOPSIS
Generate Dockerfile contents for Add/Remove Programs entries
Expand All @@ -24,3 +25,6 @@ foreach ($Item in $Artifact) {
}

Write-Output -InputObject $Result

}

@@ -1,3 +1,4 @@
function Discover_AllWindowsFeatures {
<#
.SYNOPSIS
Scans for presence of DHCP Server component in a Windows Server image.
Expand Down Expand Up @@ -42,4 +43,6 @@ $ManifestResult.Status = 'Enabled'
### Write the result to the manifest file
$ManifestResult | ConvertTo-Json | Set-Content -Path $Manifest

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

@@ -1,3 +1,4 @@
function Generate_AllWindowsFeatures {
<#
.SYNOPSIS
Generates Dockerfile contents for DHCP Server component
Expand Down Expand Up @@ -25,4 +26,6 @@ $FeatureNames = $Artifact.FeatureName.replace(';',',')
$Result += "RUN powershell.exe -ExecutionPolicy Bypass -Command Enable-WindowsOptionalFeature -Online -FeatureName $FeatureNames -All `r`n"


Write-Output -InputObject $Result
Write-Output -InputObject $Result
}

@@ -1,3 +1,4 @@
function Discover_Apache {
<#
.SYNOPSIS
Scans for the Apache Web Server
Expand Down Expand Up @@ -46,4 +47,6 @@ else {
### Write the result to the manifest file
$ManifestResult | ConvertTo-Json | Set-Content -Path $Manifest

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

@@ -1,3 +1,4 @@
function Generate_Apache {
<#
.SYNOPSIS
Generates Dockerfile contents for Apache Web Server component
Expand Down Expand Up @@ -32,4 +33,6 @@ if ($Artifact.Status -eq 'Present') {
Write-Verbose -Message ('Artifact is present: {0}. Adding text to Dockerfile {1}.' -f $ArtifactName, $Result)
}

Write-Output -InputObject $Result
Write-Output -InputObject $Result
}

@@ -1,3 +1,4 @@
function Discover_DHCPServer {
<#
.SYNOPSIS
Scans for presence of DHCP Server component in a Windows Server image.
Expand Down Expand Up @@ -40,4 +41,6 @@ else {
### Write the result to the manifest file
$ManifestResult | ConvertTo-Json | Set-Content -Path $Manifest

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

@@ -1,3 +1,4 @@
function Generate_DHCPServer {
<#
.SYNOPSIS
Generates Dockerfile contents for DHCP Server component
Expand All @@ -22,4 +23,6 @@ if ($Artifact.Status -eq 'Present') {
$Result = 'RUN powershell.exe -ExecutionPolicy Bypass -Command Enable-WindowsOptionalFeature -Online -FeatureName DHCPServer'
}

Write-Output -InputObject $Result
Write-Output -InputObject $Result
}

@@ -1,3 +1,4 @@
function Discover_DNSServer {
<#
.SYNOPSIS
Scans for presence of DNS Server component in a Windows image.
Expand Down Expand Up @@ -30,4 +31,6 @@ $ManifestResult = @{
### Write the result to the manifest file
$ManifestResult | ConvertTo-Json | Set-Content -Path $Manifest

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

@@ -1,3 +1,4 @@
function Generate_DNSServer {
<#
.SYNOPSIS
Generates Dockerfile contents for DNS Server component
Expand All @@ -22,4 +23,6 @@ if ($Artifact.Status -eq 'Enabled') {
$Result = 'RUN powershell.exe -ExecutionPolicy Bypass -Command Enable-WindowsOptionalFeature -Online -FeatureName DNS-Server-Full-Role'
}

Write-Output -InputObject $Result
Write-Output -InputObject $Result
}

@@ -1,3 +1,4 @@
function Discover_IIS {
<#
.SYNOPSIS
Scans for presence of the Internet Information Services (IIS) Web Server
Expand Down Expand Up @@ -96,3 +97,6 @@ else {
$ManifestResult | ConvertTo-Json -Depth 3 | Set-Content -Path $Manifest

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


@@ -1,3 +1,4 @@
Function Generate_IIS {
<#
.SYNOPSIS
Generates Dockerfile contents for Internet Information Services (IIS) feature
Expand Down Expand Up @@ -57,3 +58,5 @@ Write-Output $endOutput -NoEnumerate

}

}

@@ -1,3 +1,4 @@
function Discover_MSMQ {
<#
.SYNOPSIS
Scans for presence of the MSMQ Windows feature
Expand Down Expand Up @@ -42,4 +43,6 @@ else {
### Write the result to the manifest file
$ManifestResult | ConvertTo-Json | Set-Content -Path $Manifest

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

@@ -1,3 +1,4 @@
function Generate_MSMQ {
<#
.SYNOPSIS
Generates Dockerfile contents for Microsoft Message Queue (MSMQ) Server feature
Expand Down Expand Up @@ -26,3 +27,6 @@ ENTRYPOINT ["ping", "8.8.8.8", "-t"]'
Write-Output -InputObject $Result
}


}

@@ -1,3 +1,4 @@
Function Discover_SqlServer {
<#
.SYNOPSIS
Scans for presence of the MSMQ Windows feature
Expand Down Expand Up @@ -74,4 +75,6 @@ $ManifestResult = @{
### Write the result to the manifest file
$ManifestResult | ConvertTo-Json | Set-Content -Path $Manifest

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

@@ -1,3 +1,4 @@
function Generate_SQLServer {
<#
.SYNOPSIS
Generates Dockerfile contents for Microsoft SQL Server
Expand Down Expand Up @@ -32,3 +33,6 @@ RUN powershell.exe -ExecutionPolicy Bypass -Command \
Write-Output -InputObject $Result
}


}

4 changes: 1 addition & 3 deletions Functions/Private/DiscoverArtifacts.ps1
Expand Up @@ -13,8 +13,6 @@ function DiscoverArtifacts {

### Perform discovery of artifacts
foreach ($item in $Artifact) {
$DiscoveryScript = '{0}\Artifacts\{1}\Discover.ps1' -f $ModulePath, $item
Write-Verbose -Message ('Invoking artifact discovery scripts: {0}' -f $DiscoveryScript)
. $DiscoveryScript -OutputPath $OutputPath -MountPath $Mount.Path
& "Discover_$item" -OutputPath $OutputPath -MountPath $Mount.Path
}
}
2 changes: 1 addition & 1 deletion Functions/Private/GenerateDockerfile.ps1
Expand Up @@ -26,7 +26,7 @@ function GenerateDockerfile {
$Dockerfile = Get-Content -Raw -Path $DockerfileTemplate

foreach ($item in $Artifact) {
$Result = & $ModulePath\Artifacts\$item\Generate.ps1 -ManifestPath $ArtifactPath
$Result = & "Generate_$item" -ManifestPath $ArtifactPath
$Dockerfile += '{0}{1}' -f $Result, "`r`n"
}

Expand Down
5 changes: 4 additions & 1 deletion Image2Docker.psm1
Expand Up @@ -10,7 +10,7 @@ enum ImageType {
$ModulePath = $ExecutionContext.SessionState.Module.ModuleBase

### Import private (internal) functions
$PrivateFunctionList = Get-ChildItem -Path $PSScriptRoot\Functions\Private -File -Filter *.ps1
$PrivateFunctionList = Get-ChildItem -Path $PSScriptRoot\Functions\Private -File -Filter *.ps1 -Recurse
foreach ($File in $PrivateFunctionList) {
. $File.FullName
}
Expand All @@ -24,3 +24,6 @@ foreach ($File in $PublicFunctionList) {
}

Remove-Variable -Name File


Get-ChildItem -Path $PSScriptRoot\completers\*.ps1 | foreach { . $_.FullName}

0 comments on commit 43a89cd

Please sign in to comment.