Skip to content

Commit cf3b072

Browse files
Kevin BatesKevin Bates
authored andcommitted
added support for windows daemon switch
1 parent bfc8725 commit cf3b072

File tree

10 files changed

+163
-75
lines changed

10 files changed

+163
-75
lines changed

DockerPester/DockerPester.psd1

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,103 @@
11
#
2-
# Module manifest for module 'DockerPester'
2+
# Modulmanifest für das Modul "PSGet_DockerPester"
33
#
4-
# Generated by: Kevin Bates
4+
# Generiert von: Kevin Bates
55
#
6-
# Generated on: 22/02/2020
6+
# Generiert am: 26.02.2020
77
#
88

99
@{
1010

11-
# Script module or binary module file associated with this manifest.
11+
# Die diesem Manifest zugeordnete Skript- oder Binärmoduldatei.
1212
RootModule = '.\DockerPester.psm1'
1313

14-
# Version number of this module.
14+
# Die Versionsnummer dieses Moduls
1515
ModuleVersion = '0.3.0'
1616

17-
# Supported PSEditions
17+
# Unterstützte PSEditions
1818
# CompatiblePSEditions = @()
1919

20-
# ID used to uniquely identify this module
20+
# ID zur eindeutigen Kennzeichnung dieses Moduls
2121
GUID = 'f2b4bb05-f099-4745-b73a-96dbddcd07c2'
2222

23-
# Author of this module
23+
# Autor dieses Moduls
2424
Author = 'Kevin Bates'
2525

26-
# Company or vendor of this module
26+
# Unternehmen oder Hersteller dieses Moduls
2727
CompanyName = 'BatesBase'
2828

29-
# Copyright statement for this module
29+
# Urheberrechtserklärung für dieses Modul
3030
Copyright = 'Kevin Bates'
3131

32-
# Description of the functionality provided by this module
32+
# Beschreibung der von diesem Modul bereitgestellten Funktionen
3333
Description = 'Execute Pester Tests in Docker Containers locally.'
3434

35-
# Minimum version of the PowerShell engine required by this module
35+
# Die für dieses Modul mindestens erforderliche Version des Windows PowerShell-Moduls
3636
# PowerShellVersion = ''
3737

38-
# Name of the PowerShell host required by this module
38+
# Der Name des für dieses Modul erforderlichen Windows PowerShell-Hosts
3939
# PowerShellHostName = ''
4040

41-
# Minimum version of the PowerShell host required by this module
41+
# Die für dieses Modul mindestens erforderliche Version des Windows PowerShell-Hosts
4242
# PowerShellHostVersion = ''
4343

44-
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
44+
# Die für dieses Modul mindestens erforderliche Microsoft .NET Framework-Version. Diese erforderliche Komponente ist nur für die PowerShell Desktop-Edition gültig.
4545
# DotNetFrameworkVersion = ''
4646

47-
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
47+
# Die für dieses Modul mindestens erforderliche Version der CLR (Common Language Runtime). Diese erforderliche Komponente ist nur für die PowerShell Desktop-Edition gültig.
4848
# CLRVersion = ''
4949

50-
# Processor architecture (None, X86, Amd64) required by this module
50+
# Die für dieses Modul erforderliche Prozessorarchitektur ("Keine", "X86", "Amd64").
5151
# ProcessorArchitecture = ''
5252

53-
# Modules that must be imported into the global environment prior to importing this module
53+
# Die Module, die vor dem Importieren dieses Moduls in die globale Umgebung geladen werden müssen
5454
# RequiredModules = @()
5555

56-
# Assemblies that must be loaded prior to importing this module
56+
# Die Assemblys, die vor dem Importieren dieses Moduls geladen werden müssen
5757
# RequiredAssemblies = @()
5858

59-
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
59+
# Die Skriptdateien (PS1-Dateien), die vor dem Importieren dieses Moduls in der Umgebung des Aufrufers ausgeführt werden.
6060
# ScriptsToProcess = @()
6161

62-
# Type files (.ps1xml) to be loaded when importing this module
62+
# Die Typdateien (.ps1xml), die beim Importieren dieses Moduls geladen werden sollen
6363
# TypesToProcess = @()
6464

65-
# Format files (.ps1xml) to be loaded when importing this module
65+
# Die Formatdateien (.ps1xml), die beim Importieren dieses Moduls geladen werden sollen
6666
# FormatsToProcess = @()
6767

68-
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
68+
# Die Module, die als geschachtelte Module des in "RootModule/ModuleToProcess" angegebenen Moduls importiert werden sollen.
6969
# NestedModules = @()
7070

71-
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
71+
# Aus diesem Modul zu exportierende Funktionen. Um optimale Leistung zu erzielen, verwenden Sie keine Platzhalter und löschen den Eintrag nicht. Verwenden Sie ein leeres Array, wenn keine zu exportierenden Funktionen vorhanden sind.
7272
FunctionsToExport = 'Add-DockerPesterProject', 'Get-DockerContext', 'Get-DockerImages',
7373
'Get-DockerPesterContext', 'Get-DockerPesterProject',
7474
'Get-LatestDockerPesterResults', 'Invoke-DockerPester',
7575
'Remove-DockerPesterProject', 'Set-DockerPesterContext'
7676

77-
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
77+
# Aus diesem Modul zu exportierende Cmdlets. Um optimale Leistung zu erzielen, verwenden Sie keine Platzhalter und löschen den Eintrag nicht. Verwenden Sie ein leeres Array, wenn keine zu exportierenden Cmdlets vorhanden sind.
7878
CmdletsToExport = @()
7979

80-
# Variables to export from this module
80+
# Die aus diesem Modul zu exportierenden Variablen
8181
# VariablesToExport = @()
8282

83-
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
83+
# Aus diesem Modul zu exportierende Aliase. Um optimale Leistung zu erzielen, verwenden Sie keine Platzhalter und löschen den Eintrag nicht. Verwenden Sie ein leeres Array, wenn keine zu exportierenden Aliase vorhanden sind.
8484
AliasesToExport = @()
8585

86-
# DSC resources to export from this module
86+
# Aus diesem Modul zu exportierende DSC-Ressourcen
8787
# DscResourcesToExport = @()
8888

89-
# List of all modules packaged with this module
89+
# Liste aller Module in diesem Modulpaket
9090
# ModuleList = @()
9191

92-
# List of all files packaged with this module
92+
# Liste aller Dateien in diesem Modulpaket
9393
# FileList = @()
9494

95-
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
95+
# Die privaten Daten, die an das in "RootModule/ModuleToProcess" angegebene Modul übergeben werden sollen. Diese können auch eine PSData-Hashtabelle mit zusätzlichen von PowerShell verwendeten Modulmetadaten enthalten.
9696
PrivateData = @{
9797

98+
#Prerelease of this module
99+
Prerelease = 'alpha'
100+
98101
PSData = @{
99102

100103
# Tags applied to this module. These help with module discovery in online galleries.
@@ -112,23 +115,17 @@ PrivateData = @{
112115
# ReleaseNotes of this module
113116
# ReleaseNotes = ''
114117

115-
# Prerelease string of this module
116-
Prerelease = 'alpha'
117-
118-
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
119-
# RequireLicenseAcceptance = $false
120-
121118
# External dependent modules of this module
122-
# ExternalModuleDependencies = @()
119+
# ExternalModuleDependencies = ''
123120

124121
} # End of PSData hashtable
122+
123+
} # End of PrivateData hashtable
125124

126-
} # End of PrivateData hashtable
127-
128-
# HelpInfo URI of this module
125+
# HelpInfo-URI dieses Moduls
129126
# HelpInfoURI = ''
130127

131-
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
128+
# Standardpräfix für Befehle, die aus diesem Modul exportiert werden. Das Standardpräfix kann mit "Import-Module -Prefix" überschrieben werden.
132129
# DefaultCommandPrefix = ''
133130

134131
}

