Vagrantfile improvement (apt-get) (#8762)

* use privileged provisioner to simplify setup script

* fix 'not a tty' error when running privileged shell

* run apt-get non-interactively
do not install suggested/recommended packages
suppress verbose output on stdout

* beautifying shell code and output

* fixed exidently overwritten .bashrc
This commit is contained in:
Michael Göhler 2016-10-26 16:33:40 +02:00 committed by Paul Stack
parent fbcd1cff3f
commit 9c3c5c1e31
1 changed files with 24 additions and 17 deletions

41
Vagrantfile vendored
View File

@ -10,47 +10,54 @@ SRCROOT="/opt/go"
SRCPATH="/opt/gopath" SRCPATH="/opt/gopath"
# Get the ARCH # Get the ARCH
ARCH=`uname -m | sed 's|i686|386|' | sed 's|x86_64|amd64|'` ARCH="$(uname -m | sed 's|i686|386|' | sed 's|x86_64|amd64|')"
# Install Prereq Packages # Install Prereq Packages
sudo apt-get update export DEBIAN_PRIORITY=critical
sudo apt-get upgrade -y export DEBIAN_FRONTEND=noninteractive
sudo apt-get install -y build-essential curl git-core libpcre3-dev mercurial pkg-config zip export DEBCONF_NONINTERACTIVE_SEEN=true
APT_OPTS="--yes --force-yes --no-install-suggests --no-install-recommends"
echo "Upgrading packages ..."
apt-get update ${APT_OPTS} >/dev/null
apt-get upgrade ${APT_OPTS} >/dev/null
echo "Installing prerequisites ..."
apt-get install ${APT_OPTS} build-essential curl git-core libpcre3-dev mercurial pkg-config zip >/dev/null
# Install Go # Install Go
cd /tmp echo "Downloading go (${GOVERSION}) ..."
wget --quiet https://storage.googleapis.com/golang/go${GOVERSION}.linux-${ARCH}.tar.gz wget -P /tmp --quiet "https://storage.googleapis.com/golang/go${GOVERSION}.linux-${ARCH}.tar.gz"
tar -xvf go${GOVERSION}.linux-${ARCH}.tar.gz echo "Setting up go (${GOVERSION}) ..."
sudo mv go $SRCROOT tar -C /opt -xf "/tmp/go${GOVERSION}.linux-${ARCH}.tar.gz"
sudo chmod 775 $SRCROOT chmod 775 "$SRCROOT"
sudo chown vagrant:vagrant $SRCROOT chown vagrant:vagrant "$SRCROOT"
# Setup the GOPATH; even though the shared folder spec gives the working # Setup the GOPATH; even though the shared folder spec gives the working
# directory the right user/group, we need to set it properly on the # directory the right user/group, we need to set it properly on the
# parent path to allow subsequent "go get" commands to work. # parent path to allow subsequent "go get" commands to work.
sudo mkdir -p $SRCPATH mkdir -p "$SRCPATH"
sudo chown -R vagrant:vagrant $SRCPATH 2>/dev/null || true chown -R vagrant:vagrant "$SRCPATH" 2>/dev/null || true
# ^^ silencing errors here because we expect this to fail for the shared folder # ^^ silencing errors here because we expect this to fail for the shared folder
cat <<EOF >/tmp/gopath.sh install -m0755 /dev/stdin /etc/profile.d/gopath.sh <<EOF
export GOPATH="$SRCPATH" export GOPATH="$SRCPATH"
export GOROOT="$SRCROOT" export GOROOT="$SRCROOT"
export PATH="$SRCROOT/bin:$SRCPATH/bin:\$PATH" export PATH="$SRCROOT/bin:$SRCPATH/bin:\$PATH"
EOF EOF
cat <<EOF >>~/.bashrc
cat >>/home/vagrant/.bashrc <<EOF
## After login, change to terraform directory ## After login, change to terraform directory
cd /opt/gopath/src/github.com/hashicorp/terraform cd /opt/gopath/src/github.com/hashicorp/terraform
EOF EOF
sudo mv /tmp/gopath.sh /etc/profile.d/gopath.sh
sudo chmod 0755 /etc/profile.d/gopath.sh
SCRIPT SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-14.04" config.vm.box = "bento/ubuntu-14.04"
config.vm.hostname = "terraform" config.vm.hostname = "terraform"
config.vm.provision "shell", inline: $script, privileged: false config.vm.provision "prepare-shell", type: "shell", inline: "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile", privileged: false
config.vm.provision "initial-setup", type: "shell", inline: $script
config.vm.synced_folder '.', '/opt/gopath/src/github.com/hashicorp/terraform' config.vm.synced_folder '.', '/opt/gopath/src/github.com/hashicorp/terraform'
config.vm.provider "docker" do |v, override| config.vm.provider "docker" do |v, override|