diff --git a/ci/dockerfiles/windows/Dockerfile-dhydro-test-environment b/ci/dockerfiles/windows/Dockerfile-dhydro-test-environment index 2f94f0693e..5dbd32deb7 100644 --- a/ci/dockerfiles/windows/Dockerfile-dhydro-test-environment +++ b/ci/dockerfiles/windows/Dockerfile-dhydro-test-environment @@ -13,8 +13,7 @@ RUN Start-Process python-3.12.7-amd64.exe -ArgumentList '/quiet InstallAllUsers= RUN Remove-Item C:\\python-3.12.7-amd64.exe RUN New-Item -ItemType SymbolicLink -Path 'C:\\Program Files\\Python312\\python3.exe' -Target 'C:\\Program Files\\Python312\\python.exe' -ADD win-requirements.txt C:\\temp\\win-requirements.txt +ADD deltares_testbench C:\\deltares_testbench RUN & 'C:\\Program Files\\Python312\\python.exe' -m pip install --upgrade pip; \ - & 'C:\\Program Files\\Python312\\python.exe' -m pip install -r C:\\temp\\win-requirements.txt; \ - Remove-Item C:\\temp\\win-requirements.txt \ No newline at end of file + & 'C:\\Program Files\\Python312\\python.exe' -m pip install -r C:\\deltares_testbench\\pip\\win-requirements.txt \ No newline at end of file diff --git a/ci/teamcity/Delft3D/windows/test.kt b/ci/teamcity/Delft3D/windows/test.kt index 2b8955b582..1dabf48de0 100644 --- a/ci/teamcity/Delft3D/windows/test.kt +++ b/ci/teamcity/Delft3D/windows/test.kt @@ -26,13 +26,7 @@ object WindowsTest : BuildType({ name = "Test" buildNumberPattern = "%product%: %build.vcs.number%" - artifactRules = """ - test\deltares_testbench\data\cases\**\*.pdf => pdf - test\deltares_testbench\data\cases\**\*.dia => logging - test\deltares_testbench\data\cases\**\*.log => logging - test\deltares_testbench\logs => logging - test\deltares_testbench\copy_cases => copy_cases.zip - """.trimIndent() + artifactRules = "artifacts/**" val filePath = "${DslContext.baseDir}/vars/dimr_testbench_table.csv" val processor = CsvProcessor(filePath, "win64") @@ -75,34 +69,81 @@ object WindowsTest : BuildType({ steps { mergeTargetBranch {} - python { - name = "Run TestBench.py" - id = "RUNNER_testbench" - workingDir = "test/deltares_testbench/" - command = file { - filename = "TestBench.py" - scriptArguments = """ - --username "%s3_dsctestbench_accesskey%" - --password "%s3_dsctestbench_secret%" - --compare - --config "configs/%configfile%" - --filter "testcase=%case_filter%" - --log-level DEBUG - --parallel - --teamcity + powerShell { + name = "Run TestBench.py in persistent container" + workingDir = "%system.teamcity.build.checkoutDir%" + scriptMode = script { + content = """ + ${'$'}container = "delft3d-test-%teamcity.build.id%" + + docker run --name ${'$'}container ` + -v "%system.teamcity.build.checkoutDir%\test\deltares_testbench\data\engines:C:\deltares_testbench\data\engines" ` + --memory %teamcity.agent.hardware.memorySizeMb%m ` + --cpus %teamcity.agent.hardware.cpuCount% ` + -e copy_cases="%copy_cases%" ` + containers.deltares.nl/delft3d-dev/test/delft3d-test-environment-windows:%container.tag% ` + powershell -NoLogo -Command "& { + Set-Location C:\deltares_testbench + + python TestBench.py ` + --username '%s3_dsctestbench_accesskey%' ` + --password '%s3_dsctestbench_secret%' ` + --compare ` + --config 'configs/%configfile%' ` + --filter 'testcase=%case_filter%' ` + --log-level DEBUG ` + --parallel ` + --teamcity + + ${'$'}testExit = ${'$'}LASTEXITCODE + + Write-Host '##teamcity[blockOpened name=''Collecting selected artifacts inside container'']' + + ${'$'}inside = 'C:\artifacts_inside' + New-Item -Path ${'$'}inside -ItemType Directory -Force | Out-Null + + robocopy 'data\cases' "${'$'}inside\cases' *.diag *.log *.pdf /S /NJH /NJS /NP | Out-Null + + if (Test-Path 'logs') { + robocopy 'logs' "${'$'}inside\logs' /E /NJH /NJS /NP | Out-Null + } + + if ('%copy_cases%' -eq 'true') { + Compress-Archive -Path 'data\cases\*' -DestinationPath "${'$'}inside\copy_cases.zip" -Force -CompressionLevel Optimal + + ${'$'}size = '{0:N1}' -f ((Get-Item "${'$'}inside\copy_cases.zip").Length / 1MB) + + Write-Host "copy_cases.zip created inside container ($(${'$'}size) MB)" + } + + Write-Host '##teamcity[blockClosed name=''Collecting selected artifacts inside container'']' + + exit ${'$'}testExit + }" """.trimIndent() } - dockerImage = "containers.deltares.nl/delft3d-dev/test/delft3d-test-environment-windows:%container.tag%" - dockerImagePlatform = PythonBuildStep.ImagePlatform.Windows - dockerPull = true - dockerRunParameters = "--memory %teamcity.agent.hardware.memorySizeMb%m --cpus %teamcity.agent.hardware.cpuCount%" } - script { - name = "Copy cases" - executionMode = BuildStep.ExecutionMode.RUN_ON_FAILURE - conditions { equals("copy_cases", "true") } - workingDir = "test/deltares_testbench" - scriptContent = "xcopy \"data\\cases\" \"copy_cases\" /E /I /Y" + powerShell { + name = "Extract artifacts from stopped container" + executionMode = BuildStep.ExecutionMode.ALWAYS + scriptMode = script { + content = """ + ${'$'}container = "delft3d-test-%teamcity.build.id%" + ${'$'}target = "%teamcity.build.checkoutDir%\artifacts" + + New-Item -Path ${'$'}target -ItemType Directory -Force | Out-Null + docker cp "${'$'}container:C:/artifacts_inside/." "${'$'}target\" + """.trimIndent() + } + } + powerShell { + name = "Cleanup container" + executionMode = BuildStep.ExecutionMode.ALWAYS + scriptMode = script { + content = """ + docker rm -f "delft3d-test-%teamcity.build.id%" + """.trimIndent() + } } } diff --git a/ci/teamcity/Delft3D/windows/testEnvironment.kt b/ci/teamcity/Delft3D/windows/testEnvironment.kt index 5a3b186fb6..1d221ac085 100644 --- a/ci/teamcity/Delft3D/windows/testEnvironment.kt +++ b/ci/teamcity/Delft3D/windows/testEnvironment.kt @@ -44,7 +44,7 @@ object WindowsTestEnvironment : BuildType({ # Copy the files from the source to the destination Copy-Item -Path "\\directory.intra\project\d-hydro\dsc-tools\toolchain2024\python-3.12.7-amd64.exe" -Destination ${'$'}destinationDir - Copy-Item -Path "test\\deltares_testbench\\pip\\win-requirements.txt" -Destination ${'$'}destinationDir + Copy-Item -Path "test\\deltares_testbench" -Destination ${'$'}destinationDir -Recurse # List all the files in the destination directory Get-ChildItem -Path ${'$'}destinationDir