DockerPester/DockerPester.psm1

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Generated at 02/22/2020 17:31:32 by Kevin Bates
1+
#Generated at 02/26/2020 23:58:36 by Kevin Bates
22
Function DockerPesterRun {
33
param(
44
$ContainerName = "DockerPester",
@@ -11,10 +11,22 @@ Function DockerPesterRun {
1111
$Context
1212
)
1313

14-
Write-DockerPesterHost -Message "Context is set to $Context"
1514

16-
docker context use $Context
17-
15+
if($PSVersionTable.PSVersion.Major -gt 5 -and $IsMacOS -or $IsLinux){
16+
Write-DockerPesterHost -Message "Context is set to $Context"
17+
docker context use $Context
18+
}else{
19+
if($Executor -eq "WIN"){
20+
Write-DockerPesterHost -Message "Daemon switching to Windows Containers. This takes a few seconds..."
21+
& $Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchWindowsEngine
22+
#Start-Sleep -Seconds 15
23+
}elseif($Executor -eq "LNX"){
24+
Write-DockerPesterHost -Message "Daemon switching to Linux Containers. This takes a few seconds..."
25+
& $Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchLinuxEngine
26+
#Start-Sleep -Seconds 15
27+
}
28+
}
29+
1830
if($Executor -eq "WIN"){
1931

2032
Write-DockerPesterHost -Message "Executor is set to 'WIN'"
@@ -32,7 +44,7 @@ Function DockerPesterRun {
3244
$Repository = $Image.Split(":")[0]
3345
$Tag = $Image.Split(":")[1]
3446

35-
if(!((Get-DockerImages).tag.contains("$Tag") -and (Get-DockerImages).Repository.contains("$Repository"))){
47+
if(!((Get-DockerImages).tag.contains("$Tag") -and (Get-DockerImages -erroraction SilentlyContinue).Repository.contains("$Repository"))){
3648
Write-DockerPesterHost -ContainerName $ContainerName -Image $Image -Message "Pulling image $Image because it is not available locally."
3749
docker pull $Image
3850
}
@@ -52,9 +64,19 @@ Function DockerPesterRun {
5264

5365
$CPString = "$($ContainerName):$($PathOnContainer)"
5466

55-
Write-DockerPesterHost -ContainerName $ContainerName -Image $Image -Message "Copy Sources $InputFolder to $PathOnContainer on Container $ContainerName"
67+
if($PSVersionTable.PSVersion.Major -lt 6 -and !($IsMacOS) -or !($IsLinux)){
5668

57-
docker cp $InputFolder $CPString
69+
Write-DockerPesterHost -ContainerName $ContainerName -Image $Image -Message "Copy Sources $InputFolder to $PathOnContainer on Container $ContainerName"
70+
docker stop $ContainerName
71+
docker cp $InputFolder $CPString
72+
docker start $ContainerName
73+
}else{
74+
Write-DockerPesterHost -ContainerName $ContainerName -Image $Image -Message "Copy Sources $InputFolder to $PathOnContainer on Container $ContainerName"
75+
76+
docker cp $InputFolder $CPString
77+
}
78+
79+
5880

5981
Write-DockerPesterHost -ContainerName $ContainerName -Image $Image -Message "Checking for Prerequisite Modules"
6082
docker exec $ContainerName powershell -command "$ProgressPreference = SilentlyContinue"
@@ -81,7 +103,19 @@ Function DockerPesterRun {
81103

82104
$CPString2 = "$($ContainerName):$($PathOnContainer)/Output.json"
83105
$CPString3 = "$($Location)/Output.json"
84-
docker cp $CPString2 $CPString3
106+
107+
if($PSVersionTable.PSVersion.Major -lt 6 -and !($IsMacOS) -or !($IsLinux)){
108+
109+
Write-DockerPesterHost -ContainerName $ContainerName -Image $Image -Message "Copy Sources $InputFolder to $PathOnContainer on Container $ContainerName"
110+
docker stop $ContainerName
111+
docker cp $CPString2 $CPString3
112+
docker start $ContainerName
113+
}else{
114+
Write-DockerPesterHost -ContainerName $ContainerName -Image $Image -Message "Copy Sources $InputFolder to $PathOnContainer on Container $ContainerName"
115+
116+
docker cp $CPString2 $CPString3
117+
}
118+
85119
#docker exec -it $ContainerName pwsh -command "Invoke-Pester $PathToTests -PassThru -Show None"
86120
#docker exec -it $ContainerName pwsh -command "$res | convertto-json"
87121

@@ -240,7 +274,12 @@ Function Add-DockerPesterProject {
240274
$null = New-Item $ConfigFileName -ItemType File
241275
}
242276

243-
$CurrentJSON = Get-Content $ConfigFileName | ConvertFrom-Json -Depth 7
277+
if($PSVersionTable.PSVersion -gt 5){
278+
$CurrentJSON = Get-Content $ConfigFileName | ConvertFrom-Json -Depth 7
279+
}else{
280+
$CurrentJSON = Get-Content $ConfigFileName | ConvertFrom-Json
281+
}
282+
244283

245284
$arr = @()
246285

@@ -250,8 +289,11 @@ Function Add-DockerPesterProject {
250289

251290
$arr += $ConfigObj
252291

253-
$arr | ConvertTo-Json -Depth 7 | Out-File -FilePath $ConfigFileName
254-
292+
if($PSVersionTable.PSVersion -gt 5){
293+
$arr | ConvertTo-Json -Depth 7 | Out-File -FilePath $ConfigFileName
294+
}else{
295+
$arr | ConvertTo-Json | Out-File -FilePath $ConfigFileName
296+
}
255297

256298
}
257299
Function Get-Dockercontext {
@@ -436,7 +478,11 @@ Function Invoke-DockerPester {
436478
$Context = $ParamSet.Context
437479

438480
$Res = get-DockerPesterContext
439-
$Executor = ($Res | ?{$_.Context -eq $Context}).Executor
481+
if($PSVersionTable.PSVersion.Major -gt 5 -and $IsMacOS -or $IsLinux){
482+
$Executor = ($Res | ?{$_.Context -eq $Context}).Executor
483+
}else{
484+
$Executor = $ParamSet.Executor
485+
}
440486

441487
$Hash = @{
442488
ContainerName = $ParamSet.ContainerName

Examples/SetUpProject.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
$Param1 = @{
2-
InputFolder = "/Users/kevin/code/PSAtlas"
3-
Image = "mcr.microsoft.com/windows/servercore:ltsc2019"
4-
Context = "2019-box"
2+
InputFolder = "C:\code\PSHarmonize"
3+
Image = "mcr.microsoft.com/powershell:preview-nanoserver-1803"
4+
Context = "default"
55
Executor = "WIN"
66
}
77

88
Add-DockerPesterProject @Param1
99

1010
$Param2 = @{
11-
InputFolder = "/Users/kevin/code/PSAtlas"
12-
Image = "mcr.microsoft.com/powershell:7.0.0-rc.2-alpine-3.10"
11+
InputFolder = "C:\code\PSHarmonize"
12+
Image = "mcr.microsoft.com/powershell:7.0.0-rc.3-alpine-3.8"
1313
Context = "default"
1414
Executor = "LNX"
1515
}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ Up until now I tested it with the following Docker Images:
2525

2626
| OS | Pull | Pipeline |
2727
| ------------- |:-------------:| -----:|
28-
| Windows servercore 2019 | docker pull mcr.microsoft.com/windows/servercore:ltsc2019 | ![Build Status](https://dev.azure.com/KevinBates0726/DockerPester/_apis/build/status/bateskevin.DockerPester?branchName=master&jobName=servercore_2019) |
29-
| Windows servercore 1809 | docker pull mcr.microsoft.com/windows/servercore:ltsc2019 | ![Build Status](https://dev.azure.com/KevinBates0726/DockerPester/_apis/build/status/bateskevin.DockerPester?branchName=master&jobName=servercore_1809) |
28+
| Windows servercore | docker pull mcr.microsoft.com/powershell:7.0.0-rc.3-windowsservercore-1803-kb4537762-amd64 | ![Build Status](https://dev.azure.com/KevinBates0726/DockerPester/_apis/build/status/bateskevin.DockerPester?branchName=master&jobName=servercore_2019) |
3029
| Alpine 3.8 | docker pull mcr.microsoft.com/powershell:7.0.0-rc.2-alpine-3.8 | ![Build Status](https://dev.azure.com/KevinBates0726/DockerPester/_apis/build/status/bateskevin.DockerPester?branchName=master&jobName=alpine_3_8) |
3130
| Alpine 3.9 | docker pull mcr.microsoft.com/powershell:7.0.0-rc.2-alpine-3.9 | ![Build Status](https://dev.azure.com/KevinBates0726/DockerPester/_apis/build/status/bateskevin.DockerPester?branchName=master&jobName=alpine_3_9) |
3231
| Alpine 3.10 | docker pull mcr.microsoft.com/powershell:7.0.0-rc.2-alpine-3.10 | ![Build Status](https://dev.azure.com/KevinBates0726/DockerPester/_apis/build/status/bateskevin.DockerPester?branchName=master&jobName=alpine_3_10) |

Tests/BaseTests/DockerPester.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Import-Module Pester
22
Import-Module "$PSScriptRoot/../../DockerPester/DockerPester.psd1" -Force
33

44
Describe "Testing Base Funcionality" {
5-
$res = Invoke-DockerPester -Image "mcr.microsoft.com/powershell:preview-nanoserver-1809" -InputFolder "$PSScriptRoot/../TestModule/" -PathOnContainer "C:/Temp" -Executor WIN
5+
$res = Invoke-DockerPester -Image "mcr.microsoft.com/powershell:7.0.0-rc.3-windowsservercore-1803-kb4537762-amd64" -InputFolder "$PSScriptRoot/../TestModule/" -PathOnContainer "C:/Temp" -Executor WIN
66
it "Result should contain PassThru Object from Pester" {
77
$res.TestResult | Should -Not -BeNullOrEmpty
88
}

Tests/WIN/DockerPester.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Import-Module Pester
22
Import-Module "$PSScriptRoot/../../DockerPester/DockerPester.psd1" -Force
33

44
Describe "Testing Base Funcionality" {
5-
$res = Invoke-DockerPester -Image "mcr.microsoft.com/windows/servercore:1809" -InputFolder "$PSScriptRoot/../TestModule/" -PathOnContainer "C:\Temp" -Executor WIN
5+
$res = Invoke-DockerPester -Image "mcr.microsoft.com/powershell:7.0.0-rc.3-windowsservercore-1803-kb4537762-amd64" -InputFolder "$PSScriptRoot/../TestModule/" -PathOnContainer "C:\Temp" -Executor WIN
66
it "Result should contain PassThru Object from Pester" {
77
$res.TestResult | Should -Not -BeNullOrEmpty
88
}

Tests/servercore/DockerPester.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Import-Module Pester
22
Import-Module "$PSScriptRoot/../../DockerPester/DockerPester.psd1" -Force
33

44
Describe "Testing Base Funcionality" {
5-
$res = Invoke-DockerPester -Image "mcr.microsoft.com/windows/servercore:ltsc2019" -InputFolder "$PSScriptRoot/../TestModule/" -Executor WIN -PathToTests "Tests" -PathOnContainer "c:/Temp"
5+
$res = Invoke-DockerPester -Image "mcr.microsoft.com/powershell:7.0.0-rc.3-windowsservercore-1803-kb4537762-amd64" -InputFolder "$PSScriptRoot/../TestModule/" -Executor WIN -PathToTests "Tests" -PathOnContainer "c:/Temp"
66
it "Result should contain PassThru Object from Pester" {
77
$res.TestResult | Should -Not -BeNullOrEmpty
88
}

0 commit comments

Comments
 (0)