From 2ee29eddc1acb9d4a9aa8655ea6266433fe1247f Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev <48208649+miketimofeev@users.noreply.github.com> Date: Fri, 29 Jan 2021 11:38:57 +0300 Subject: [PATCH] [Windows] Add more docker tests and move K8s tools into single provisioner (#2583) * Add more docker tests * Rework tools installation and test * remove docker tests from tools * get back kind installation * transform kind download link to string * add Add-MachinePathItem after kind installation --- .../win/scripts/Installers/Install-Docker.ps1 | 5 +-- .../win/scripts/Installers/Install-Kind.ps1 | 42 ------------------- .../Installers/Install-KubernetesCli.ps1 | 9 ---- .../Installers/Install-KubernetesTools.ps1 | 24 +++++++++++ .../Installers/Update-DockerImages.ps1 | 2 + images/win/scripts/Tests/Docker.Tests.ps1 | 22 ++++++++++ images/win/scripts/Tests/Tools.Tests.ps1 | 29 ++++--------- images/win/windows2016.json | 6 +-- images/win/windows2019.json | 6 +-- 9 files changed, 64 insertions(+), 81 deletions(-) delete mode 100644 images/win/scripts/Installers/Install-Kind.ps1 delete mode 100644 images/win/scripts/Installers/Install-KubernetesCli.ps1 create mode 100644 images/win/scripts/Installers/Install-KubernetesTools.ps1 create mode 100644 images/win/scripts/Tests/Docker.Tests.ps1 diff --git a/images/win/scripts/Installers/Install-Docker.ps1 b/images/win/scripts/Installers/Install-Docker.ps1 index 433d76da4..8c2da9b5b 100644 --- a/images/win/scripts/Installers/Install-Docker.ps1 +++ b/images/win/scripts/Installers/Install-Docker.ps1 @@ -12,7 +12,4 @@ Start-Service docker Write-Host "Install-Package Docker-Compose" Choco-Install -PackageName docker-compose -Write-Host "Install Helm" -Choco-Install -PackageName kubernetes-helm - -Invoke-PesterTests -TestFile "Tools" -TestName "Docker" \ No newline at end of file +Invoke-PesterTests -TestFile "Docker" -TestName "Docker" \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-Kind.ps1 b/images/win/scripts/Installers/Install-Kind.ps1 deleted file mode 100644 index b1c936fc9..000000000 --- a/images/win/scripts/Installers/Install-Kind.ps1 +++ /dev/null @@ -1,42 +0,0 @@ -################################################################################ -## File: Install-Kind.ps1 -## Desc: Install Kind -################################################################################ - -function Get-LatestRelease -{ - $url = 'https://api.github.com/repos/kubernetes-sigs/kind/releases/latest' - (Invoke-RestMethod -Uri $url).assets.browser_download_url -match "kind-windows-amd64" -} - -try -{ - Write-Host "Starting Install kind.exe..." - $destFilePath = "C:\ProgramData\kind" - $null = New-Item -Path $destFilePath -ItemType Directory -Force - - $kindUrl = Get-LatestRelease - $kindInstallerPath = Start-DownloadWithRetry -Url $kindUrl -Name "kind.exe" -DownloadPath $destFilePath - - $process = Start-Process -FilePath $kindInstallerPath -Wait -PassThru - $exitCode = $process.ExitCode - - if ($exitCode -eq 0 -or $exitCode -eq 3010) - { - Write-Host 'Installation successful' - Add-MachinePathItem $destFilePath - } - else - { - Write-Host "Non zero exit code returned by the installation process : $exitCode." - exit $exitCode - } -} -catch -{ - Write-Host "Failed to install the Executable kind.exe" - Write-Host $_.Exception.Message - exit 1 -} - -Invoke-PesterTests -TestFile "Tools" -TestName "Kind" \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-KubernetesCli.ps1 b/images/win/scripts/Installers/Install-KubernetesCli.ps1 deleted file mode 100644 index cf4b8a8f4..000000000 --- a/images/win/scripts/Installers/Install-KubernetesCli.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -################################################################################ -## File: Install-KubernetesCli.ps1 -## Desc: Install KubernetesCli -################################################################################ - -Choco-Install -PackageName kubernetes-cli -Choco-Install -PackageName minikube - -Invoke-PesterTests -TestFile "Tools" -TestName "KubernetesCli" \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-KubernetesTools.ps1 b/images/win/scripts/Installers/Install-KubernetesTools.ps1 new file mode 100644 index 000000000..968cc5362 --- /dev/null +++ b/images/win/scripts/Installers/Install-KubernetesTools.ps1 @@ -0,0 +1,24 @@ +################################################################################ +## File: Install-KubernetesTools.ps1 +## Desc: Install tools for K8s. +################################################################################ + +Write-Host "Install Kind" +# Choco installation can't be used because it depends on docker-desktop +$url = 'https://api.github.com/repos/kubernetes-sigs/kind/releases/latest' +[System.String] $kindDownloadLink = (Invoke-RestMethod -Uri $url).assets.browser_download_url -match "kind-windows-amd64" +$destFilePath = "C:\ProgramData\kind" +$null = New-Item -Path $destFilePath -ItemType Directory -Force +Start-DownloadWithRetry -Url $kindDownloadLink -Name "kind.exe" -DownloadPath $destFilePath +Add-MachinePathItem $destFilePath + +Write-Host "Install Kubectl" +Choco-Install -PackageName kubernetes-cli + +Write-Host "Install Helm" +Choco-Install -PackageName kubernetes-helm + +Write-Host "Install Minikube" +Choco-Install -PackageName minikube + +Invoke-PesterTests -TestFile "Tools" -TestName "KubernetesTools" \ No newline at end of file diff --git a/images/win/scripts/Installers/Update-DockerImages.ps1 b/images/win/scripts/Installers/Update-DockerImages.ps1 index ec5df1b4a..39279e4f9 100644 --- a/images/win/scripts/Installers/Update-DockerImages.ps1 +++ b/images/win/scripts/Installers/Update-DockerImages.ps1 @@ -20,3 +20,5 @@ $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/Docker.Tests.ps1 b/images/win/scripts/Tests/Docker.Tests.ps1 new file mode 100644 index 000000000..697de6a72 --- /dev/null +++ b/images/win/scripts/Tests/Docker.Tests.ps1 @@ -0,0 +1,22 @@ +Describe "Docker" { + It "" -TestCases @( + @{ ToolName = "docker" } + @{ ToolName = "docker-compose" } + ) { + "$ToolName --version" | Should -ReturnZeroExitCode + } + + It "docker service is up" { + "docker images" | Should -ReturnZeroExitCode + } +} + +Describe "DockerImages" { + Context "docker images" { + $testCases = (Get-ToolsetContent).docker.images | ForEach-Object { @{ ImageName = $_ } } + + It "" -TestCases $testCases { + docker images "$ImageName" --format "{{.Repository}}" | Should -Not -BeNullOrEmpty + } + } +} \ 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 a00245321..4b446cd4d 100644 --- a/images/win/scripts/Tests/Tools.Tests.ps1 +++ b/images/win/scripts/Tests/Tools.Tests.ps1 @@ -64,25 +64,6 @@ Describe "DACFx" { "${sqlPackagePath}" | Should -Exist "${sqlLocalDBPath}" | Should -Exist } - } - -Describe "Docker" { - It "" -TestCases @( - @{ ToolName = "docker" } - @{ ToolName = "docker-compose" } - ) { - "$ToolName --version"| Should -ReturnZeroExitCode - } - - It "Helm" { - "helm version --short" | Should -ReturnZeroExitCode - } -} - -Describe "Kind" { - It "Kind" { - "kind version" | Should -ReturnZeroExitCode - } } Describe "DotnetTLS" { @@ -113,11 +94,19 @@ Describe "Mercurial" { } } -Describe "KubernetesCli" { +Describe "KubernetesTools" { + It "Kind" { + "kind version" | Should -ReturnZeroExitCode + } + It "kubectl" { "kubectl version --client=true --short=true" | Should -ReturnZeroExitCode } + It "Helm" { + "helm version --short" | Should -ReturnZeroExitCode + } + It "minikube" { "minikube version --short" | Should -ReturnZeroExitCode } diff --git a/images/win/windows2016.json b/images/win/windows2016.json index f7762385b..c491d6112 100644 --- a/images/win/windows2016.json +++ b/images/win/windows2016.json @@ -139,7 +139,8 @@ "type": "powershell", "environment_vars": [ "IMAGE_VERSION={{user `image_version`}}", - "IMAGEDATA_FILE={{user `imagedata_file`}}" + "IMAGEDATA_FILE={{user `imagedata_file`}}", + "TOOLSET_JSON_PATH={{user `toolset_json_path`}}" ], "scripts": [ "{{ template_dir }}/scripts/Installers/Update-ImageData.ps1", @@ -162,6 +163,7 @@ ], "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", "{{ template_dir }}/scripts/Installers/Windows2016/Install-SSDT.ps1" @@ -313,8 +315,6 @@ "{{ template_dir }}/scripts/Installers/Install-NSIS.ps1", "{{ template_dir }}/scripts/Installers/Install-CloudFoundryCli.ps1", "{{ template_dir }}/scripts/Installers/Install-Vcpkg.ps1", - "{{ template_dir }}/scripts/Installers/Install-KubernetesCli.ps1", - "{{ template_dir }}/scripts/Installers/Install-Kind.ps1", "{{ template_dir }}/scripts/Installers/Install-MongoDB.ps1", "{{ template_dir }}/scripts/Installers/Install-GoogleCloudSDK.ps1", "{{ template_dir }}/scripts/Installers/Install-CodeQLBundle.ps1" diff --git a/images/win/windows2019.json b/images/win/windows2019.json index 24e1ec640..4ce73b8ed 100644 --- a/images/win/windows2019.json +++ b/images/win/windows2019.json @@ -147,7 +147,8 @@ "type": "powershell", "environment_vars": [ "IMAGE_VERSION={{user `image_version`}}", - "IMAGEDATA_FILE={{user `imagedata_file`}}" + "IMAGEDATA_FILE={{user `imagedata_file`}}", + "TOOLSET_JSON_PATH={{user `toolset_json_path`}}" ], "scripts": [ "{{ template_dir }}/scripts/Installers/Update-ImageData.ps1", @@ -170,6 +171,7 @@ ], "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" ], @@ -297,8 +299,6 @@ "{{ template_dir }}/scripts/Installers/Install-CloudFoundryCli.ps1", "{{ template_dir }}/scripts/Installers/Install-Vcpkg.ps1", "{{ template_dir }}/scripts/Installers/Install-PostgreSQL.ps1", - "{{ template_dir }}/scripts/Installers/Install-KubernetesCli.ps1", - "{{ template_dir }}/scripts/Installers/Install-Kind.ps1", "{{ template_dir }}/scripts/Installers/Install-Bazel.ps1", "{{ template_dir }}/scripts/Installers/Install-AliyunCli.ps1", "{{ template_dir }}/scripts/Installers/Install-RootCA.ps1",