mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
build: Rework Vagrant to support multiple OS boxes
This commit reworks the Vagrantfile for Nomad in order to support straightforward testing on more than one operating system, whilst retaining the ability to stand up a test cluster running Ubuntu. The following changes are made: - Scripts have been extracted from the Vagrantfile into their own shell script files, in order that editors lint them. - All scripts have been edited to lint with no warnings or errors for their respective shells. - Scripts are named according to the operating system and privilege level which they run. We prefer to run a whole shell script as root versus prefixing (essentially) every command with `sudo` or an equivalent. - The Linux development box has been separated from the test cluster, removing some of the more gnarly (and less portable) logic. The Linux development box is still primary and autostarts. - A FreeBSD target has been added. The base box works for both Virtualbox and VMWare Fusion. - A target is added to the GNUmakefile to stand up a test cluster, using the default provider, or overriding the provider by setting the PROVIDER variable in make: - `make testcluster` - `make testcluster PROVIDER=vmware_fusion` - Machines in the test cluster have Avahi configured for zeroconf discovery. Each machine can ping each other machine at `hostname.local` - for example `nomad-server02.local`, `nomad-client03.local`.
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
CONSUL_VERSION="0.9.2"
|
||||
CURDIR=`pwd`
|
||||
|
||||
if [[ $(which consul >/dev/null && consul version | head -n 1 | cut -d ' ' -f 2) == "v$CONSUL_VERSION" ]]; then
|
||||
echo "Consul v$CONSUL_VERSION already installed; Skipping"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo Fetching Consul...
|
||||
cd /tmp/
|
||||
wget -q https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip -O consul.zip
|
||||
echo Installing Consul...
|
||||
unzip consul.zip
|
||||
sudo chmod +x consul
|
||||
sudo mv consul /usr/bin/consul
|
||||
cd ${CURDIR}
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
RKT_VERSION="v1.18.0"
|
||||
CMD="cp"
|
||||
|
||||
if [ ! -v DEST_DIR ]; then
|
||||
DEST_DIR="/usr/local/bin"
|
||||
CMD="sudo cp"
|
||||
fi
|
||||
|
||||
if [[ $(which rkt >/dev/null && rkt version | head -n 1) == "rkt Version: 1.18.0" ]]; then
|
||||
echo "rkt installed; Skipping"
|
||||
else
|
||||
printf "Fetching rkt-%s.tar.gz\n" "${RKT_VERSION}"
|
||||
cd /tmp
|
||||
wget -q https://github.com/coreos/rkt/releases/download/$RKT_VERSION/rkt-$RKT_VERSION.tar.gz -O rkt.tar.gz
|
||||
tar xzf rkt.tar.gz
|
||||
|
||||
$CMD rkt-$RKT_VERSION/rkt $DEST_DIR
|
||||
$CMD rkt-$RKT_VERSION/*.aci $DEST_DIR
|
||||
fi
|
||||
|
||||
rkt version
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Configure rkt networking
|
||||
sudo mkdir -p /etc/rkt/net.d
|
||||
if [[ -f /etc/rkt/net.d/99-network.conf ]]; then
|
||||
echo "rkt network already configured; Skipping"
|
||||
exit
|
||||
fi
|
||||
echo '{"name": "default", "type": "ptp", "ipMasq": false, "ipam": { "type": "host-local", "subnet": "172.16.28.0/24", "routes": [ { "dst": "0.0.0.0/0" } ] } }' | jq . | sudo tee -a /etc/rkt/net.d/99-network.conf
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
VAULT_VERSION="0.7.0"
|
||||
CURDIR=`pwd`
|
||||
|
||||
if [[ $(which vault >/dev/null && vault version | cut -d ' ' -f 2) == "v$VAULT_VERSION" ]]; then
|
||||
echo "Vault v$VAULT_VERSION already installed; Skipping"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo Fetching Vault ${VAULT_VERSION}...
|
||||
cd /tmp/
|
||||
wget -q https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip -O vault.zip
|
||||
echo Installing Vault...
|
||||
unzip vault.zip
|
||||
sudo chmod +x vault
|
||||
sudo mv vault /usr/bin/vault
|
||||
cd ${CURDIR}
|
||||
35
scripts/vagrant-freebsd-priv-config.sh
Executable file
35
scripts/vagrant-freebsd-priv-config.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
|
||||
chown vagrant:wheel \
|
||||
/opt/gopath \
|
||||
/opt/gopath/src \
|
||||
/opt/gopath/src/github.com \
|
||||
/opt/gopath/src/github.com/hashicorp
|
||||
|
||||
mkdir -p /usr/local/etc/pkg/repos
|
||||
|
||||
cat <<EOT > /usr/local/etc/pkg/repos/FreeBSD.conf
|
||||
FreeBSD: {
|
||||
url: "pkg+http://pkg.FreeBSD.org/\${ABI}/latest"
|
||||
}
|
||||
EOT
|
||||
|
||||
pkg update
|
||||
|
||||
pkg install -y \
|
||||
editors/vim-lite \
|
||||
devel/git \
|
||||
devel/gmake \
|
||||
lang/go \
|
||||
security/ca_root_nss \
|
||||
shells/bash
|
||||
|
||||
chsh -s /usr/local/bin/bash vagrant
|
||||
chsh -s /usr/local/bin/bash root
|
||||
|
||||
cat <<EOT >> /home/vagrant/.profile
|
||||
export GOPATH=/opt/gopath
|
||||
export PATH=\$GOPATH/bin:\$PATH
|
||||
|
||||
cd /opt/gopath/src/github.com/hashicorp/nomad
|
||||
EOT
|
||||
8
scripts/vagrant-freebsd-unpriv-bootstrap.sh
Executable file
8
scripts/vagrant-freebsd-unpriv-bootstrap.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
export GOPATH=/opt/gopath
|
||||
|
||||
PATH=$GOPATH/bin:$PATH
|
||||
export PATH
|
||||
|
||||
cd /opt/gopath/src/github.com/hashicorp/nomad && gmake bootstrap
|
||||
107
scripts/vagrant-linux-priv-config.sh
Executable file
107
scripts/vagrant-linux-priv-config.sh
Executable file
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Update and ensure we have apt-add-repository
|
||||
apt-get update
|
||||
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 \
|
||||
--recv-keys 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
|
||||
add-apt-repository \
|
||||
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
|
||||
$(lsb_release -cs) \
|
||||
stable"
|
||||
|
||||
# Update with i386, Go and Docker
|
||||
apt-get update
|
||||
|
||||
# Install Core build utilities for Linux
|
||||
apt-get install -y \
|
||||
build-essential \
|
||||
git \
|
||||
golang-1.9 \
|
||||
libc6-dev-i386 \
|
||||
liblxc1 \
|
||||
libpcre3-dev \
|
||||
linux-libc-dev:i386 \
|
||||
lxc-dev \
|
||||
lxc-templates \
|
||||
pkg-config \
|
||||
zip
|
||||
|
||||
# Install Development utilities
|
||||
apt-get install -y \
|
||||
curl \
|
||||
default-jre \
|
||||
docker-ce \
|
||||
htop \
|
||||
jq \
|
||||
qemu \
|
||||
silversearcher-ag \
|
||||
tree \
|
||||
unzip \
|
||||
vim
|
||||
|
||||
# Install ARM build utilities
|
||||
apt-get install -y \
|
||||
binutils-aarch64-linux-gnu \
|
||||
binutils-arm-linux-gnueabihf \
|
||||
gcc-5-aarch64-linux-gnu \
|
||||
gcc-5-arm-linux-gnueabihf \
|
||||
gcc-5-multilib-arm-linux-gnueabihf
|
||||
|
||||
# Install Windows build utilities
|
||||
apt-get install -y \
|
||||
binutils-mingw-w64 \
|
||||
gcc-mingw-w64
|
||||
|
||||
# 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 <<EOF > /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
|
||||
|
||||
# Ensure Docker can be used by vagrant user
|
||||
usermod -aG docker vagrant
|
||||
|
||||
# Set hostname -> IP to make advertisement work as expected
|
||||
ip=$(ip route get 1 | awk '{print $NF; exit}')
|
||||
hostname=$(hostname)
|
||||
sed -i -e "s/.*nomad.*/${ip} ${hostname}/" /etc/hosts
|
||||
|
||||
# Ensure we cd into the working directory on login
|
||||
if ! grep "cd /opt/gopath/src/github.com/hashicorp/nomad" /home/vagrant/.profile ; then
|
||||
echo 'cd /opt/gopath/src/github.com/hashicorp/nomad' >> /home/vagrant/.profile
|
||||
fi
|
||||
22
scripts/vagrant-linux-priv-consul.sh
Executable file
22
scripts/vagrant-linux-priv-consul.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
|
||||
VERSION=0.9.2
|
||||
DOWNLOAD=https://releases.hashicorp.com/consul/${VERSION}/consul_${VERSION}_linux_amd64.zip
|
||||
|
||||
function install_consul() {
|
||||
if [[ -e /usr/bin/consul ]] ; then
|
||||
if [ "v${VERSION}" == "$(consul version | head -n1 | awk '{print $2}')" ] ; then
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
wget -q -O /tmp/consul.zip ${DOWNLOAD}
|
||||
|
||||
unzip -d /tmp /tmp/consul.zip
|
||||
mv /tmp/consul /usr/bin/consul
|
||||
chmod +x /usr/bin/consul
|
||||
}
|
||||
|
||||
install_consul
|
||||
47
scripts/vagrant-linux-priv-rkt.sh
Executable file
47
scripts/vagrant-linux-priv-rkt.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
|
||||
VERSION=1.18.0
|
||||
DOWNLOAD=https://github.com/coreos/rkt/releases/download/v${VERSION}/rkt-v${VERSION}.tar.gz
|
||||
|
||||
function install_rkt() {
|
||||
if [[ -e /usr/local/bin/rkt ]] ; then
|
||||
if [ "rkt Version: ${VERSION}" == "$(rkt version | head -n1)" ] ; then
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
wget -q -O /tmp/rkt.tar.gz "${DOWNLOAD}"
|
||||
|
||||
tar -C /tmp -xvf /tmp/rkt.tar.gz
|
||||
mv /tmp/rkt-v${VERSION}/rkt /usr/local/bin
|
||||
mv /tmp/rkt-v${VERSION}/*.aci /usr/local/bin
|
||||
}
|
||||
|
||||
function configure_rkt_networking() {
|
||||
if [[ -e /etc/rkt/net.d/99-network.conf ]] ; then
|
||||
return
|
||||
fi
|
||||
|
||||
mkdir -p /etc/rkt/net.d
|
||||
cat <<EOT > /etc/rkt/net.d/99-network.conf
|
||||
{
|
||||
"name": "default",
|
||||
"type": "ptp",
|
||||
"ipMasq": false,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"subnet": "172.16.28.0/24",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
EOT
|
||||
}
|
||||
|
||||
install_rkt
|
||||
configure_rkt_networking
|
||||
22
scripts/vagrant-linux-priv-vault.sh
Executable file
22
scripts/vagrant-linux-priv-vault.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
|
||||
VERSION=0.7.0
|
||||
DOWNLOAD=https://releases.hashicorp.com/vault/${VERSION}/vault_${VERSION}_linux_amd64.zip
|
||||
|
||||
function install_vault() {
|
||||
if [[ -e /usr/bin/vault ]] ; then
|
||||
if [ "v${VERSION}" = "$(vault version | head -n1 | awk '{print $2}')" ] ; then
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
wget -q -O /tmp/vault.zip ${DOWNLOAD}
|
||||
|
||||
unzip -d /tmp /tmp/vault.zip
|
||||
mv /tmp/vault /usr/bin/vault
|
||||
chmod +x /usr/bin/vault
|
||||
}
|
||||
|
||||
install_vault
|
||||
10
scripts/vagrant-linux-priv-zeroconf.sh
Normal file
10
scripts/vagrant-linux-priv-zeroconf.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
|
||||
apt-get install -y \
|
||||
avahi-daemon \
|
||||
avahi-discover \
|
||||
avahi-utils \
|
||||
libnss-mdns \
|
||||
mdns-scan
|
||||
3
scripts/vagrant-linux-unpriv-bootstrap.sh
Executable file
3
scripts/vagrant-linux-unpriv-bootstrap.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd /opt/gopath/src/github.com/hashicorp/nomad && make bootstrap
|
||||
Reference in New Issue
Block a user