diff --git a/Vagrantfile b/Vagrantfile index 57f8b57da2..41a8bb69a7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,6 +1,5 @@ OS = (ENV['OS'] || "alpine310") BOX_REPO = (ENV['BOX_REPO'] || "generic") -BOX = (ENV['BOX'] || "#{BOX_REPO}/#{OS}") HOME = File.dirname(__FILE__) PROJECT = File.basename(HOME) NUM_NODES = (ENV['NUM_NODES'] || 0).to_i @@ -16,7 +15,11 @@ MOUNT_TYPE = ENV['MOUNT_TYPE'] || "nfs" # %admin ALL = (root) NOPASSWD: /sbin/nfsd restart # --- May need to add terminal to System Preferences -> Security & Privacy -> Privacy -> Full Disk Access -def provision(vm) +def provision(vm, node_num) + node_os = (ENV["OS_#{node_num}"] || OS) + vm.box = (ENV["BOX_#{node_num}"] || ENV["BOX"] || "#{BOX_REPO}/#{node_os}") + vm.hostname = "#{PROJECT}-#{node_num}-#{node_os}" + vm.network "private_network", ip: "#{NETWORK_PREFIX}.#{100+node_num}" vm.provision "shell", path: VAGRANT_PROVISION, env: { 'HOME' => HOME, 'GOPATH' => ENV['GOPATH'], 'BOX' => vm.box } @@ -29,26 +32,17 @@ Vagrant.configure("2") do |config| v.memory = NODE_MEMORY v.customize ["modifyvm", :id, "--audio", "none"] end - - config.vm.box = BOX - config.vm.hostname = PROJECT - config.vm.synced_folder ".", HOME, type: MOUNT_TYPE - if Vagrant.has_plugin?("vagrant-timezone") config.timezone.value = :host end + config.vm.synced_folder ".", HOME, type: MOUNT_TYPE if NUM_NODES==0 - config.vm.network "private_network", ip: "#{NETWORK_PREFIX}.100" - provision(config.vm) + provision(config.vm, 0) else (1..NUM_NODES).each do |i| config.vm.define ".#{i}" do |node| - node_os = (ENV["OS_#{i}"] || OS) - node.vm.box = (ENV["BOX_#{i}"] || "#{BOX_REPO}/#{node_os}") - node.vm.network "private_network", ip: "#{NETWORK_PREFIX}.#{100+i}" - node.vm.hostname = "#{PROJECT}-#{i}" - provision(node.vm) + provision(node.vm, i) end end end diff --git a/scripts/provision/generic/alpine310/vagrant b/scripts/provision/generic/alpine310/vagrant index f06bddfb49..ecd6898989 100755 --- a/scripts/provision/generic/alpine310/vagrant +++ b/scripts/provision/generic/alpine310/vagrant @@ -2,8 +2,8 @@ set -ve apk add -q -f curl libc6-compat tzdata -echo "Installing go $goversion" -curl -sL https://storage.googleapis.com/golang/go${goversion}.linux-${ARCH}.tar.gz | tar -xzf - -C /usr/local +download_go +download_dqlite # --- cat </etc/profile.d/build.sh export SELINUX=true @@ -12,9 +12,6 @@ export STATIC_BUILD=true EOF . /etc/profile.d/build.sh # --- -echo "Downloading DQLITE from $DQLITE_URL" -curl -sfL $DQLITE_URL -o /usr/src/dqlite.tgz -# --- . /tmp/docker-run # --- go get -u github.com/go-delve/delve/cmd/dlv diff --git a/scripts/provision/generic/centos7/vagrant b/scripts/provision/generic/centos7/vagrant index e58ad8731f..448d59edd4 100755 --- a/scripts/provision/generic/centos7/vagrant +++ b/scripts/provision/generic/centos7/vagrant @@ -1,9 +1,7 @@ #!/bin/bash set -ve - -echo "Installing go $goversion" -curl -sL https://storage.googleapis.com/golang/go${goversion}.linux-${ARCH}.tar.gz | tar -xzf - -C /usr/local +download_go # --- cat </etc/profile.d/build.sh export SELINUX=true diff --git a/scripts/provision/generic/ubuntu1804/vagrant b/scripts/provision/generic/ubuntu1804/vagrant new file mode 100755 index 0000000000..4cb6b0c771 --- /dev/null +++ b/scripts/provision/generic/ubuntu1804/vagrant @@ -0,0 +1,26 @@ +#!/bin/bash +set -ve + +download_go +# --- +cat </etc/profile.d/build.sh +export SELINUX=true +# export DQLITE=true +# export STATIC_BUILD=true +EOF +. /etc/profile.d/build.sh +# --- +apt-get install -y \ + build-essential \ + pkg-config \ + libseccomp-dev \ + libsqlite3-dev \ + libselinux1-dev \ + zlib1g-dev \ + +# --- +sed -E 's|apk( -U)?( --no-cache)?( --repository [^ ]*)? add|apt-get install -y|g' -i /tmp/docker-run +. /tmp/docker-run +# --- +go get -u github.com/go-delve/delve/cmd/dlv +# --- diff --git a/scripts/provision/vagrant b/scripts/provision/vagrant index aae94d3653..631acf41bc 100755 --- a/scripts/provision/vagrant +++ b/scripts/provision/vagrant @@ -1,9 +1,7 @@ #!/bin/bash set -ve -ARCH=amd64 PROVISION="scripts/provision/$BOX/vagrant" -OS=$(basename $BOX) if [ ! -f /etc/vagrant_box_build_time ]; then echo "This script should only be called during vagrant provisioning" @@ -28,15 +26,10 @@ if [ -z "${GOPATH}" ]; then else echo "Using parent GOPATH=$GOPATH" fi -goversion=$(grep "^FROM " Dockerfile.dapper | sed -e 's/^FROM golang:\(.*\)-.*/\1/') - -if [ -z "$goversion" ]; then - echo "Cannot find version of go to fetch" - exit 1 -fi # --- Setup basic env cat </etc/profile.d/env.sh +export ARCH=amd64 export GO111MODULE=off export GOPATH="$GOPATH" export PATH=/usr/local/bin:$PATH:/usr/local/go/bin:$GOPATH/bin @@ -44,10 +37,6 @@ export HOME="$HOME" && cd EOF . /etc/profile.d/env.sh -# --- Setup for dqlite download -DQLITE_URL="https://github.com/$(grep dqlite-build Dockerfile.dapper | sed -e 's/^.*--from=\([^ ]*\).*$/\1/' -e 's|:|/releases/download/|')/dqlite-$ARCH.tgz" -mkdir -p /usr/src/ - # --- Clean go cache rm -rf .cache/go-build || true @@ -55,13 +44,13 @@ rm -rf .cache/go-build || true sed -i 's|:/bin/ash$|:/bin/bash|g' /etc/passwd cat </etc/profile.d/color.sh alias ls='ls --color=auto' -export PS1='\033[31m[ \033[90m\D{%F %T}\033[31m ] \033[35m{\033[90m$OS\033[35m}\n\[\033[36m\]\u\[\033[m\]🐮\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ ' +export PS1='\033[31m[ \033[90m\D{%F %T}\033[31m ]\n\[\033[36m\]\u\[\033[m\]🐮\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ ' EOF # --- Setup install script from docker run commands mkdir -p ${GOPATH}/bin mkdir -p /go -ln -s $GOPATH/bin /go/bin +ln -sf $GOPATH/bin /go/bin sed ':a;N;$!ba;s/\\\n/ /g' /tmp/docker-run export BINDIR=/go/bin export GOPATH=/go @@ -79,6 +68,30 @@ cat <<\EOF >/etc/motd EOF +# --- Utility function to download go +download_go() { + goversion=$(grep "^FROM " Dockerfile.dapper | sed -e 's/^FROM golang:\(.*\)-.*/\1/') + if [ -z "$goversion" ]; then + echo "Cannot find version of go to fetch" + return 1 + fi + echo "Installing go $goversion" + curl -sL https://storage.googleapis.com/golang/go${goversion}.linux-${ARCH}.tar.gz | tar -xzf - -C /usr/local +} + + +# --- Utility function to download dqlite +download_dqlite() { + dqliteURL="https://github.com/$(grep dqlite-build Dockerfile.dapper | sed -e 's/^.*--from=\([^ ]*\).*$/\1/' -e 's|:|/releases/download/|')/dqlite-$ARCH.tgz" + if [ -z "$dqliteURL" ]; then + echo "Cannot find dqlite URL to fetch" + return 1 + fi + mkdir -p /usr/src/ + echo "Downloading DQLITE from $dqliteURL" + curl -sfL $dqliteURL -o /usr/src/dqlite.tgz +} + # --- Run vagrant provision script if available if [ ! -f "${PROVISION}" ]; then echo 'WARNING: Unable to execute provision script "${PROVISION}"'