From 9ec82bc5452e7f0020a8a228e3d8d175edb8f161 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Fri, 8 Sep 2017 18:59:03 -0500 Subject: [PATCH] build: Install Go in Vagrant from official release --- Vagrantfile | 4 +++ scripts/vagrant-linux-priv-config.sh | 27 ---------------- scripts/vagrant-linux-priv-go.sh | 46 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 27 deletions(-) create mode 100755 scripts/vagrant-linux-priv-go.sh diff --git a/Vagrantfile b/Vagrantfile index 5429b5e98..d402443a6 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -93,6 +93,10 @@ def configureLinuxProvisioners(vmCfg) privileged: true, inline: 'rm -f /home/vagrant/linux.iso' + vmCfg.vm.provision "shell", + privileged: true, + path: './scripts/vagrant-linux-priv-go.sh' + vmCfg.vm.provision "shell", privileged: true, path: './scripts/vagrant-linux-priv-config.sh' diff --git a/scripts/vagrant-linux-priv-config.sh b/scripts/vagrant-linux-priv-config.sh index 999981fb7..4c23f41b5 100755 --- a/scripts/vagrant-linux-priv-config.sh +++ b/scripts/vagrant-linux-priv-config.sh @@ -9,9 +9,6 @@ apt-get install -y software-properties-common # Add i386 architecture (for libraries) dpkg --add-architecture i386 -# Add a Golang PPA -sudo add-apt-repository ppa:gophers/archive - # Add the Docker repository apt-key adv \ --keyserver hkp://p80.pool.sks-keyservers.net:80 \ @@ -28,7 +25,6 @@ apt-get update apt-get install -y \ build-essential \ git \ - golang-1.9 \ libc6-dev-i386 \ liblxc1 \ libpcre3-dev \ @@ -67,29 +63,6 @@ apt-get install -y \ # Ensure everything is up to date apt-get upgrade -y -# Ensure Go is on PATH -if [ ! -e /usr/bin/go ] ; then - ln -s /usr/lib/go-1.9/bin/go /usr/bin/go -fi -if [ ! -e /usr/bin/gofmt ] ; then - ln -s /usr/lib/go-1.9/bin/gofmt /usr/bin/gofmt -fi - -# Ensure that the GOPATH tree is owned by vagrant:vagrant -mkdir -p /opt/gopath -chown vagrant:vagrant \ - /opt/gopath \ - /opt/gopath/src \ - /opt/gopath/src/github.com \ - /opt/gopath/src/github.com/hashicorp - -# Ensure new sessions know about GOPATH -cat < /etc/profile.d/gopath.sh -export GOPATH="/opt/gopath" -export PATH="/opt/gopath/bin:\$PATH" -EOF -chmod 755 /etc/profile.d/gopath.sh - # Restart Docker in case it got upgraded systemctl restart docker.service diff --git a/scripts/vagrant-linux-priv-go.sh b/scripts/vagrant-linux-priv-go.sh new file mode 100755 index 000000000..4a320b40b --- /dev/null +++ b/scripts/vagrant-linux-priv-go.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +function install_go() { + local go_version=1.9 + local download= + + download="https://storage.googleapis.com/golang/go${go_version}.linux-amd64.tar.gz" + + if [ -d /usr/local/go ] ; then + return + fi + + wget -q -O /tmp/go.tar.gz ${download} + + tar -C /tmp -xvf /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 vagrant:vagrant \ + /opt/gopath \ + /opt/gopath/src \ + /opt/gopath/src/github.com \ + /opt/gopath/src/github.com/hashicorp + +# 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 < /etc/profile.d/gopath.sh +export GOPATH="/opt/gopath" +export PATH="/opt/gopath/bin:\$PATH" +EOT + chmod 755 /etc/profile.d/gopath.sh +fi