2121
2222$ErrorActionPreference = ' Stop'
2323$ProgressPreference = ' SilentlyContinue' # Disable Progress bar for faster downloads
24- $LogCommandLifecycleEvent = $true
2524
2625if (! [String ]::IsNullOrWhiteSpace($env: TESTS_DEBUG )) {
2726 $TestsDebug = $env: TESTS_DEBUG
@@ -32,8 +31,7 @@ if (![String]::IsNullOrWhiteSpace($env:AGENT_TYPE)) {
3231 $AgentType = $env: AGENT_TYPE
3332}
3433
35- # $AgentTypes = @('agent', 'inbound-agent')
36- $AgentTypes = @ (' inbound-agent' )
34+ $AgentTypes = @ (' agent' , ' inbound-agent' )
3735if ($AgentType -ne ' ' -and $AgentType -in $AgentTypes ) {
3836 $AgentTypes = @ ($AgentType )
3937}
@@ -175,119 +173,12 @@ Test-CommandExists 'docker-compose'
175173Test-CommandExists ' docker buildx'
176174Test-CommandExists ' yq'
177175
178- # Doc: https://github.com/moby/buildkit/blob/master/docs/windows.md & https://docs.docker.com/build/buildkit/#buildkit-on-windows
179- function Buildkit-Setup {
180- param (
181- [Boolean ] $InstallContainerd = $false ,
182- [Boolean ] $InstallBuildkitd = $false
183- )
184-
185- # Ensure Hyper-V and Containers Windows features are enabled
186- Enable-WindowsOptionalFeature - Online - FeatureName Microsoft- Hyper- V, Containers - All
187-
188- # https://github.com/containerd/containerd/blob/main/docs/getting-started.md#installing-containerd-on-windows
189- if ($InstallContainerd ) {
190- # If containerd previously installed run:
191- Stop-Service containerd
192-
193- # Download and extract desired containerd Windows binaries
194- $Version = " 1.7.13" # update to your preferred version
195- $Arch = " amd64" # arm64 also available
196- curl.exe - LO https:// github.com / containerd/ containerd/ releases/ download/ v$Version / containerd- $Version - windows- $Arch.tar.gz
197- tar.exe xvf .\containerd- $Version - windows- $Arch.tar.gz
198-
199- # Copy
200- Copy-Item - Path .\bin - Destination $Env: ProgramFiles \containerd - Recurse - Force
201-
202- # add the binaries (containerd.exe, ctr.exe) in $env:Path
203- $Path = [Environment ]::GetEnvironmentVariable(" PATH" , " Machine" ) + [IO.Path ]::PathSeparator + " $Env: ProgramFiles \containerd"
204- [Environment ]::SetEnvironmentVariable( " Path" , $Path , " Machine" )
205- # reload path, so you don't have to open a new PS terminal later if needed
206- $Env: Path = [System.Environment ]::GetEnvironmentVariable(" Path" , " Machine" ) + " ;" + [System.Environment ]::GetEnvironmentVariable(" Path" , " User" )
207-
208- # configure
209- containerd.exe config default | Out-File $Env: ProgramFiles \containerd\config.toml - Encoding ascii
210- # Review the configuration. Depending on setup you may want to adjust:
211- # - the sandbox_image (Kubernetes pause image)
212- # - cni bin_dir and conf_dir locations
213- Get-Content $Env: ProgramFiles \containerd\config.toml
214-
215- # Register and start service
216- containerd.exe -- register-service
217- Start-Service containerd
218- }
219-
220- if ($InstallBuildkitd ) {
221- # # Download and extract
222- $url = " https://api.github.com/repos/moby/buildkit/releases/latest"
223- $version = (Invoke-RestMethod - Uri $url - UseBasicParsing).tag_name
224- $arch = " amd64" # arm64 binary available too
225- curl.exe - fSLO https:// github.com / moby/ buildkit/ releases/ download/ $version / buildkit- $version.windows - $arch.tar.gz
226- # there could be another `.\bin` directory from containerd instructions
227- # you can move those
228- mv bin bin2
229- tar.exe xvf .\buildkit- $version.windows - $arch.tar.gz
230- # # x bin/
231- # # x bin/buildctl.exe
232- # # x bin/buildkitd.exe
233-
234- # # Setup buildkitd binaries
235- # after the binaries are extracted in the bin directory
236- # move them to an appropriate path in your $Env:PATH directories or:
237- Copy-Item - Path " .\bin" - Destination " $Env: ProgramFiles \buildkit" - Recurse - Force
238- # add `buildkitd.exe` and `buildctl.exe` binaries in the $Env:PATH
239- $Path = [Environment ]::GetEnvironmentVariable(" PATH" , " Machine" ) + `
240- [IO.Path ]::PathSeparator + " $Env: ProgramFiles \buildkit"
241- [Environment ]::SetEnvironmentVariable( " Path" , $Path , " Machine" )
242- $Env: Path = [System.Environment ]::GetEnvironmentVariable(" Path" , " Machine" ) + " ;" + `
243- [System.Environment ]::GetEnvironmentVariable(" Path" , " User" )
244- }
245- }
246- try {
247- Test-CommandExists ' ctr'
248- } catch {
249- Write-Host ' containerd not found'
250- }
251- try {
252- Test-CommandExists ' buildkitd'
253- } catch {
254- Write-Host ' buildkitd not found'
255- }
256- # try {
257- # Buildkit-Setup -InstallContainerd $false -InstallBuildkitd $false
258- # } catch {}
259-
260- # Sanity checks
261- Invoke-Expression ' docker info'
262- Write-Host ' Checking for Microsoft-Hyper-V feature...'
263- Get-WindowsOptionalFeature - Online - FeatureName ' Microsoft-Hyper-V'
264-
265- # Docker warmup (TODO: proper improvement incoming to pull only the base images from docker bake/compose file)
266- Write-Host ' = PREPARE: Docker warmup (pull base images)'
267- $warmupImages = @ (
268- ' mcr.microsoft.com/windows/servercore:ltsc2019' ,
269- ' mcr.microsoft.com/powershell:nanoserver-1809' ,
270- ' mcr.microsoft.com/windows/nanoserver:ltsc2019'
271- )
272-
273- $warmupJobs = @ ()
274- foreach ($image in $warmupImages ) {
275- $warmupJobs += Start-Job - ScriptBlock {
276- param ($img )
277- Write-Host " == PREPARE: pulling $img "
278- Invoke-Expression " docker pull $img "
279- } - ArgumentList $image
280- }
281- # Wait for all pulls to finish
282- $warmupJobs | ForEach-Object { Receive-Job - Job $_ - Wait; Remove-Job $_ }
283- Invoke-Expression ' docker images ls --tree'
284-
285176$testImageFunction = ${function: Test-Image}
286177$workspacePath = (Get-Location ).Path
287178foreach ($agentType in $AgentTypes ) {
288179 $dockerComposeFile = ' build-windows_{0}_{1}.yaml' -f $AgentType , $ImageType
289180 $baseDockerCmd = ' docker-compose --file={0}' -f $dockerComposeFile
290- $baseDockerBuildCmd = ' {0} build --parallel' -f $baseDockerCmd
181+ $baseDockerBuildCmd = ' {0} build --parallel --pull ' -f $baseDockerCmd
291182
292183 # Generate the docker compose file if it doesn't exists or if the parameter OverwriteDockerComposeFile is set
293184 if ((Test-Path $dockerComposeFile ) -and -not $OverwriteDockerComposeFile ) {
@@ -333,63 +224,42 @@ foreach($agentType in $AgentTypes) {
333224 Write-Host " = TEST: Testing all ${agentType} images..."
334225 $jdks = Invoke-Expression " $baseDockerCmd config" | yq -- unwrapScalar -- output- format json ' .services' | ConvertFrom-Json
335226
336- $testMode = $env: TESTS_MODE
337-
338- if ($testMode -eq ' sequential' ) {
339- Write-Host " == TEST: Setting up Pester environment for $anImage testing..."
340- Import-Module Pester
341- $configuration = [PesterConfiguration ]::Default
342- $configuration.Run.PassThru = $true
343- $configuration.Run.Path = ' {0}\tests' -f $workspacePath
344- $configuration.Run.Exit = $true
345- $configuration.TestResult.Enabled = $true
346- $configuration.TestResult.OutputFormat = ' JUnitXml'
347- $configuration.Output.Verbosity = ' Diagnostic'
348- $configuration.CodeCoverage.Enabled = $false
349-
350- # Run Test-Image sequentially for each JDK
351- Write-Host " = TEST: Starting ${image} tests sequentially..."
352- foreach ($jdk in $jdks.PSObject.Properties ) {
353- $testFailed = $testFailed -or (Test-Image - AgentType $agentType - RemotingVersion $RemotingVersion - ImageName $jdk.Value.image - JavaVersion $jdk.Value.build.args.JAVA_VERSION )
354- }
355- } else {
356- # Run Test-Image in parallel for each JDK
357- $jobs = @ ()
358- foreach ($jdk in $jdks.PSObject.Properties ) {
359- $image = $jdk.Value.image
360- $javaVersion = $jdk.Value.build.args.JAVA_VERSION
361- Write-Host " = TEST: Starting ${image} tests in parallel..."
362- $jobs += Start-Job - ScriptBlock {
363- param ($anAgentType , $aRemotingVersion , $anImage , $aJavaVersion , $aTestImageFunction , $aWorkspacePath )
364-
365- Write-Host " == TEST: Setting up Pester environment for $anImage testing..."
366- Import-Module Pester
367- $configuration = [PesterConfiguration ]::Default
368- $configuration.Run.PassThru = $true
369- $configuration.Run.Path = ' {0}\tests' -f $aWorkspacePath
370- $configuration.Run.Exit = $true
371- $configuration.TestResult.Enabled = $true
372- $configuration.TestResult.OutputFormat = ' JUnitXml'
373- $configuration.Output.Verbosity = ' Diagnostic'
374- $configuration.CodeCoverage.Enabled = $false
375- Set-Item - Path Function:Test-Image - Value $aTestImageFunction
376- Set-Location - Path $aWorkspacePath
377-
378- Test-Image - AgentType $anAgentType - RemotingVersion $aRemotingVersion - ImageName $anImage - JavaVersion $aJavaVersion
379- } - ArgumentList $agentType , $RemotingVersion , $image , $javaVersion , $testImageFunction , $workspacePath
380- }
227+ # Run Test-Image in parallel for each JDK
228+ $jobs = @ ()
229+ foreach ($jdk in $jdks.PSObject.Properties ) {
230+ $image = $jdk.Value.image
231+ $javaVersion = $jdk.Value.build.args.JAVA_VERSION
232+ Write-Host " = TEST: Starting ${image} tests in parallel..."
233+ $jobs += Start-Job - ScriptBlock {
234+ param ($anAgentType , $aRemotingVersion , $anImage , $aJavaVersion , $aTestImageFunction , $aWorkspacePath )
235+
236+ Write-Host " == TEST: Setting up Pester environment for $anImage testing..."
237+ Import-Module Pester
238+ $configuration = [PesterConfiguration ]::Default
239+ $configuration.Run.PassThru = $true
240+ $configuration.Run.Path = ' {0}\tests' -f $aWorkspacePath
241+ $configuration.Run.Exit = $true
242+ $configuration.TestResult.Enabled = $true
243+ $configuration.TestResult.OutputFormat = ' JUnitXml'
244+ $configuration.Output.Verbosity = ' Diagnostic'
245+ $configuration.CodeCoverage.Enabled = $false
246+ Set-Item - Path Function:Test-Image - Value $aTestImageFunction
247+ Set-Location - Path $aWorkspacePath
248+
249+ Test-Image - AgentType $anAgentType - RemotingVersion $aRemotingVersion - ImageName $anImage - JavaVersion $aJavaVersion
250+ } - ArgumentList $agentType , $RemotingVersion , $image , $javaVersion , $testImageFunction , $workspacePath
251+ }
381252
382- # Wait for all jobs to finish and collect results
383- $testFailed = $false
384- foreach ($job in $jobs ) {
385- $result = Receive-Job - Job $job - Wait
386- if ($result.Failed ) {
387- Write-Host " = TEST: Error(s), see the results below"
388- $result.Tests | ConvertTo-Json | Write-Host
389- $testFailed = $true
390- }
391- Remove-Job $job
253+ # Wait for all jobs to finish and collect results
254+ $testFailed = $false
255+ foreach ($job in $jobs ) {
256+ $result = Receive-Job - Job $job - Wait
257+ if ($result.Failed ) {
258+ Write-Host " = TEST: Error(s), see the results below"
259+ $result.Tests | ConvertTo-Json | Write-Host
260+ $testFailed = $true
392261 }
262+ Remove-Job $job
393263 }
394264
395265 # Fail if any test failures
0 commit comments