mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-28 12:27:54 +08:00
[Windows] Refactor virtual-env image generation provisioners (#1288)
* refactor virtual-env image generation provisioners
This commit is contained in:
committed by
GitHub
parent
97e1907055
commit
21165eb578
@@ -1,122 +0,0 @@
|
||||
################################################################################
|
||||
## File: Initialize-VM.ps1
|
||||
## Desc: VM initialization script, machine level configuration
|
||||
################################################################################
|
||||
|
||||
function Disable-InternetExplorerESC {
|
||||
$AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
|
||||
$UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
|
||||
Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0 -Force
|
||||
Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0 -Force
|
||||
|
||||
$ieProcess = Get-Process -Name Explorer -ErrorAction SilentlyContinue
|
||||
|
||||
if ($ieProcess){
|
||||
Stop-Process -Name Explorer -Force -ErrorAction Continue
|
||||
}
|
||||
|
||||
Write-Host "IE Enhanced Security Configuration (ESC) has been disabled."
|
||||
}
|
||||
|
||||
function Disable-InternetExplorerWelcomeScreen {
|
||||
$AdminKey = "HKLM:\Software\Policies\Microsoft\Internet Explorer\Main"
|
||||
New-Item -Path $AdminKey -Value 1 -Force
|
||||
Set-ItemProperty -Path $AdminKey -Name "DisableFirstRunCustomize" -Value 1 -Force
|
||||
Write-Host "Disabled IE Welcome screen"
|
||||
}
|
||||
|
||||
function Disable-UserAccessControl {
|
||||
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "ConsentPromptBehaviorAdmin" -Value 00000000 -Force
|
||||
Write-Host "User Access Control (UAC) has been disabled."
|
||||
}
|
||||
|
||||
Write-Host "Disable Antivirus"
|
||||
Set-MpPreference -DisableRealtimeMonitoring $true
|
||||
|
||||
# Disable Windows Update
|
||||
$AutoUpdatePath = "HKLM:SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
|
||||
If (Test-Path -Path $AutoUpdatePath) {
|
||||
Set-ItemProperty -Path $AutoUpdatePath -Name NoAutoUpdate -Value 1
|
||||
Write-Host "Disabled Windows Update"
|
||||
}
|
||||
else {
|
||||
Write-Host "Windows Update key does not exist"
|
||||
}
|
||||
|
||||
# Install .NET Framework 3.5 (required by Chocolatey)
|
||||
Install-WindowsFeature -Name NET-Framework-Features -IncludeAllSubFeature
|
||||
# Explicitly install all 4.7 sub features to include ASP.Net.
|
||||
# As of 1/16/2019, WinServer 19 lists .Net 4.7 as NET-Framework-45-Features
|
||||
Install-WindowsFeature -Name NET-Framework-45-Features -IncludeAllSubFeature
|
||||
# Install FS-iSCSITarget-Server
|
||||
$fsResult = Install-WindowsFeature -Name FS-iSCSITarget-Server -IncludeAllSubFeature -IncludeManagementTools
|
||||
if ( $fsResult.Success ) {
|
||||
Write-Host "FS-iSCSITarget-Server has been successfully installed"
|
||||
} else {
|
||||
Write-Host "Failed to install FS-iSCSITarget-Server"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Disable UAC"
|
||||
Disable-UserAccessControl
|
||||
|
||||
Write-Host "Disable IE Welcome Screen"
|
||||
Disable-InternetExplorerWelcomeScreen
|
||||
|
||||
Write-Host "Disable IE ESC"
|
||||
Disable-InternetExplorerESC
|
||||
|
||||
Write-Host "Setting local execution policy"
|
||||
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine -ErrorAction Continue | Out-Null
|
||||
Get-ExecutionPolicy -List
|
||||
|
||||
Write-Host "Enable long path behavior"
|
||||
# See https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#maximum-path-length-limitation
|
||||
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1
|
||||
|
||||
Write-Host "Install chocolatey"
|
||||
$chocoExePath = 'C:\ProgramData\Chocolatey\bin'
|
||||
|
||||
if ($($env:Path).ToLower().Contains($($chocoExePath).ToLower())) {
|
||||
Write-Host "Chocolatey found in PATH, skipping install..."
|
||||
Exit
|
||||
}
|
||||
|
||||
# Add to system PATH
|
||||
$systemPath = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine)
|
||||
$systemPath += ';' + $chocoExePath
|
||||
[Environment]::SetEnvironmentVariable("PATH", $systemPath, [System.EnvironmentVariableTarget]::Machine)
|
||||
|
||||
# Update local process' path
|
||||
$userPath = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User)
|
||||
if ($userPath) {
|
||||
$env:Path = $systemPath + ";" + $userPath
|
||||
}
|
||||
else {
|
||||
$env:Path = $systemPath
|
||||
}
|
||||
|
||||
# Run the installer
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12"
|
||||
Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
|
||||
|
||||
# Turn off confirmation
|
||||
choco feature enable -n allowGlobalConfirmation
|
||||
|
||||
# https://github.com/chocolatey/choco/issues/89
|
||||
# Remove some of the command aliases, like `cpack` #89
|
||||
Remove-Item -Path $env:ChocolateyInstall\bin\cpack.exe -Force
|
||||
|
||||
# Install webpi
|
||||
Choco-Install -PackageName webpicmd
|
||||
|
||||
# Expand disk size of OS drive
|
||||
New-Item -Path d:\ -Name cmds.txt -ItemType File -Force
|
||||
Add-Content -Path d:\cmds.txt "SELECT VOLUME=C`r`nEXTEND"
|
||||
|
||||
$expandResult = (diskpart /s 'd:\cmds.txt')
|
||||
Write-Host $expandResult
|
||||
|
||||
Write-Host "Disk sizes after expansion"
|
||||
wmic logicaldisk get size,freespace,caption
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
################################################################################
|
||||
## File: Install-VS2019.ps1
|
||||
## Desc: Install Visual Studio 2019
|
||||
################################################################################
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$toolset = Get-ToolsetContent
|
||||
$requiredComponents = $toolset.visualStudio.workloads | ForEach-Object { "--add $_" }
|
||||
$workLoads = @(
|
||||
"--allWorkloads --includeRecommended"
|
||||
$requiredComponents
|
||||
"--remove Component.CPython3.x64"
|
||||
)
|
||||
$workLoadsArgument = [String]::Join(" ", $workLoads)
|
||||
|
||||
$releaseInPath = $toolset.visualStudio.edition
|
||||
$bootstrapperUrl = "https://aka.ms/vs/16/release/vs_${releaseInPath}.exe"
|
||||
|
||||
# Install VS
|
||||
Install-VisualStudio -BootstrapperUrl $bootstrapperUrl -WorkLoads $workLoadsArgument
|
||||
|
||||
# Find the version of VS installed for this instance
|
||||
# Only supports a single instance
|
||||
$vsProgramData = Get-Item -Path "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances"
|
||||
$instanceFolders = Get-ChildItem -Path $vsProgramData.FullName
|
||||
|
||||
if ($instanceFolders -is [array])
|
||||
{
|
||||
Write-Host "More than one instance installed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$visualStudioVersion = $toolset.visualStudio.version
|
||||
$vsInstallRoot = Get-VisualStudioPath -Version $visualStudioVersion -Edition $releaseInPath
|
||||
|
||||
# Initialize Visual Studio Experimental Instance
|
||||
& "$vsInstallRoot\Common7\IDE\devenv.exe" /RootSuffix Exp /ResetSettings General.vssettings /Command File.Exit
|
||||
|
||||
# Updating content of MachineState.json file to disable autoupdate of VSIX extensions
|
||||
$newContent = '{"Extensions":[{"Key":"1e906ff5-9da8-4091-a299-5c253c55fdc9","Value":{"ShouldAutoUpdate":false}},{"Key":"Microsoft.VisualStudio.Web.AzureFunctions","Value":{"ShouldAutoUpdate":false}}],"ShouldAutoUpdate":false,"ShouldCheckForUpdates":false}'
|
||||
Set-Content -Path "$vsInstallRoot\Common7\IDE\Extensions\MachineState.json" -Value $newContent
|
||||
|
||||
# Install Windows 10 SDK version 10.0.14393.795
|
||||
$sdkUrl = "https://go.microsoft.com/fwlink/p/?LinkId=838916"
|
||||
$sdkFileName = "sdksetup14393.exe"
|
||||
$argumentList = ("/q", "/norestart", "/ceip off", "/features OptionId.WindowsSoftwareDevelopmentKit")
|
||||
|
||||
Install-Binary -Url $sdkUrl -Name $sdkFileName -ArgumentList $argumentList
|
||||
|
||||
Invoke-PesterTests -TestFile "VisualStudio"
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
DockerPull mcr.microsoft.com/windows/servercore:ltsc2019
|
||||
DockerPull mcr.microsoft.com/windows/nanoserver:1809
|
||||
DockerPull microsoft/aspnetcore-build:1.0-2.0
|
||||
DockerPull mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
|
||||
DockerPull mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019
|
||||
|
||||
Reference in New Issue
Block a user