Install Go to hostedtoolcache directory on Ubuntu image (#848)

* Move go location to the toolcache
This commit is contained in:
Vladimir Safonkin
2020-05-11 18:26:20 +03:00
committed by GitHub
parent ceef6d41d6
commit fad0a6e41d
3 changed files with 35 additions and 32 deletions

View File

@@ -13,8 +13,8 @@ golangTags="/tmp/golang_tags.json"
# $2=IsDefaultVersion (true or false) # $2=IsDefaultVersion (true or false)
function InstallGo () { function InstallGo () {
version=$( getFullGoVersion $1 ) version=$( getFullGoVersion $1 )
downloadVersion=$version.linux-amd64.tar.gz downloadVersion="go$version.linux-amd64.tar.gz"
goFolder=/usr/local/go$1 goFolder="$AGENT_TOOLSDIRECTORY/go/$version/x64"
echo "Install Go $version" echo "Install Go $version"
curl -sL https://dl.google.com/go/${downloadVersion} -o ${downloadVersion} curl -sL https://dl.google.com/go/${downloadVersion} -o ${downloadVersion}
@@ -22,7 +22,10 @@ function InstallGo () {
tar -C $goFolder -xzf $downloadVersion --strip-components=1 go tar -C $goFolder -xzf $downloadVersion --strip-components=1 go
rm $downloadVersion rm $downloadVersion
echo "GOROOT_${1//./_}_X64=$goFolder" | tee -a /etc/environment echo "GOROOT_${1//./_}_X64=$goFolder" | tee -a /etc/environment
DocumentInstalledItem "Go $1 ($($goFolder/bin/go version))" DocumentInstalledItem "Go $version ($($goFolder/bin/go version))"
# Create symlink in old location /usr/local/go<version> to new location
ln -s $goFolder /usr/local/go$version
# If this version of Go is to be the default version, # If this version of Go is to be the default version,
# symlink it into the path and point GOROOT to it. # symlink it into the path and point GOROOT to it.
@@ -37,8 +40,8 @@ function getFullGoVersion () {
local pattern="refs/tags/go$1([.0-9]{0,3})$" local pattern="refs/tags/go$1([.0-9]{0,3})$"
local query='[.[] | select( .ref | test($pattern))] | .[-1] | .ref' local query='[.[] | select( .ref | test($pattern))] | .[-1] | .ref'
refValue=$(jq --arg pattern "$pattern" "$query" $golangTags) refValue=$(jq --arg pattern "$pattern" "$query" $golangTags)
version=$(echo "$refValue" | cut -d '/' -f 3) version=$(echo "$refValue" | cut -d '/' -f 3 | awk -F 'go' '{print $2}')
version=$(echo "${version//\"}") # go1.12.17 version=$(echo "${version//\"}") # 1.12.17
echo $version echo $version
} }
@@ -52,4 +55,4 @@ for go in ${GO_VERSIONS}; do
else else
InstallGo $go false InstallGo $go false
fi fi
done done

View File

@@ -251,19 +251,6 @@
], ],
"execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" "execute_command": "/bin/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": "file", "type": "file",
"source": "{{template_dir}}/toolcache-1604.json", "source": "{{template_dir}}/toolcache-1604.json",
@@ -292,6 +279,19 @@
], ],
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" "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", "type": "shell",
"scripts":[ "scripts":[

View File

@@ -255,19 +255,6 @@
], ],
"execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" "execute_command": "/bin/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": "file", "type": "file",
"source": "{{template_dir}}/toolcache-1804.json", "source": "{{template_dir}}/toolcache-1804.json",
@@ -296,6 +283,19 @@
], ],
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" "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", "type": "shell",
"scripts":[ "scripts":[