diff --git a/images/linux/scripts/installers/Install-Toolset.ps1 b/images/linux/scripts/installers/Install-Toolset.ps1 index fb5d18255..ce5bfb0d9 100644 --- a/images/linux/scripts/installers/Install-Toolset.ps1 +++ b/images/linux/scripts/installers/Install-Toolset.ps1 @@ -28,7 +28,8 @@ $ErrorActionPreference = "Stop" # Get toolset content $toolsetJson = Get-Content -Path "$env:INSTALLER_SCRIPT_FOLDER/toolset.json" -Raw -$toolsToInstall = @("Python", "Node", "Boost") +$toolsToInstall = @("Python", "Node", "Boost", "Go") + $tools = ConvertFrom-Json -InputObject $toolsetJson | Select-Object -ExpandProperty toolcache | Where {$ToolsToInstall -contains $_.Name} foreach ($tool in $tools) { @@ -54,4 +55,5 @@ foreach ($tool in $tools) { } chown -R "$($env:SUDO_USER):$($env:SUDO_USER)" /opt/hostedtoolcache/Python -chown -R "$($env:SUDO_USER):$($env:SUDO_USER)" /opt/hostedtoolcache/node \ No newline at end of file +chown -R "$($env:SUDO_USER):$($env:SUDO_USER)" /opt/hostedtoolcache/node +chown -R "$($env:SUDO_USER):$($env:SUDO_USER)" /opt/hostedtoolcache/go \ No newline at end of file diff --git a/images/linux/scripts/installers/Validate-Toolset.ps1 b/images/linux/scripts/installers/Validate-Toolset.ps1 index dfb1811c7..5d20dfcaf 100644 --- a/images/linux/scripts/installers/Validate-Toolset.ps1 +++ b/images/linux/scripts/installers/Validate-Toolset.ps1 @@ -9,13 +9,13 @@ function Run-ExecutableTests { [Parameter(Mandatory)] [string[]] $Executables, [Parameter(Mandatory)] [string] $ToolPath ) + $versionCommand = $Executables["command"] - foreach ($executable in $Executables) { + foreach ($executable in $Executables["tools"]) { $executablePath = Join-Path $ToolPath $executable - Write-Host "Check $executable..." if (Test-Path $executablePath) { - Write-Host "$executable is successfully installed: $(& $executablePath --version)" + Write-Host "$executable is successfully installed: $(& $executablePath $versionCommand)" } else { Write-Host "$executablePath is not installed!" exit 1 @@ -27,9 +27,22 @@ $ErrorActionPreference = "Stop" # Define executables for cached tools $toolsExecutables = @{ - Python = @("python", "bin/pip") - node = @("bin/node", "bin/npm") - PyPy = @("bin/python", "bin/pip") + Python = @{ + tools = @("python", "bin/pip") + command = "--version" + } + node = @{ + tools = @("bin/node", "bin/npm") + command = "--version" + } + PyPy = @{ + tools = @("bin/python", "bin/pip") + command = "--version" + } + go = @{ + tools = @("bin/go") + command = "version" + } } # Get toolset content diff --git a/images/linux/scripts/installers/go.sh b/images/linux/scripts/installers/go.sh index 617c406d8..d6f4a9c26 100644 --- a/images/linux/scripts/installers/go.sh +++ b/images/linux/scripts/installers/go.sh @@ -4,55 +4,23 @@ ## Desc: Installs go, configures GOROOT, and adds go to the path ################################################################################ -# Source the helpers for use with the script -source $HELPER_SCRIPTS/document.sh -golangTags="/tmp/golang_tags.json" +# Fail out if any setups fail +set -e -# This function installs Go using the specified arguments: -# $1=MajorVersion (1.11) -# $2=IsDefaultVersion (true or false) -function InstallGo () { - version=$( getFullGoVersion $1 ) - downloadVersion="go$version.linux-amd64.tar.gz" - goFolder="$AGENT_TOOLSDIRECTORY/go/$version/x64" +toolsetJson="$INSTALLER_SCRIPT_FOLDER/toolset.json" +toolsetVersions=(`ls $AGENT_TOOLSDIRECTORY/go`) +defaultVersion=$(jq -r '.toolcache[] | select(.name | contains("go")) | .default' $toolsetJson) - echo "Install Go $version" - curl -sL https://dl.google.com/go/${downloadVersion} -o ${downloadVersion} - mkdir -p $goFolder - tar -C $goFolder -xzf $downloadVersion --strip-components=1 go - rm $downloadVersion - echo "GOROOT_${1//./_}_X64=$goFolder" | tee -a /etc/environment - DocumentInstalledItem "Go $version ($($goFolder/bin/go version))" +for toolsetVersion in ${toolsetVersions[@]} +do + major="$(cut -d'.' -f1 <<< "$toolsetVersion")" + minor="$(cut -d'.' -f2 <<< "$toolsetVersion")" + goFolder="$AGENT_TOOLSDIRECTORY/go/$toolsetVersion/x64" - # Create symlink in old location /usr/local/go to new location - ln -s $goFolder /usr/local/go$version + echo "GOROOT_${major}_${minor}_X64=$goFolder" | tee -a /etc/environment - # If this version of Go is to be the default version, - # symlink it into the path and point GOROOT to it. - if [ $2 = true ] - then + if [[ "$toolsetVersion" =~ $defaultVersion ]]; then ln -s $goFolder/bin/* /usr/bin/ echo "GOROOT=$goFolder" | tee -a /etc/environment fi -} - -function getFullGoVersion () { - local pattern="refs/tags/go$1([.0-9]{0,3})$" - local query='[.[] | select( .ref | test($pattern))] | .[-1] | .ref' - refValue=$(jq --arg pattern "$pattern" "$query" $golangTags) - version=$(echo "$refValue" | cut -d '/' -f 3 | awk -F 'go' '{print $2}') - version=$(echo "${version//\"}") # 1.12.17 - echo $version -} - -# load golang_tags.json file -curl -s 'https://api.github.com/repos/golang/go/git/refs/tags' > $golangTags -# Install Go versions -for go in ${GO_VERSIONS}; do - echo "Installing Go ${go}" - if [[ $go == $GO_DEFAULT ]]; then - InstallGo $go true - else - InstallGo $go false - fi -done +done \ No newline at end of file diff --git a/images/linux/toolset-1604.json b/images/linux/toolset-1604.json index 281e625fd..4cbe78d4f 100644 --- a/images/linux/toolset-1604.json +++ b/images/linux/toolset-1604.json @@ -35,6 +35,19 @@ "14.*" ] }, + { + "name": "go", + "url" : "https://raw.githubusercontent.com/actions/go-versions/master/versions-manifest.json", + "arch": "x64", + "platform" : "linux", + "versions": [ + "1.11.*", + "1.12.*", + "1.13.*", + "1.14.*" + ], + "default": "1.14.*" + }, { "name": "boost", "url" : "https://raw.githubusercontent.com/actions/boost-versions/master/versions-manifest.json", diff --git a/images/linux/toolset-1804.json b/images/linux/toolset-1804.json index e48b1ad1f..ea910cdee 100644 --- a/images/linux/toolset-1804.json +++ b/images/linux/toolset-1804.json @@ -35,6 +35,19 @@ "14.*" ] }, + { + "name": "go", + "url" : "https://raw.githubusercontent.com/actions/go-versions/master/versions-manifest.json", + "arch": "x64", + "platform" : "linux", + "versions": [ + "1.11.*", + "1.12.*", + "1.13.*", + "1.14.*" + ], + "default": "1.14.*" + }, { "name": "boost", "url" : "https://raw.githubusercontent.com/actions/boost-versions/master/versions-manifest.json", diff --git a/images/linux/toolset-2004.json b/images/linux/toolset-2004.json index ce308d15c..c4f53b12e 100644 --- a/images/linux/toolset-2004.json +++ b/images/linux/toolset-2004.json @@ -34,6 +34,16 @@ "12.*", "14.*" ] + }, + { + "name": "go", + "url" : "https://raw.githubusercontent.com/actions/go-versions/master/versions-manifest.json", + "arch": "x64", + "platform" : "linux", + "versions": [ + "1.14.*" + ], + "default": "1.14.*" } ] } \ No newline at end of file diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index bcd7fa276..bb58b7758 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -24,9 +24,7 @@ "image_version": "dev", "image_os": "ubuntu16", "github_feed_token": null, - "run_validation_diskspace": "false", - "go_default": "1.14", - "go_versions": "1.11 1.12 1.13 1.14" + "run_validation_diskspace": "false" }, "sensitive-variables": ["client_secret", "github_feed_token"], "builders": [ @@ -276,19 +274,6 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, - { - "type": "shell", - "scripts": [ - "{{template_dir}}/scripts/installers/go.sh" - ], - "environment_vars": [ - "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "GO_VERSIONS={{user `go_versions`}}", - "GO_DEFAULT={{user `go_default`}}" - ], - "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}" - }, { "type": "shell", "scripts":[ @@ -302,6 +287,16 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" }, + { + "type": "shell", + "scripts": [ + "{{template_dir}}/scripts/installers/go.sh" + ], + "environment_vars": [ + "INSTALLER_SCRIPT_FOLDER={{user `installer_script_folder`}}" + ], + "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" + }, { "type": "shell", "scripts":[ diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index 3af30e620..5cbabc001 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -24,9 +24,7 @@ "image_version": "dev", "image_os": "ubuntu18", "github_feed_token": null, - "run_validation_diskspace": "false", - "go_default": "1.14", - "go_versions": "1.11 1.12 1.13 1.14" + "run_validation_diskspace": "false" }, "sensitive-variables": ["client_secret", "github_feed_token"], "builders": [ @@ -280,19 +278,6 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, - { - "type": "shell", - "scripts": [ - "{{template_dir}}/scripts/installers/go.sh" - ], - "environment_vars": [ - "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "GO_VERSIONS={{user `go_versions`}}", - "GO_DEFAULT={{user `go_default`}}" - ], - "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}" - }, { "type": "shell", "scripts":[ @@ -306,6 +291,16 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" }, + { + "type": "shell", + "scripts": [ + "{{template_dir}}/scripts/installers/go.sh" + ], + "environment_vars": [ + "INSTALLER_SCRIPT_FOLDER={{user `installer_script_folder`}}" + ], + "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" + }, { "type": "shell", "scripts":[ diff --git a/images/linux/ubuntu2004.json b/images/linux/ubuntu2004.json index 3112f0c9a..f4131a455 100644 --- a/images/linux/ubuntu2004.json +++ b/images/linux/ubuntu2004.json @@ -279,19 +279,6 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, - { - "type": "shell", - "scripts": [ - "{{template_dir}}/scripts/installers/go.sh" - ], - "environment_vars": [ - "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "GO_VERSIONS={{user `go_versions`}}", - "GO_DEFAULT={{user `go_default`}}" - ], - "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}" - }, { "type": "shell", "scripts":[ @@ -305,6 +292,16 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" }, + { + "type": "shell", + "scripts": [ + "{{template_dir}}/scripts/installers/go.sh" + ], + "environment_vars": [ + "INSTALLER_SCRIPT_FOLDER={{user `installer_script_folder`}}" + ], + "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" + }, { "type": "shell", "scripts":[