mirror of
https://github.com/actions/runner-images.git
synced 2025-12-20 06:35:47 +00:00
Install latest patch versions of golang for linux (#501)
* install golang for linux
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
#!/bin/bash
|
||||
################################################################################
|
||||
## File: go.sh
|
||||
## Desc: Installs go, configures GOROOT, and adds go to the path
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/document.sh
|
||||
|
||||
# This function installs Go using the specified arguments:
|
||||
# $1=MajorVersion (1.11)
|
||||
# $2=MajorAndMinorVersion (1.11.1)
|
||||
# $3=IsDefaultVersion (true or false)
|
||||
function InstallGo () {
|
||||
curl -sL https://dl.google.com/go/go$2.linux-amd64.tar.gz -o go$2.linux-amd64.tar.gz
|
||||
mkdir -p /usr/local/go$1
|
||||
tar -C /usr/local/go$1 -xzf go$2.linux-amd64.tar.gz --strip-components=1 go
|
||||
rm go$2.linux-amd64.tar.gz
|
||||
echo "GOROOT_${1//./_}_X64=/usr/local/go$1" | tee -a /etc/environment
|
||||
DocumentInstalledItem "Go $1 ($(/usr/local/go$1/bin/go version))"
|
||||
|
||||
# If this version of Go is to be the default version,
|
||||
# symlink it into the path and point GOROOT to it.
|
||||
if [ $3 = true ]
|
||||
then
|
||||
ln -s /usr/local/go$1/bin/* /usr/bin/
|
||||
echo "GOROOT=/usr/local/go$1" | tee -a /etc/environment
|
||||
fi
|
||||
}
|
||||
|
||||
# Install Go versions
|
||||
InstallGo 1.9 1.9.7 false
|
||||
InstallGo 1.10 1.10.8 false
|
||||
InstallGo 1.11 1.11.12 false
|
||||
InstallGo 1.12 1.12.7 true
|
||||
InstallGo 1.13 1.13 false
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
################################################################################
|
||||
## File: go.sh
|
||||
## Desc: Installs go, configures GOROOT, and adds go to the path
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/document.sh
|
||||
|
||||
# This function installs Go using the specified arguments:
|
||||
# $1=MajorVersion (1.11)
|
||||
# $2=MajorAndMinorVersion (1.11.1)
|
||||
# $3=IsDefaultVersion (true or false)
|
||||
function InstallGo () {
|
||||
curl -sL https://dl.google.com/go/go$2.linux-amd64.tar.gz -o go$2.linux-amd64.tar.gz
|
||||
mkdir -p /usr/local/go$1
|
||||
tar -C /usr/local/go$1 -xzf go$2.linux-amd64.tar.gz --strip-components=1 go
|
||||
rm go$2.linux-amd64.tar.gz
|
||||
echo "GOROOT_${1//./_}_X64=/usr/local/go$1" | tee -a /etc/environment
|
||||
DocumentInstalledItem "Go $1 ($(/usr/local/go$1/bin/go version))"
|
||||
|
||||
# If this version of Go is to be the default version,
|
||||
# symlink it into the path and point GOROOT to it.
|
||||
if [ $3 = true ]
|
||||
then
|
||||
ln -s /usr/local/go$1/bin/* /usr/bin/
|
||||
echo "GOROOT=/usr/local/go$1" | tee -a /etc/environment
|
||||
fi
|
||||
}
|
||||
|
||||
# Install Go versions
|
||||
InstallGo 1.11 1.11.12 false
|
||||
InstallGo 1.12 1.12.7 true
|
||||
InstallGo 1.13 1.13 false
|
||||
55
images/linux/scripts/installers/go.sh
Normal file
55
images/linux/scripts/installers/go.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
################################################################################
|
||||
## File: go.sh
|
||||
## 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"
|
||||
|
||||
# This function installs Go using the specified arguments:
|
||||
# $1=MajorVersion (1.11)
|
||||
# $2=IsDefaultVersion (true or false)
|
||||
function InstallGo () {
|
||||
version=$( getFullGoVersion $1 )
|
||||
downloadVersion=$version.linux-amd64.tar.gz
|
||||
goFolder=/usr/local/go$1
|
||||
|
||||
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))"
|
||||
|
||||
# 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
|
||||
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)
|
||||
version=$(echo "${version//\"}") # go1.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
|
||||
@@ -23,7 +23,9 @@
|
||||
"capture_name_prefix": "packer",
|
||||
"image_version": "dev",
|
||||
"image_os": "ubuntu16",
|
||||
"github_feed_token": null
|
||||
"github_feed_token": null,
|
||||
"go_default": "1.14",
|
||||
"go_versions": "1.11 1.12 1.13 1.14"
|
||||
},
|
||||
"sensitive-variables": ["client_secret", "github_feed_token"],
|
||||
"builders": [
|
||||
@@ -148,7 +150,6 @@
|
||||
"{{template_dir}}/scripts/installers/gcc.sh",
|
||||
"{{template_dir}}/scripts/installers/gfortran.sh",
|
||||
"{{template_dir}}/scripts/installers/git.sh",
|
||||
"{{template_dir}}/scripts/installers/1604/go.sh",
|
||||
"{{template_dir}}/scripts/installers/google-chrome.sh",
|
||||
"{{template_dir}}/scripts/installers/google-cloud-sdk.sh",
|
||||
"{{template_dir}}/scripts/installers/haskell.sh",
|
||||
@@ -192,6 +193,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": "file",
|
||||
"source": "{{template_dir}}/toolcache-1604.json",
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
"capture_name_prefix": "packer",
|
||||
"image_version": "dev",
|
||||
"image_os": "ubuntu18",
|
||||
"github_feed_token": null
|
||||
"github_feed_token": null,
|
||||
"go_default": "1.14",
|
||||
"go_versions": "1.11 1.12 1.13 1.14"
|
||||
},
|
||||
"sensitive-variables": ["client_secret", "github_feed_token"],
|
||||
"builders": [
|
||||
@@ -151,7 +153,6 @@
|
||||
"{{template_dir}}/scripts/installers/gcc.sh",
|
||||
"{{template_dir}}/scripts/installers/gfortran.sh",
|
||||
"{{template_dir}}/scripts/installers/git.sh",
|
||||
"{{template_dir}}/scripts/installers/1804/go.sh",
|
||||
"{{template_dir}}/scripts/installers/google-chrome.sh",
|
||||
"{{template_dir}}/scripts/installers/google-cloud-sdk.sh",
|
||||
"{{template_dir}}/scripts/installers/haskell.sh",
|
||||
@@ -194,6 +195,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": "file",
|
||||
"source": "{{template_dir}}/toolcache-1804.json",
|
||||
|
||||
Reference in New Issue
Block a user