mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
dev: modify Go install to support arch64 and non-vagrant machines. (#16651)
This commit is contained in:
2
Vagrantfile
vendored
2
Vagrantfile
vendored
@@ -130,7 +130,7 @@ def configureLinuxProvisioners(vmCfg)
|
||||
|
||||
vmCfg.vm.provision "shell",
|
||||
privileged: true,
|
||||
path: './scripts/vagrant-linux-priv-go.sh'
|
||||
path: './scripts/linux-priv-go.sh'
|
||||
|
||||
vmCfg.vm.provision "shell",
|
||||
privileged: true,
|
||||
|
||||
67
scripts/linux-priv-go.sh
Executable file
67
scripts/linux-priv-go.sh
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
|
||||
# Identify the user we are running as. If it's as root, we assume Vagrant
|
||||
# which isn't great, but is better than the old behaviour.
|
||||
USER=""
|
||||
case $(whoami) in
|
||||
root) USER="vagrant" ;;
|
||||
*) USER=$(whoami) ;;
|
||||
esac
|
||||
|
||||
# Minimal effort to support amd64 and arm64 installs.
|
||||
ARCH=""
|
||||
case $(arch) in
|
||||
x86_64) ARCH="amd64" ;;
|
||||
aarch64) ARCH="arm64" ;;
|
||||
esac
|
||||
|
||||
function install_go() {
|
||||
local go_version="1.20.2"
|
||||
local download="https://storage.googleapis.com/golang/go${go_version}.linux-${ARCH}.tar.gz"
|
||||
|
||||
if go version 2>&1 | grep -q "${go_version}"; then
|
||||
return
|
||||
fi
|
||||
|
||||
# remove previous older version
|
||||
sudo rm -rf /usr/local/go
|
||||
|
||||
if [ -f /tmp/go.tar.gz ] ; then
|
||||
sudo rm -f /tmp/go.tar.gz
|
||||
fi
|
||||
|
||||
# retry downloading on spurious failure
|
||||
curl -sSL --fail -o /tmp/go.tar.gz \
|
||||
--retry 5 --retry-connrefused \
|
||||
"${download}"
|
||||
|
||||
tar -C /tmp -xf /tmp/go.tar.gz
|
||||
sudo mv /tmp/go /usr/local
|
||||
sudo chown -R root:root /usr/local/go
|
||||
}
|
||||
|
||||
install_go
|
||||
|
||||
# Ensure that the GOPATH tree is owned by the correct user.
|
||||
sudo mkdir -p /opt/gopath
|
||||
sudo chown -R $USER:$USER /opt/gopath
|
||||
|
||||
# Ensure Go is on PATH
|
||||
if [ ! -e /usr/bin/go ] ; then
|
||||
sudo ln -s /usr/local/go/bin/go /usr/bin/go
|
||||
fi
|
||||
if [ ! -e /usr/bin/gofmt ] ; then
|
||||
sudo ln -s /usr/local/go/bin/gofmt /usr/bin/gofmt
|
||||
fi
|
||||
|
||||
|
||||
# Ensure new sessions know about GOPATH
|
||||
if sudo test ! -f /etc/profile.d/gopath.sh ; then
|
||||
sudo bash -c 'cat <<EOT > /etc/profile.d/gopath.sh
|
||||
export GOPATH="/opt/gopath"
|
||||
export PATH="/opt/gopath/bin:\$PATH"
|
||||
EOT'
|
||||
sudo chmod 755 /etc/profile.d/gopath.sh
|
||||
fi
|
||||
@@ -21,8 +21,8 @@ RUN useradd --create-home vagrant \
|
||||
COPY ./scripts/linux-priv-config.sh /tmp/scripts/linux-priv-config.sh
|
||||
RUN /tmp/scripts/linux-priv-config.sh
|
||||
|
||||
COPY ./scripts/vagrant-linux-priv-go.sh /tmp/scripts/vagrant-linux-priv-go.sh
|
||||
RUN /tmp/scripts/vagrant-linux-priv-go.sh
|
||||
COPY ./scripts/linux-priv-go.sh /tmp/scripts/linux-priv-go.sh
|
||||
RUN /tmp/scripts/linux-priv-go.sh
|
||||
|
||||
COPY ./scripts/vagrant-linux-priv-buf.sh /tmp/scripts/vagrant-linux-priv-buf.sh
|
||||
RUN /tmp/scripts/vagrant-linux-priv-buf.sh
|
||||
|
||||
@@ -37,7 +37,7 @@ sed -i'' -e "s|\\(Install .Go\\) [.0-9]*|\\1 ${golang_version}|g" \
|
||||
contributing/README.md
|
||||
|
||||
sed -i'' -e "s|go_version=\"*[^\"]*\"*$|go_version=\"${golang_version}\"|g" \
|
||||
scripts/vagrant-linux-priv-go.sh scripts/release/mac-remote-build
|
||||
scripts/linux-priv-go.sh scripts/release/mac-remote-build
|
||||
|
||||
echo "--> Checking if there is any remaining references to old versions..."
|
||||
if git grep -I --fixed-strings "${current_version}" | grep -v -e CHANGELOG.md -e .changelog/ -e vendor/ -e website/ -e ui/ -e contributing/golang.md -e '.*.go:' -e go.sum -e go.mod -e LICENSE
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
|
||||
function install_go() {
|
||||
local go_version="1.20.2"
|
||||
local download="https://storage.googleapis.com/golang/go${go_version}.linux-amd64.tar.gz"
|
||||
|
||||
if go version 2>&1 | grep -q "${go_version}"; then
|
||||
return
|
||||
fi
|
||||
|
||||
# remove previous older version
|
||||
rm -rf /usr/local/go
|
||||
|
||||
# retry downloading on spurious failure
|
||||
curl -sSL --fail -o /tmp/go.tar.gz \
|
||||
--retry 5 --retry-connrefused \
|
||||
"${download}"
|
||||
|
||||
tar -C /tmp -xf /tmp/go.tar.gz
|
||||
sudo mv /tmp/go /usr/local
|
||||
sudo chown -R root:root /usr/local/go
|
||||
}
|
||||
|
||||
install_go
|
||||
|
||||
# Ensure that the GOPATH tree is owned by vagrant:vagrant
|
||||
mkdir -p /opt/gopath
|
||||
chown -R vagrant:vagrant /opt/gopath
|
||||
|
||||
# Ensure Go is on PATH
|
||||
if [ ! -e /usr/bin/go ] ; then
|
||||
ln -s /usr/local/go/bin/go /usr/bin/go
|
||||
fi
|
||||
if [ ! -e /usr/bin/gofmt ] ; then
|
||||
ln -s /usr/local/go/bin/gofmt /usr/bin/gofmt
|
||||
fi
|
||||
|
||||
|
||||
# Ensure new sessions know about GOPATH
|
||||
if [ ! -f /etc/profile.d/gopath.sh ] ; then
|
||||
cat <<EOT > /etc/profile.d/gopath.sh
|
||||
export GOPATH="/opt/gopath"
|
||||
export PATH="/opt/gopath/bin:\$PATH"
|
||||
EOT
|
||||
chmod 755 /etc/profile.d/gopath.sh
|
||||
fi
|
||||
Reference in New Issue
Block a user