Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions images/linux/scripts/installers/go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ golangTags="/tmp/golang_tags.json"
# $2=IsDefaultVersion (true or false)
function InstallGo () {
version=$( getFullGoVersion $1 )
downloadVersion=$version.linux-amd64.tar.gz
goFolder=/usr/local/go$1
downloadVersion="go$version.linux-amd64.tar.gz"
goFolder="$AGENT_TOOLSDIRECTORY/go/$version/x64"

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 $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,
# symlink it into the path and point GOROOT to it.
Expand All @@ -37,8 +40,8 @@ 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)
version=$(echo "${version//\"}") # go1.12.17
version=$(echo "$refValue" | cut -d '/' -f 3 | awk -F 'go' '{print $2}')
version=$(echo "${version//\"}") # 1.12.17
echo $version
}

Expand All @@ -52,4 +55,4 @@ for go in ${GO_VERSIONS}; do
else
InstallGo $go false
fi
done
done
26 changes: 13 additions & 13 deletions images/linux/ubuntu1604.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,6 @@
],
"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",
"source": "{{template_dir}}/toolcache-1604.json",
Expand Down Expand Up @@ -292,6 +279,19 @@
],
"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":[
Expand Down
26 changes: 13 additions & 13 deletions images/linux/ubuntu1804.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,6 @@
],
"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",
"source": "{{template_dir}}/toolcache-1804.json",
Expand Down Expand Up @@ -296,6 +283,19 @@
],
"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":[
Expand Down