mirror of
https://github.com/actions/runner-images.git
synced 2026-01-06 10:09:20 +08:00
Toolcache: Add NPM Toolcache support for Windows/Linux
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
"private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}",
|
||||
"vm_size": "Standard_DS4_v2",
|
||||
|
||||
"root_folder": "C:",
|
||||
"image_folder": "C:\\image",
|
||||
"commit_file": "C:\\image\\commit.txt",
|
||||
"metadata_file": "C:\\image\\metadata.txt",
|
||||
@@ -24,7 +25,8 @@
|
||||
"install_user": "installer",
|
||||
"install_password": null,
|
||||
"capture_name_prefix": "packer",
|
||||
"image_version": "dev"
|
||||
"image_version": "dev",
|
||||
"toolcache_registry": "https://buildcanary.pkgs.visualstudio.com/PipelineCanary/_packaging/hostedtoolcache/npm/registry/"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
@@ -268,6 +270,27 @@
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-NodeLts.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-7zip.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"source": "{{template_dir}}/toolcache.json",
|
||||
"destination": "{{user `root_folder`}}/toolcache.json"
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"environment_vars":[
|
||||
"TOOLCACHE_REGISTRY={{ user `toolcache_registry` }}",
|
||||
"ROOT_FOLDER={{user `root_folder`}}"
|
||||
],
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Download-ToolCache.ps1"
|
||||
]
|
||||
@@ -362,12 +385,6 @@
|
||||
"{{ template_dir }}/scripts/Installers/Validate-WinAppDriver.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-NodeLts.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
@@ -450,12 +467,6 @@
|
||||
"{{ template_dir }}/scripts/Installers/Install-AzureCosmosDbEmulator.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-7zip.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"environment_vars": [
|
||||
@@ -562,6 +573,9 @@
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"environment_vars":[
|
||||
"ROOT_FOLDER={{user `root_folder`}}"
|
||||
],
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Validate-ToolCache.ps1"
|
||||
]
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}",
|
||||
"vm_size": "Standard_DS4_v2",
|
||||
|
||||
"root_folder": "C:",
|
||||
"image_folder": "C:\\image",
|
||||
"commit_file": "C:\\image\\commit.txt",
|
||||
"metadata_file": "C:\\image\\metadata.txt",
|
||||
@@ -24,7 +25,8 @@
|
||||
"install_user": "installer",
|
||||
"install_password": null,
|
||||
"capture_name_prefix": "packer",
|
||||
"image_version": "dev"
|
||||
"image_version": "dev",
|
||||
"toolcache_registry": "https://buildcanary.pkgs.visualstudio.com/PipelineCanary/_packaging/hostedtoolcache/npm/registry/"
|
||||
},
|
||||
"sensitive-variables": ["install_password", "ssh_password", "client_secret"],
|
||||
"builders": [
|
||||
@@ -238,6 +240,27 @@
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-NodeLts.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-7zip.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"source": "{{template_dir}}/toolcache.json",
|
||||
"destination": "{{user `root_folder`}}/toolcache.json"
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"environment_vars":[
|
||||
"TOOLCACHE_REGISTRY={{ user `toolcache_registry` }}",
|
||||
"ROOT_FOLDER={{user `root_folder`}}"
|
||||
],
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Download-ToolCache.ps1"
|
||||
]
|
||||
@@ -332,12 +355,6 @@
|
||||
"{{ template_dir }}/scripts/Installers/Validate-WinAppDriver.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-NodeLts.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
@@ -420,12 +437,6 @@
|
||||
"{{ template_dir }}/scripts/Installers/Install-AzureCosmosDbEmulator.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Install-7zip.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"environment_vars": [
|
||||
@@ -532,6 +543,9 @@
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"environment_vars":[
|
||||
"ROOT_FOLDER={{user `root_folder`}}"
|
||||
],
|
||||
"scripts":[
|
||||
"{{ template_dir }}/scripts/Installers/Validate-ToolCache.ps1"
|
||||
]
|
||||
|
||||
@@ -1,51 +1,62 @@
|
||||
################################################################################
|
||||
## File: Download-ToolCache.ps1
|
||||
## Team: CI-Build
|
||||
## Desc: Download tool cache
|
||||
################################################################################
|
||||
|
||||
Function InstallTool
|
||||
{
|
||||
Param
|
||||
(
|
||||
[System.Object]$ExecutablePath
|
||||
Function Install-NpmPackage {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[System.String]
|
||||
$Name,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[System.String]
|
||||
$NpmRegistry
|
||||
)
|
||||
|
||||
Write-Host $ExecutablePath.DirectoryName
|
||||
Set-Location -Path $ExecutablePath.DirectoryName
|
||||
Get-Location | Write-Host
|
||||
if (Test-Path 'tool.zip')
|
||||
{
|
||||
Write-Host "Installing npm '$Name' package from '$NpmRegistry'"
|
||||
|
||||
npm install $Name --registry=$NpmRegistry
|
||||
}
|
||||
|
||||
Function InstallTool {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[System.IO.FileInfo]$ExecutablePath
|
||||
)
|
||||
|
||||
Set-Location -Path $ExecutablePath.DirectoryName -PassThru | Write-Host
|
||||
if (Test-Path 'tool.zip') {
|
||||
Expand-Archive 'tool.zip' -DestinationPath '.'
|
||||
}
|
||||
cmd.exe /c 'install_to_tools_cache.bat'
|
||||
}
|
||||
|
||||
$SourceUrl = "https://vstsagenttools.blob.core.windows.net/tools"
|
||||
|
||||
# HostedToolCache Path
|
||||
$Dest = "C:/"
|
||||
|
||||
$Path = "hostedtoolcache/windows"
|
||||
|
||||
$env:Path = "C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy;" + $env:Path
|
||||
|
||||
Write-Host "Started AzCopy from $SourceUrl to $Dest"
|
||||
|
||||
AzCopy /Source:$SourceUrl /Dest:$Dest /S /V /Pattern:$Path
|
||||
|
||||
$ToolsDirectory = $Dest + $Path
|
||||
|
||||
$current = Get-Location
|
||||
Set-Location -Path $ToolsDirectory
|
||||
|
||||
Get-ChildItem -Recurse -Depth 4 -Filter install_to_tools_cache.bat | ForEach-Object {
|
||||
#In order to work correctly Python 3.4 x86 must be installed after x64, this is achieved by current toolcache catalog structure
|
||||
InstallTool($_)
|
||||
}
|
||||
|
||||
Set-Location -Path $current
|
||||
|
||||
# Define AGENT_TOOLSDIRECTORY environment variable
|
||||
$env:AGENT_TOOLSDIRECTORY = $ToolsDirectory
|
||||
setx AGENT_TOOLSDIRECTORY $ToolsDirectory /M
|
||||
|
||||
# Install tools form NPM
|
||||
|
||||
$ToolVersionsFileContent = Get-Content -Path "$env:ROOT_FOLDER/toolcache.json" -Raw
|
||||
$ToolVersions = ConvertFrom-Json -InputObject $ToolVersionsFileContent
|
||||
|
||||
$ToolVersions.PSObject.Properties | ForEach-Object {
|
||||
$PackageName = $_.Name
|
||||
$PackageVersions = $_.Value
|
||||
$NpmPackages = $PackageVersions | ForEach-Object { "$PackageName@$_" }
|
||||
foreach($NpmPackage in $NpmPackages) {
|
||||
Install-NpmPackage -Name $NpmPackage -NpmRegistry $env:TOOLCACHE_REGISTRY
|
||||
}
|
||||
}
|
||||
|
||||
#junction point from the previous Python2 directory to the toolcache Python2
|
||||
Write-Host "Create symlink to Python2"
|
||||
$python2Dir = (Get-Item -Path ($ToolsDirectory + '/Python/2.7*/x64')).FullName
|
||||
cmd.exe /c mklink /d "C:\Python27amd64" "$python2Dir"
|
||||
|
||||
@@ -1,28 +1,16 @@
|
||||
################################################################################
|
||||
## File: Install-Boost.ps1
|
||||
## File: Set-BoostRoot.ps1
|
||||
## Team: CI-Build
|
||||
## Desc: Install boost using tool cache
|
||||
################################################################################
|
||||
|
||||
$ToolCache = 'C:\hostedtoolcache\windows\boost'
|
||||
$BoostDirectory = Join-Path -Path $env:ProgramFiles -ChildPath "Boost"
|
||||
$BoostVersionsToInstall = $env:BOOST_VERSIONS.split(',')
|
||||
$BoostVersions = $env:BOOST_VERSIONS.split(',')
|
||||
$BoostDefault = $env:BOOST_DEFAULT
|
||||
|
||||
foreach($BoostVersion in $BoostVersionsToInstall)
|
||||
foreach($BoostVersion in $BoostVersions)
|
||||
{
|
||||
$ZipName = Join-Path -Path $ToolCache -ChildPath "boost_${BoostVersion}_msvc-14.1.zip"
|
||||
|
||||
if (-Not (Test-Path $ZipName))
|
||||
{
|
||||
Write-Host "$ZipName not found"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Expanding $ZipName"
|
||||
|
||||
$BoostInstallationDir = Join-Path -Path $BoostDirectory -ChildPath $BoostVersion
|
||||
# Expand-Archive slower for 70% than 7z
|
||||
& "$env:ProgramFiles\7-Zip\7z.exe" x $ZipName -o"$BoostDirectory" -y
|
||||
|
||||
$EnvBoostPath = "BOOST_ROOT_{0}" -f ($BoostVersion.Replace('.', '_'))
|
||||
setx $EnvBoostPath $BoostInstallationDir /M | Out-Null
|
||||
@@ -36,10 +24,3 @@ foreach($BoostVersion in $BoostVersionsToInstall)
|
||||
setx BOOST_ROOT $BoostInstallationDir /M | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
# Removing boost cache folder
|
||||
Write-Host "Removing boost cache folder"
|
||||
if (Test-Path $ToolCache)
|
||||
{
|
||||
Remove-Item -Path $ToolCache -Force -Recurse
|
||||
}
|
||||
|
||||
@@ -12,6 +12,21 @@ function GetChildFolders {
|
||||
return Get-ChildItem -Path $Path -Directory -Name
|
||||
}
|
||||
|
||||
function Get-ToolcachePackages {
|
||||
$toolcachePath = Join-Path $env:ROOT_FOLDER "toolcache.json"
|
||||
return Get-Content -Raw $toolcachePath | ConvertFrom-Json
|
||||
}
|
||||
|
||||
$packages = (Get-ToolcachePackages).PSObject.Properties | ForEach-Object {
|
||||
$packageNameParts = $_.Name.Split("-")
|
||||
$toolName = $packageNameParts[1]
|
||||
return [PSCustomObject] @{
|
||||
ToolName = $packageNameParts[1]
|
||||
Versions = $_.Value
|
||||
Arch = $packageNameParts[3]
|
||||
}
|
||||
}
|
||||
|
||||
function ToolcacheTest {
|
||||
param (
|
||||
[Parameter(Mandatory = $True)]
|
||||
@@ -22,36 +37,53 @@ function ToolcacheTest {
|
||||
if (Test-Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName")
|
||||
{
|
||||
$description = ""
|
||||
[array]$versions = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName"
|
||||
if ($versions.count -gt 0){
|
||||
foreach ($version in $versions)
|
||||
[array]$instaledVersions = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName"
|
||||
if ($instaledVersions.count -gt 0){
|
||||
$softwarePackages = $packages | Where-Object { $_.ToolName -eq $SoftwareName }
|
||||
foreach($softwarePackage in $softwarePackages)
|
||||
{
|
||||
$architectures = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version"
|
||||
|
||||
Write-Host "$SoftwareName version - $version : $([system.String]::Join(",", $architectures))"
|
||||
|
||||
foreach ($arch in $architectures)
|
||||
foreach ($version in $softwarePackage.Versions)
|
||||
{
|
||||
$path = "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version\$arch"
|
||||
foreach ($test in $ExecTests)
|
||||
{
|
||||
if (Test-Path "$path\$test")
|
||||
{
|
||||
Write-Host "$SoftwareName($test) $version($arch) is successfully installed:"
|
||||
Write-Host (& "$path\$test" --version)
|
||||
$foundVersion = $instaledVersions | where { $_.StartsWith($version) }
|
||||
|
||||
if ($foundVersion -ne $null){
|
||||
|
||||
$architectures = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion"
|
||||
|
||||
$softwareArch = $softwarePackage.Arch
|
||||
|
||||
if ($architectures -Contains $softwareArch) {
|
||||
$path = "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion\$softwareArch"
|
||||
foreach ($test in $ExecTests)
|
||||
{
|
||||
if (Test-Path "$path\$test")
|
||||
{
|
||||
Write-Host "$SoftwareName($test) $foundVersion($softwareArch) is successfully installed:"
|
||||
Write-Host (& "$path\$test" --version)
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "$SoftwareName($test) $foundVersion ($softwareArch) is not installed"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
$description += "_Version:_ $foundVersion ($softwareArch)<br/>"
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "$SoftwareName($test) $version ($arch) is not installed"
|
||||
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion does not include required architecture"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
$description += "_Version:_ $version ($arch)<br/>"
|
||||
else
|
||||
{
|
||||
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version.* was not found"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $description
|
||||
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $description
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
17
images/win/toolcache.json
Normal file
17
images/win/toolcache.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"toolcache-python-windows-x64": [
|
||||
"2.7", "3.5", "3.6", "3.7", "3.8"
|
||||
],
|
||||
"toolcache-python-windows-x86": [
|
||||
"2.7", "3.5", "3.6", "3.7", "3.8"
|
||||
],
|
||||
"toolcache-ruby-windows-x64": [
|
||||
"2.4", "2.5", "2.6"
|
||||
],
|
||||
"toolcache-pypy-windows-x86": [
|
||||
"2", "3"
|
||||
],
|
||||
"toolcache-boost-windows-x64": [
|
||||
"1.69"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user