From 892ada55d596e8869f6e771639c7b816e4f25801 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Sun, 1 Aug 2021 15:10:59 +0300 Subject: [PATCH] [Windows] Docker, .NET Core and NPM improvements (#3811) * improve InitializeVM script * Update windows2019.json * remove configs * resolve comments * resolve comments; fix order * fix templates * move Node.js packages to toolset * dotnet warmup and merge docker scripts * Update Node.Tests.ps1 * Update Install-Docker.ps1 * fix node.js tests * fix npm package installation * Update Install-NodeLts.ps1 * fix tests * fix test --- .../win/scripts/Installers/Install-Docker.ps1 | 13 +++++- .../scripts/Installers/Install-DotnetSDK.ps1 | 44 ++++++++++--------- .../scripts/Installers/Install-NodeLts.ps1 | 13 ++---- .../scripts/Installers/Install-TypeScript.ps1 | 8 ---- .../Installers/Update-DockerImages.ps1 | 24 ---------- images/win/scripts/Tests/Node.Tests.ps1 | 16 +++---- images/win/scripts/Tests/Tools.Tests.ps1 | 6 --- images/win/toolsets/toolset-2016.json | 18 +++++++- images/win/toolsets/toolset-2019.json | 18 +++++++- images/win/windows2016.json | 2 - images/win/windows2019.json | 2 - 11 files changed, 81 insertions(+), 83 deletions(-) delete mode 100644 images/win/scripts/Installers/Install-TypeScript.ps1 delete mode 100644 images/win/scripts/Installers/Update-DockerImages.ps1 diff --git a/images/win/scripts/Installers/Install-Docker.ps1 b/images/win/scripts/Installers/Install-Docker.ps1 index 8c2da9b5b..cb713ca4d 100644 --- a/images/win/scripts/Installers/Install-Docker.ps1 +++ b/images/win/scripts/Installers/Install-Docker.ps1 @@ -12,4 +12,15 @@ Start-Service docker Write-Host "Install-Package Docker-Compose" Choco-Install -PackageName docker-compose -Invoke-PesterTests -TestFile "Docker" -TestName "Docker" \ No newline at end of file +$dockerImages = (Get-ToolsetContent).docker.images +foreach ($dockerImage in $dockerImages) { + Write-Host "Pulling docker image $dockerImage ..." + docker pull $dockerImage + + if (!$?) { + Write-Host "Docker pull failed with a non-zero exit code" + exit 1 + } +} + +Invoke-PesterTests -TestFile "Docker" \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-DotnetSDK.ps1 b/images/win/scripts/Installers/Install-DotnetSDK.ps1 index 12b4a701c..27cd6d39c 100644 --- a/images/win/scripts/Installers/Install-DotnetSDK.ps1 +++ b/images/win/scripts/Installers/Install-DotnetSDK.ps1 @@ -12,16 +12,26 @@ Set-SystemVariable -SystemVariable DOTNET_MULTILEVEL_LOOKUP -Value "0" [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12" -$templates = @( - 'console', - 'mstest', - 'web', - 'mvc', - 'webapi' -) +function Invoke-Warmup ( + $SdkVersion +) { + # warm up dotnet for first time experience + $projectTypes = @('console', 'mstest', 'web', 'mvc', 'webapi') + $projectTypes | ForEach-Object { + $template = $_ + $projectPath = Join-Path -Path C:\temp -ChildPath $template + New-Item -Path $projectPath -Force -ItemType Directory + Push-Location -Path $projectPath + & $env:ProgramFiles\dotnet\dotnet.exe new globaljson --sdk-version "$sdkVersion" + & $env:ProgramFiles\dotnet\dotnet.exe new $template + Pop-Location + Remove-Item $projectPath -Force -Recurse + } +} function InstallSDKVersion ( - $sdkVersion + $SdkVersion, + $Warmup ) { if (!(Test-Path -Path "C:\Program Files\dotnet\sdk\$sdkVersion")) @@ -40,16 +50,8 @@ function InstallSDKVersion ( $sdkTargetsPath = "C:\Program Files\dotnet\sdk\$sdkVersion\Sdks\Microsoft.NET.Sdk\targets" Start-DownloadWithRetry -Url $sdkTargetsUrl -DownloadPath $sdkTargetsPath -Name $sdkTargetsName - # warm up dotnet for first time experience - $templates | ForEach-Object { - $template = $_ - $projectPath = Join-Path -Path C:\temp -ChildPath $template - New-Item -Path $projectPath -Force -ItemType Directory - Push-Location -Path $projectPath - & $env:ProgramFiles\dotnet\dotnet.exe new globaljson --sdk-version "$sdkVersion" - & $env:ProgramFiles\dotnet\dotnet.exe new $template - Pop-Location - Remove-Item $projectPath -Force -Recurse + if ($Warmup) { + Invoke-Warmup -SdkVersion $SdkVersion } } @@ -57,7 +59,9 @@ function InstallAllValidSdks() { # Consider all channels except preview/eol channels. # Sort the channels in ascending order - $dotnetVersions = (Get-ToolsetContent).dotnet.versions + $dotnetToolset = (Get-ToolsetContent).dotnet + $dotnetVersions = $dotnetToolset.versions + $warmup = $dotnetToolset.warmup # Download installation script. $installationName = "dotnet-install.ps1" @@ -93,7 +97,7 @@ function InstallAllValidSdks() elseif (!$release.'sdk'.'version'.Contains('-')) { $sdkVersion = $release.'sdk'.'version' - InstallSDKVersion -sdkVersion $sdkVersion + InstallSDKVersion -SdkVersion $sdkVersion -Warmup $warmup } } } diff --git a/images/win/scripts/Installers/Install-NodeLts.ps1 b/images/win/scripts/Installers/Install-NodeLts.ps1 index 2a74cc14d..3b91ad201 100644 --- a/images/win/scripts/Installers/Install-NodeLts.ps1 +++ b/images/win/scripts/Installers/Install-NodeLts.ps1 @@ -21,14 +21,9 @@ $env:npm_config_prefix = $PrefixPath npm config set cache $CachePath --global npm config set registry https://registry.npmjs.org/ -npm install -g cordova -npm install -g grunt-cli -npm install -g gulp-cli -npm install -g parcel-bundler -npm install -g --save-dev webpack webpack-cli -npm install -g yarn -npm install -g lerna -npm install -g node-sass -npm install -g newman +$globalNpmPackages = (Get-ToolsetContent).npm.global_packages +$globalNpmPackages | ForEach-Object { + npm install -g $_.name +} Invoke-PesterTests -TestFile "Node" diff --git a/images/win/scripts/Installers/Install-TypeScript.ps1 b/images/win/scripts/Installers/Install-TypeScript.ps1 deleted file mode 100644 index d413c1000..000000000 --- a/images/win/scripts/Installers/Install-TypeScript.ps1 +++ /dev/null @@ -1,8 +0,0 @@ -################################################################################ -## File: Install-TypeScript.ps1 -## Desc: Install Latest TypeScript -################################################################################ - -npm install -g typescript - -Invoke-PesterTests -TestFile "Tools" -TestName "Typescript" diff --git a/images/win/scripts/Installers/Update-DockerImages.ps1 b/images/win/scripts/Installers/Update-DockerImages.ps1 deleted file mode 100644 index 39279e4f9..000000000 --- a/images/win/scripts/Installers/Update-DockerImages.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -## File: Update-DockerImages.ps1 -## Desc: Pull some standard docker images. -## Must be run after docker is installed. -################################################################################ - -function DockerPull { - Param ([string]$image) - - Write-Host Installing $image ... - docker pull $image - - if (!$?) { - Write-Host "Docker pull failed with a non-zero exit code" - exit 1 - } -} - -$dockerToolset = (Get-ToolsetContent).docker -foreach($dockerImage in $dockerToolset.images) { - DockerPull $dockerImage -} - -Invoke-PesterTests -TestFile "Docker" -TestName "DockerImages" \ No newline at end of file diff --git a/images/win/scripts/Tests/Node.Tests.ps1 b/images/win/scripts/Tests/Node.Tests.ps1 index cb8883ad4..58577276e 100644 --- a/images/win/scripts/Tests/Node.Tests.ps1 +++ b/images/win/scripts/Tests/Node.Tests.ps1 @@ -4,18 +4,16 @@ Describe "Node.JS" { @{ ToolName = "node" } @{ ToolName = "npm" } ) { - "$ToolName --version" | Should -ReturnZeroExitCode + "$ToolName --version" | Should -ReturnZeroExitCode } } + + $globalNpmPackages = (Get-ToolsetContent).npm.global_packages + $globalNpmPackagesWithTests = $globalNpmPackages | Where-Object { $_.test } | ForEach-Object { @{ Name = $_.name; Test = $_.test } } + Context "Global NPM Packages" { - It " " -TestCases @( - @{ ToolName = "gulp" } - @{ ToolName = "grunt" } - @{ ToolName = "yarn" } - @{ ToolName = "lerna" } - @{ ToolName = "newman" } - ) { - "$ToolName --version" | Should -ReturnZeroExitCode + It "" -TestCases $globalNpmPackagesWithTests { + $Test | Should -ReturnZeroExitCode } } } \ No newline at end of file diff --git a/images/win/scripts/Tests/Tools.Tests.ps1 b/images/win/scripts/Tests/Tools.Tests.ps1 index 0827a4cce..03756723e 100644 --- a/images/win/scripts/Tests/Tools.Tests.ps1 +++ b/images/win/scripts/Tests/Tools.Tests.ps1 @@ -139,12 +139,6 @@ Describe "Stack" { } } -Describe "Typescript" { - It "tsc" { - "tsc --version" | Should -ReturnZeroExitCode - } -} - Describe "Vcpkg" { It "vcpkg" { "vcpkg version" | Should -ReturnZeroExitCode diff --git a/images/win/toolsets/toolset-2016.json b/images/win/toolsets/toolset-2016.json index 8f6354834..f9a4b28f7 100644 --- a/images/win/toolsets/toolset-2016.json +++ b/images/win/toolsets/toolset-2016.json @@ -340,12 +340,28 @@ "cmd": "yamllint --version" } ], + "npm": { + "global_packages": [ + { "name": "yarn", "test": "yarn --version" }, + { "name": "newman", "test": "newman --version" }, + { "name": "lerna", "test": "lerna --version" }, + { "name": "typescript", "test": "tsc --version" }, + { "name": "cordova" }, + { "name": "grunt-cli", "test": "grunt --version" }, + { "name": "gulp-cli", "test": "gulp --version" }, + { "name": "parcel-bundler" }, + { "name": "webpack" }, + { "name": "webpack-cli" }, + { "name": "node-sass" } + ] + }, "dotnet": { "versions": [ "2.1", "3.1", "5.0" - ] + ], + "warmup": true }, "choco": { "common_packages": [ diff --git a/images/win/toolsets/toolset-2019.json b/images/win/toolsets/toolset-2019.json index 28d8873a1..40e8d6b8a 100644 --- a/images/win/toolsets/toolset-2019.json +++ b/images/win/toolsets/toolset-2019.json @@ -368,12 +368,28 @@ "cmd": "yamllint --version" } ], + "npm": { + "global_packages": [ + { "name": "yarn", "test": "yarn --version" }, + { "name": "newman", "test": "newman --version" }, + { "name": "lerna", "test": "lerna --version" }, + { "name": "typescript", "test": "tsc --version" }, + { "name": "cordova" }, + { "name": "grunt-cli", "test": "grunt --version" }, + { "name": "gulp-cli", "test": "gulp --version" }, + { "name": "parcel-bundler" }, + { "name": "webpack" }, + { "name": "webpack-cli" }, + { "name": "node-sass" } + ] + }, "dotnet": { "versions": [ "2.1", "3.1", "5.0" - ] + ], + "warmup": true }, "choco": { "common_packages": [ diff --git a/images/win/windows2016.json b/images/win/windows2016.json index bb4cd77cb..7445431ed 100644 --- a/images/win/windows2016.json +++ b/images/win/windows2016.json @@ -172,7 +172,6 @@ "TOOLSET_JSON_PATH={{user `toolset_json_path`}}" ], "scripts": [ - "{{ template_dir }}/scripts/Installers/Update-DockerImages.ps1", "{{ template_dir }}/scripts/Installers/Install-KubernetesTools.ps1", "{{ template_dir }}/scripts/Installers/Install-VS.ps1", "{{ template_dir }}/scripts/Installers/Install-NET48.ps1", @@ -304,7 +303,6 @@ "type": "powershell", "scripts": [ "{{ template_dir }}/scripts/Installers/Install-Mingw64.ps1", - "{{ template_dir }}/scripts/Installers/Install-TypeScript.ps1", "{{ template_dir }}/scripts/Installers/Install-Haskell.ps1", "{{ template_dir }}/scripts/Installers/Install-Stack.ps1", "{{ template_dir }}/scripts/Installers/Install-Miniconda.ps1", diff --git a/images/win/windows2019.json b/images/win/windows2019.json index a9e17fb52..18c63ed85 100644 --- a/images/win/windows2019.json +++ b/images/win/windows2019.json @@ -180,7 +180,6 @@ "TOOLSET_JSON_PATH={{user `toolset_json_path`}}" ], "scripts": [ - "{{ template_dir }}/scripts/Installers/Update-DockerImages.ps1", "{{ template_dir }}/scripts/Installers/Install-KubernetesTools.ps1", "{{ template_dir }}/scripts/Installers/Install-VS.ps1", "{{ template_dir }}/scripts/Installers/Install-NET48.ps1" @@ -287,7 +286,6 @@ "{{ template_dir }}/scripts/Installers/Install-SQLPowerShellTools.ps1", "{{ template_dir }}/scripts/Installers/Install-DotnetSDK.ps1", "{{ template_dir }}/scripts/Installers/Install-Mingw64.ps1", - "{{ template_dir }}/scripts/Installers/Install-TypeScript.ps1", "{{ template_dir }}/scripts/Installers/Install-Haskell.ps1", "{{ template_dir }}/scripts/Installers/Install-Stack.ps1", "{{ template_dir }}/scripts/Installers/Install-Miniconda.ps1",