Merge branch 'master' of https://github.com/miketimofeev/virtual-environments into v-mitim/get_rid_of_apt.sh_invocation

This commit is contained in:
Mikhail Timofeev
2020-07-10 12:35:52 +03:00
31 changed files with 303 additions and 308 deletions

View File

@@ -14,9 +14,9 @@ download_with_retries() {
local COMPRESSED="$4" local COMPRESSED="$4"
if [ $COMPRESSED == "compressed" ]; then if [ $COMPRESSED == "compressed" ]; then
COMMAND="curl $URL -4 -s --compressed -o '$DEST/$NAME'" COMMAND="curl $URL -4 -sL --compressed -o '$DEST/$NAME'"
else else
COMMAND="curl $URL -4 -s -o '$DEST/$NAME'" COMMAND="curl $URL -4 -sL -o '$DEST/$NAME'"
fi fi
echo "Downloading $URL..." echo "Downloading $URL..."

View File

@@ -1,84 +0,0 @@
#!/bin/bash
################################################################################
## File: basic.sh
## Desc: Installs basic command line utilities and dev packages
################################################################################
# Source the helpers for use with the script
source $HELPER_SCRIPTS/document.sh
set -e
common_packages="dnsutils
iproute2
iputils-ping
libc++-dev
libc++abi-dev
libcurl3
libicu55
libunwind8
locales
openssh-client
tzdata
zstd
lib32z1
libxkbfile-dev
pkg-config
libsecret-1-dev
libxss1
libgconf-2-4
dbus
xvfb
libgbm-dev
libgtk-3-0
tk
fakeroot
dpkg
rpm
xz-utils
xorriso
zsync
gnupg2
texinfo"
cmd_packages="curl
file
ftp
jq
netcat
ssh
parallel
rsync
shellcheck
sudo
telnet
time
unzip
zip
wget
upx
m4
bison
flex"
# Install basic command-line utilities
for package in $common_packages $cmd_packages; do
echo "Install $package"
apt-fast install -y --no-install-recommends $package
done
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
for cmd in $cmd_packages; do
if ! command -v $cmd; then
echo "$cmd was not installed"
exit 1
fi
done
# Document what was added to the image
echo "Lastly, documenting what we added to the metadata file"
DocumentInstalledItem "Basic packages:"
for package in $common_packages $cmd_packages; do
DocumentInstalledItemIndent $package
done

View File

@@ -37,7 +37,8 @@ common_packages="dnsutils
zsync zsync
gnupg2 gnupg2
lib32z1 lib32z1
texinfo" texinfo
libsqlite3-dev"
cmd_packages="curl cmd_packages="curl
file file
@@ -56,7 +57,10 @@ cmd_packages="curl
wget wget
m4 m4
bison bison
flex" flex
patchelf
bzip2
sqlite3"
if isUbuntu20 ; then if isUbuntu20 ; then
echo "Install python2" echo "Install python2"
@@ -64,7 +68,7 @@ if isUbuntu20 ; then
fi fi
echo "Install libcurl" echo "Install libcurl"
if isUbuntu18 ; then if isUbuntu16 || isUbuntu18; then
libcurelVer="libcurl3" libcurelVer="libcurl3"
fi fi
@@ -74,12 +78,19 @@ fi
apt-get install -y --no-install-recommends $libcurelVer apt-get install -y --no-install-recommends $libcurelVer
# install additional packages only for Ubuntu16.04
if isUbuntu16; then
common_packages="$common_packages
libc++-dev
libc++abi-dev
libicu55"
fi
for package in $common_packages $cmd_packages; do for package in $common_packages $cmd_packages; do
echo "Install $package" echo "Install $package"
apt-get install -y --no-install-recommends $package apt-get install -y --no-install-recommends $package
done done
# Run tests to determine that the software installed as expected # Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work" echo "Testing to make sure that script performed as expected, and basic scenarios work"
for cmd in $cmd_packages; do for cmd in $cmd_packages; do

View File

@@ -0,0 +1,30 @@
#!/bin/bash
################################################################################
## File: oras-cli.sh
## Desc: Installs ORAS CLI
################################################################################
# Source the helpers for use with the script
source $HELPER_SCRIPTS/document.sh
source $HELPER_SCRIPTS/install.sh
# Determine latest ORAS CLI version
ORAS_CLI_LATEST_VERSION_URL=https://api.github.com/repos/deislabs/oras/releases/latest
ORAS_CLI_DOWNLOAD_URL=$(curl -s $ORAS_CLI_LATEST_VERSION_URL | jq -r '.assets[].browser_download_url | select(contains("linux_amd64.tar.gz"))')
ORAS_CLI_ARCHIVE=$(basename $ORAS_CLI_DOWNLOAD_URL)
# Install ORAS CLI
cd /tmp
download_with_retries $ORAS_CLI_DOWNLOAD_URL
tar -zxvf $ORAS_CLI_ARCHIVE -C /usr/local/bin oras
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! oras version; then
echo "ORAS CLI was not installed"
exit 1
fi
# Document what was added to the image
echo "Lastly, documenting what we added to the metadata file"
DocumentInstalledItem "ORAS CLI $(oras version | awk 'NR==1{print $2}')"

View File

@@ -19,13 +19,15 @@ source $CARGO_HOME/env
# Install common tools # Install common tools
rustup component add rustfmt clippy rustup component add rustfmt clippy
cargo install bindgen cbindgen cargo install bindgen cbindgen
cargo install cargo-audit
cargo install cargo-outdated
echo "Test installation of the Rust toochain" echo "Test installation of the Rust toochain"
# Permissions # Permissions
chmod -R 777 $(dirname $RUSTUP_HOME) chmod -R 777 $(dirname $RUSTUP_HOME)
for cmd in rustup rustc rustdoc cargo rustfmt cargo-clippy bindgen cbindgen; do for cmd in rustup rustc rustdoc cargo rustfmt cargo-clippy bindgen cbindgen 'cargo audit' 'cargo outdated'; do
if ! command -v $cmd --version; then if ! command -v $cmd --version; then
echo "$cmd was not installed or is not found on the path" echo "$cmd was not installed or is not found on the path"
exit 1 exit 1
@@ -54,3 +56,5 @@ DocumentInstalledItem "clippy ($(cargo-clippy --version 2>&1 | cut -d ' ' -f 2))
DocumentInstalledItem "rustdoc ($(rustdoc --version 2>&1 | cut -d ' ' -f 2))" DocumentInstalledItem "rustdoc ($(rustdoc --version 2>&1 | cut -d ' ' -f 2))"
DocumentInstalledItem "bindgen ($(bindgen --version 2>&1 | cut -d ' ' -f 2))" DocumentInstalledItem "bindgen ($(bindgen --version 2>&1 | cut -d ' ' -f 2))"
DocumentInstalledItem "cbindgen ($(cbindgen --version 2>&1 | cut -d ' ' -f 2))" DocumentInstalledItem "cbindgen ($(cbindgen --version 2>&1 | cut -d ' ' -f 2))"
DocumentInstalledItem "cargo audit ($(cargo audit --version 2>&1 | cut -d ' ' -f 2))"
DocumentInstalledItem "cargo outdated ($(cargo outdated --version 2>&1 | cut -d ' ' -f 2))"

View File

@@ -143,7 +143,7 @@
"{{template_dir}}/scripts/installers/azcopy.sh", "{{template_dir}}/scripts/installers/azcopy.sh",
"{{template_dir}}/scripts/installers/azure-cli.sh", "{{template_dir}}/scripts/installers/azure-cli.sh",
"{{template_dir}}/scripts/installers/azure-devops-cli.sh", "{{template_dir}}/scripts/installers/azure-devops-cli.sh",
"{{template_dir}}/scripts/installers/1604/basic.sh", "{{template_dir}}/scripts/installers/basic.sh",
"{{template_dir}}/scripts/installers/aliyun-cli.sh", "{{template_dir}}/scripts/installers/aliyun-cli.sh",
"{{template_dir}}/scripts/installers/aws.sh", "{{template_dir}}/scripts/installers/aws.sh",
"{{template_dir}}/scripts/installers/build-essential.sh", "{{template_dir}}/scripts/installers/build-essential.sh",
@@ -177,6 +177,7 @@
"{{template_dir}}/scripts/installers/mysql.sh", "{{template_dir}}/scripts/installers/mysql.sh",
"{{template_dir}}/scripts/installers/nodejs.sh", "{{template_dir}}/scripts/installers/nodejs.sh",
"{{template_dir}}/scripts/installers/bazel.sh", "{{template_dir}}/scripts/installers/bazel.sh",
"{{template_dir}}/scripts/installers/oras-cli.sh",
"{{template_dir}}/scripts/installers/phantomjs.sh", "{{template_dir}}/scripts/installers/phantomjs.sh",
"{{template_dir}}/scripts/installers/php.sh", "{{template_dir}}/scripts/installers/php.sh",
"{{template_dir}}/scripts/installers/pollinate.sh", "{{template_dir}}/scripts/installers/pollinate.sh",

View File

@@ -181,6 +181,7 @@
"{{template_dir}}/scripts/installers/nvm.sh", "{{template_dir}}/scripts/installers/nvm.sh",
"{{template_dir}}/scripts/installers/nodejs.sh", "{{template_dir}}/scripts/installers/nodejs.sh",
"{{template_dir}}/scripts/installers/bazel.sh", "{{template_dir}}/scripts/installers/bazel.sh",
"{{template_dir}}/scripts/installers/oras-cli.sh",
"{{template_dir}}/scripts/installers/phantomjs.sh", "{{template_dir}}/scripts/installers/phantomjs.sh",
"{{template_dir}}/scripts/installers/php.sh", "{{template_dir}}/scripts/installers/php.sh",
"{{template_dir}}/scripts/installers/pollinate.sh", "{{template_dir}}/scripts/installers/pollinate.sh",

View File

@@ -183,6 +183,7 @@
"{{template_dir}}/scripts/installers/nvm.sh", "{{template_dir}}/scripts/installers/nvm.sh",
"{{template_dir}}/scripts/installers/nodejs.sh", "{{template_dir}}/scripts/installers/nodejs.sh",
"{{template_dir}}/scripts/installers/bazel.sh", "{{template_dir}}/scripts/installers/bazel.sh",
"{{template_dir}}/scripts/installers/oras-cli.sh",
"{{template_dir}}/scripts/installers/phantomjs.sh", "{{template_dir}}/scripts/installers/phantomjs.sh",
"{{template_dir}}/scripts/installers/php.sh", "{{template_dir}}/scripts/installers/php.sh",
"{{template_dir}}/scripts/installers/pollinate.sh", "{{template_dir}}/scripts/installers/pollinate.sh",

View File

@@ -2,7 +2,7 @@
- System Version: macOS 10.15.5 (19F101) - System Version: macOS 10.15.5 (19F101)
- Kernel Version: Darwin 19.5.0 - Kernel Version: Darwin 19.5.0
- System Integrity Protection: Enabled - System Integrity Protection: Enabled
- Image Version: 20200625.2 - Image Version: 20200702.1
## Installed Software ## Installed Software
### Language and Runtime ### Language and Runtime
@@ -18,9 +18,9 @@
- gcc-9 (Homebrew GCC 9.3.0_1) 9.3.0 - gcc-9 (Homebrew GCC 9.3.0_1) 9.3.0
- GNU Fortran (Homebrew GCC 8.4.0_1) 8.4.0 - GNU Fortran (Homebrew GCC 8.4.0_1) 8.4.0
- GNU Fortran (Homebrew GCC 9.3.0_1) 9.3.0 - GNU Fortran (Homebrew GCC 9.3.0_1) 9.3.0
- Node.js v12.18.1 - Node.js v12.18.2
- NVM 0.35.3 - NVM 0.35.3
- NVM - Cached node versions: v6.17.1 v8.17.0 v10.21.0 v12.18.1 v13.14.0 v14.4.0 - NVM - Cached node versions: v6.17.1 v8.17.0 v10.21.0 v12.18.2 v13.14.0 v14.5.0
- PowerShell 7.0.2 - PowerShell 7.0.2
- Python 2.7.17 - Python 2.7.17
- Python 3.7.7 - Python 3.7.7
@@ -36,7 +36,7 @@
- Bundler version 2.1.4 - Bundler version 2.1.4
- Carthage 0.35.0 - Carthage 0.35.0
- CocoaPods 1.9.3 - CocoaPods 1.9.3
- Homebrew 2.4.2 - Homebrew 2.4.3
- NPM 6.14.5 - NPM 6.14.5
- Yarn 1.22.4 - Yarn 1.22.4
- NuGet 5.6.0.6489 - NuGet 5.6.0.6489
@@ -47,10 +47,10 @@
### Project Management ### Project Management
- Apache Maven 3.6.3 - Apache Maven 3.6.3
- Gradle 6.5 - Gradle 6.5.1
### Utilities ### Utilities
- Curl 7.71.0 - Curl 7.71.1
- Git: 2.27.0 - Git: 2.27.0
- Git LFS: 2.11.0 - Git LFS: 2.11.0
- GitHub CLI: 0.10.1 - GitHub CLI: 0.10.1
@@ -67,7 +67,7 @@
- aria2 1.35.0 - aria2 1.35.0
- azcopy 10.4.3 - azcopy 10.4.3
- zstd 1.4.5 - zstd 1.4.5
- bazel 3.3.0 - bazel 3.3.1
- bazelisk v1.5.0 - bazelisk v1.5.0
- helm v3.2.4+g0ad800e - helm v3.2.4+g0ad800e
- virtualbox 6.1.10r138449 - virtualbox 6.1.10r138449
@@ -77,13 +77,13 @@
- 7-Zip 16.02 - 7-Zip 16.02
### Tools ### Tools
- Fastlane 2.149.1 - Fastlane 2.150.1
- Cmake 3.17.3 - Cmake 3.17.3
- App Center CLI 2.6.0 - App Center CLI 2.6.1
- Azure CLI 2.8.0 - Azure CLI 2.8.0
- AWS CLI 2.0.25 - AWS CLI 2.0.27
- AWS SAM CLI 0.53.0 - AWS SAM CLI 0.53.0
- Aliyun CLI 3.0.48 - Aliyun CLI 3.0.49
- GHCup v0.1.5-p2 - GHCup v0.1.5-p2
- GHC 8.10.1 - GHC 8.10.1
- Cabal 3.2.0.0 - Cabal 3.2.0.0
@@ -94,9 +94,9 @@
- SafariDriver 13.1.1 (15609.2.9.1.2) - SafariDriver 13.1.1 (15609.2.9.1.2)
- Google Chrome 83.0.4103.116 - Google Chrome 83.0.4103.116
- ChromeDriver 83.0.4103.39 - ChromeDriver 83.0.4103.39
- Microsoft Edge 83.0.478.56 - Microsoft Edge 83.0.478.58
- MSEdgeDriver 83.0.478.56 - MSEdgeDriver 83.0.478.58
- Mozilla Firefox 77.0.1 - Mozilla Firefox 78.0.1
- geckodriver 0.26.0 - geckodriver 0.26.0
### Cached Tools ### Cached Tools
@@ -109,8 +109,8 @@
#### Python #### Python
- 2.7.18 - 2.7.18
- 3.5.9 - 3.5.9
- 3.6.10 - 3.6.11
- 3.7.7 - 3.7.8
- 3.8.3 - 3.8.3
#### PyPy #### PyPy

View File

@@ -84,6 +84,11 @@
"source": "{{ template_dir }}/scripts/SoftwareReport", "source": "{{ template_dir }}/scripts/SoftwareReport",
"destination": "{{user `image_folder`}}" "destination": "{{user `image_folder`}}"
}, },
{
"type": "file",
"source": "{{ template_dir }}/scripts/Tests",
"destination": "{{user `image_folder`}}"
},
{ {
"type": "windows-shell", "type": "windows-shell",
"inline": [ "inline": [
@@ -839,18 +844,6 @@
"{{ template_dir }}/scripts/Installers/Validate-AliyunCli.ps1" "{{ template_dir }}/scripts/Installers/Validate-AliyunCli.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-JavaTools.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Cmake.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -911,12 +904,6 @@
"{{ template_dir }}/scripts/Installers/Validate-AzureCosmosDbEmulator.ps1" "{{ template_dir }}/scripts/Installers/Validate-AzureCosmosDbEmulator.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-7zip.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -983,18 +970,6 @@
"{{ template_dir }}/scripts/Installers/Validate-KubernetesCli.ps1" "{{ template_dir }}/scripts/Installers/Validate-KubernetesCli.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Kind.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-MongoDB.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -1019,6 +994,12 @@
"type": "windows-restart", "type": "windows-restart",
"restart_timeout": "10m" "restart_timeout": "10m"
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Tests/RunAll-Tests.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"inline": [ "inline": [

View File

@@ -84,6 +84,11 @@
"source": "{{ template_dir }}/scripts/SoftwareReport", "source": "{{ template_dir }}/scripts/SoftwareReport",
"destination": "{{user `image_folder`}}" "destination": "{{user `image_folder`}}"
}, },
{
"type": "file",
"source": "{{ template_dir }}/scripts/Tests",
"destination": "{{user `image_folder`}}"
},
{ {
"type": "windows-shell", "type": "windows-shell",
"inline": [ "inline": [
@@ -109,6 +114,14 @@
], ],
"execution_policy": "unrestricted" "execution_policy": "unrestricted"
}, },
{
"type": "powershell",
"elevated_user": "SYSTEM",
"elevated_password": "",
"scripts":[
"{{ template_dir }}/scripts/Installers/Windows2019/Install-WSL.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -243,6 +256,12 @@
"{{ template_dir }}/scripts/Installers/Validate-Wix.ps1" "{{ template_dir }}/scripts/Installers/Validate-Wix.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-WSL.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -812,18 +831,6 @@
"{{ template_dir }}/scripts/Installers/Validate-NodeLts.ps1" "{{ template_dir }}/scripts/Installers/Validate-NodeLts.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-JavaTools.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Cmake.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -885,12 +892,6 @@
] ]
}, },
{ {
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-7zip.ps1"
]
},
{
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Packer.ps1" "{{ template_dir }}/scripts/Installers/Validate-Packer.ps1"
@@ -962,18 +963,6 @@
"{{ template_dir }}/scripts/Installers/Validate-KubernetesCli.ps1" "{{ template_dir }}/scripts/Installers/Validate-KubernetesCli.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Kind.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-MongoDB.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"scripts":[ "scripts":[
@@ -1010,6 +999,12 @@
"type": "windows-restart", "type": "windows-restart",
"restart_timeout": "10m" "restart_timeout": "10m"
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Tests/RunAll-Tests.ps1"
]
},
{ {
"type": "powershell", "type": "powershell",
"inline": [ "inline": [

View File

@@ -4,6 +4,7 @@ param()
. $PSScriptRoot\PathHelpers.ps1 . $PSScriptRoot\PathHelpers.ps1
. $PSScriptRoot\InstallHelpers.ps1 . $PSScriptRoot\InstallHelpers.ps1
. $PSScriptRoot\ChocoHelpers.ps1 . $PSScriptRoot\ChocoHelpers.ps1
. $PSScriptRoot\TestsHelpers.ps1
Export-ModuleMember -Function @( Export-ModuleMember -Function @(
'Test-MachinePath' 'Test-MachinePath'
@@ -28,4 +29,7 @@ Export-ModuleMember -Function @(
'Test-IsWin16' 'Test-IsWin16'
'Choco-Install' 'Choco-Install'
'Extract-7Zip' 'Extract-7Zip'
'Get-CommandResult'
'Get-EnvironmentVariable'
'Invoke-PesterTests'
) )

View File

@@ -0,0 +1,96 @@
function Get-CommandResult {
Param (
[Parameter(Mandatory)][string] $Command
)
# CMD trick to suppress and show error output because some commands write to stderr (for example, "python --version")
[string[]]$output = & $env:comspec /c "$Command 2>&1"
$exitCode = $LASTEXITCODE
return @{
Output = $output
ExitCode = $exitCode
}
}
# Gets value of environment variable by the name
function Get-EnvironmentVariable($variable) {
return [System.Environment]::GetEnvironmentVariable($variable)
}
# Update environment variables without reboot
function Update-Environment {
$variables = [Environment]::GetEnvironmentVariables("Machine")
$variables.Keys | ForEach-Object {
$key = $_
$value = $variables[$key]
Set-Item -Path "env:$key" -Value $value
}
# We need to refresh PATH the latest one because it could include other variables "%M2_HOME%/bin"
$env:PATH = [Environment]::GetEnvironmentVariable("PATH", "Machine")
}
# Run Pester tests for specific tool
function Invoke-PesterTests {
Param(
[Parameter(Mandatory)][string] $TestFile,
[string] $TestName
)
$testPath = "C:\image\Tests\${TestFile}.Tests.ps1"
if (-not (Test-Path $testPath)) {
throw "Unable to find test file '$TestFile' on '$testPath'."
}
$configuration = [PesterConfiguration] @{
Run = @{ Path = $testPath; PassThru = $true }
Output = @{ Verbosity = "Detailed" }
}
if ($TestName) {
$configuration.Filter.FullName = $TestName
}
# Update environment variables without reboot
Update-Environment
# Switch ErrorActionPreference to Stop temporary to make sure that tests will on silent errors too
$backupErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "Stop"
$results = Invoke-Pester -Configuration $configuration
$ErrorActionPreference = $backupErrorActionPreference
# Fail in case if no tests are run
if (-not ($results -and ($results.FailedCount -eq 0) -and ($results.PassedCount -gt 0))) {
$results
throw "Test run has failed"
}
}
# Pester Assert to check exit code of command
function ShouldReturnZeroExitCode {
Param(
[String] $ActualValue,
[switch] $Negate,
[string] $Because
)
$result = Get-CommandResult $ActualValue
[bool]$succeeded = $result.ExitCode -eq 0
if ($Negate) { $succeeded = -not $succeeded }
if (-not $succeeded)
{
$сommandOutputIndent = " " * 4
$commandOutput = ($result.Output | ForEach-Object { "${сommandOutputIndent}${_}" }) -join "`n"
$failureMessage = "Command '${ActualValue}' has finished with exit code ${actualExitCode}`n${commandOutput}"
}
return [PSCustomObject] @{
Succeeded = $succeeded
FailureMessage = $failureMessage
}
}
If (Get-Command -Name Add-AssertionOperator -ErrorAction SilentlyContinue) {
Add-AssertionOperator -Name ReturnZeroExitCode -InternalName ShouldReturnZeroExitCode -Test ${function:ShouldReturnZeroExitCode}
}

View File

@@ -4,3 +4,5 @@
################################################################################ ################################################################################
Choco-Install -PackageName 7zip.install Choco-Install -PackageName 7zip.install
Invoke-PesterTests -TestFile "Tools" -TestName "7-Zip"

View File

@@ -4,3 +4,5 @@
################################################################################ ################################################################################
Choco-Install -PackageName cmake.install -ArgumentList "--installargs",'ADD_CMAKE_TO_PATH=""System""' Choco-Install -PackageName cmake.install -ArgumentList "--installargs",'ADD_CMAKE_TO_PATH=""System""'
Invoke-PesterTests -TestFile "Tools" -TestName "CMake"

View File

@@ -126,3 +126,5 @@ $archivePath = Start-DownloadWithRetry -Url $uri -Name "cobertura.zip"
Extract-7Zip -Path $archivePath -DestinationPath "C:\" Extract-7Zip -Path $archivePath -DestinationPath "C:\"
setx COBERTURA_HOME $coberturaPath /M setx COBERTURA_HOME $coberturaPath /M
Invoke-PesterTests -TestFile "Java"

View File

@@ -38,3 +38,5 @@ catch
Write-Host $_.Exception.Message Write-Host $_.Exception.Message
exit 1 exit 1
} }
Invoke-PesterTests -TestFile "Tools" -TestName "Kind"

View File

@@ -7,3 +7,5 @@ Choco-Install -PackageName mongodb
$mongoPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'mongodb'").PathName $mongoPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'mongodb'").PathName
$mongoBin = Split-Path -Path $mongoPath.split('"')[1] $mongoBin = Split-Path -Path $mongoPath.split('"')[1]
Add-MachinePathItem "$mongoBin" Add-MachinePathItem "$mongoBin"
Invoke-PesterTests -TestFile "Databases" -TestName "MongoDB"

View File

@@ -1,16 +0,0 @@
################################################################################
## File: Validate-Cmake.ps1
## Desc: Validate Cmake
################################################################################
if(Get-Command -Name 'cmake')
{
Write-Host "CMake $(cmake -version) on path"
}
else
{
Write-Host "CMake not on path"
exit 1
}

View File

@@ -1,79 +0,0 @@
################################################################################
## File: Validate-JavaTools.ps1
## Desc: Validate various JDKs and java tools
################################################################################
Function Validate-JavaVersion {
param (
[Parameter(Mandatory)] [string] $Version,
[switch] $Default
)
Write-Host "Checking Java $version"
# Set Path to get Java
if (-not $Default)
{
# Take 7 & 8 for versions 1.7 and 1.8
$versionNumber = $version.Split(".") | Select-Object -Last 1
$javaPath = [System.Environment]::GetEnvironmentVariable("JAVA_HOME_${versionNumber}_X64")
if ([string]::IsNullOrEmpty($javaPath))
{
Write-Host "Environment variable 'JAVA_HOME_${versionNumber}_X64' is null"
exit 1
}
$javaBin = "$javaPath\bin;"
$env:Path = $javaBin + $env:Path
}
else
{
Validate-JavaVersion -Version $Version
}
$isJavaExists = $($(& $env:comspec "/s /c java -version 2>&1") | Out-String) -match '^(?<vendor>.+) version "(?<version>.+)".*'
if ($isJavaExists)
{
$javaVersion = $matches.version
}
else
{
Write-Host "Java $version was not found"
exit 1
}
$isJavaCorrect = $javaVersion.StartsWith($version)
if($isJavaCorrect)
{
Write-Host "Java $javaVersion found"
# Reset Path to the default one in case we need to check the default Java later
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
}
else
{
Write-Host "Expected Java $version, but found $javaVersion"
exit 1
}
}
if((Get-Command -Name 'java') -and (Get-Command -Name 'mvn') -and (Get-Command -Name 'ant') -and (Get-Command -Name 'gradle'))
{
Write-Host "Java $(java -version) on path"
Write-Host "Maven $(mvn -version) on path"
Write-Host "Ant $(ant -version) on path"
Write-Host "Gradle $(gradle -version) on path"
}
else
{
Write-Host "one of Java,Maven,Ant,Gradle is not on path."
exit 1
}
Write-Host "Checking installed Java versions"
Validate-JavaVersion -Version "1.7"
Validate-JavaVersion -Version "1.8" -Default
Validate-JavaVersion -Version "11"
Validate-JavaVersion -Version "13"

View File

@@ -1,14 +0,0 @@
################################################################################
## File: Validate-Kind.ps1
## Desc: Validate Kind.
################################################################################
if (Get-Command -Name 'kind')
{
Write-Host "kind $(kind version) in path"
}
else
{
Write-Host "kind is not in path"
exit 1
}

View File

@@ -1,24 +0,0 @@
################################################################################
## File: Validate-MongoDB.ps1
## Desc: Validate MongoDB
################################################################################
if (Get-Command -Name 'mongod')
{
Write-Host 'mongod is on path'
}
else
{
Write-Host 'mongod not on path'
exit 1
}
if (Get-Command -Name 'mongo')
{
Write-Host 'mongo is on path'
}
else
{
Write-Host 'mongo not on path'
exit 1
}

View File

@@ -1,15 +1,14 @@
################################################################################ ################################################################################
## File: Validate-7zip.ps1 ## File: Validate-WSL.ps1
## Desc: Validate 7zip ## Desc: Validate WSL CLI existst
################################################################################ ################################################################################
if (Get-Command -Name '7z') if (Get-Command -Name 'wsl')
{ {
Write-Host '7zip on path' Write-Host 'wsl is on path'
} }
else else
{ {
Write-Host '7zip is not on path' Write-Host 'wsl not on path'
exit 1 exit 1
} }

View File

@@ -41,6 +41,8 @@ Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name PowerShellGet -Force Install-Module -Name PowerShellGet -Force
Set-PSRepository -InstallationPolicy Trusted -Name PSGallery Set-PSRepository -InstallationPolicy Trusted -Name PSGallery
Write-Host "Install the latest Pester version"
Install-Module Pester -Scope AllUsers -SkipPublisherCheck -Force
Write-Host "Disable Antivirus" Write-Host "Disable Antivirus"
Set-MpPreference -DisableRealtimeMonitoring $true Set-MpPreference -DisableRealtimeMonitoring $true

View File

@@ -38,6 +38,8 @@ Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name PowerShellGet -Force Install-Module -Name PowerShellGet -Force
Set-PSRepository -InstallationPolicy Trusted -Name PSGallery Set-PSRepository -InstallationPolicy Trusted -Name PSGallery
Write-Host "Install the latest Pester version"
Install-Module Pester -Scope AllUsers -SkipPublisherCheck -Force
Write-Host "Disable Antivirus" Write-Host "Disable Antivirus"
Set-MpPreference -DisableRealtimeMonitoring $true Set-MpPreference -DisableRealtimeMonitoring $true

View File

@@ -0,0 +1,8 @@
################################################################################
## File: Install-WSL.ps1
## Desc: Install Windows Subsystem for Linux
################################################################################
Write-Host "Install Windows Subsystem for Linux"
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart

View File

@@ -22,6 +22,11 @@ $markdown += New-MDList -Style Unordered -Lines @(
"Image Version: $env:ImageVersion" "Image Version: $env:ImageVersion"
) )
$markdown += New-MDHeader "Enabled windows optional features" -Level 2
$markdown += New-MDList -Style Unordered -Lines @(
"Windows Subsystem for Linux"
)
$markdown += New-MDHeader "Installed Software" -Level 2 $markdown += New-MDHeader "Installed Software" -Level 2
$markdown += New-MDHeader "Language and Runtime" -Level 3 $markdown += New-MDHeader "Language and Runtime" -Level 3

View File

@@ -0,0 +1,8 @@
Describe "MongoDB" {
It "<ToolName>" -TestCases @(
@{ ToolName = "mongo" }
@{ ToolName = "mongod" }
) {
"$ToolName --version" | Should -ReturnZeroExitCode
}
}

View File

@@ -0,0 +1,36 @@
Describe "Java" {
It "Java <DefaultJavaVersion> is default" -TestCases @(@{ DefaultJavaVersion = 8 }) {
$actualJavaPath = Get-EnvironmentVariable "JAVA_HOME"
$expectedJavaPath = Get-EnvironmentVariable "JAVA_HOME_${DefaultJavaVersion}_X64"
$actualJavaPath | Should -Not -BeNullOrEmpty
$expectedJavaPath | Should -Not -BeNullOrEmpty
$actualJavaPath | Should -Be $expectedJavaPath
}
It "<ToolName>" -TestCases @(
@{ ToolName = "java" }
@{ ToolName = "mvn" }
@{ ToolName = "ant" }
@{ ToolName = "gradle" }
) {
"$ToolName -version" | Should -ReturnZeroExitCode
}
It "Java <Version>" -TestCases @(
@{ Version = "1.7" }
@{ Version = "1.8" }
@{ Version = "11" }
@{ Version = "13" }
) {
$versionNumber = $version.Split(".") | Select-Object -Last 1
$javaVariableValue = Get-EnvironmentVariable "JAVA_HOME_${versionNumber}_X64"
$javaVariableValue | Should -Not -BeNullOrEmpty
$javaPath = Join-Path $javaVariableValue "bin\java"
$result = Get-CommandResult "`"$javaPath`" -version"
$result.ExitCode | Should -Be 0
$result.Output[0] | Should -Match ([regex]::Escape("openjdk version `"${Version}."))
}
}

View File

@@ -0,0 +1 @@
Invoke-PesterTests "*"

View File

@@ -0,0 +1,17 @@
Describe "7-Zip" {
It "7z" {
"7z" | Should -ReturnZeroExitCode
}
}
Describe "CMake" {
It "cmake" {
"cmake --version" | Should -ReturnZeroExitCode
}
}
Describe "Kind" {
It "Kind" {
"kind version" | Should -ReturnZeroExitCode
}
}