Skip to content

Instantly share code, notes, and snippets.

@liaden
Created October 18, 2020 19:09
Show Gist options
  • Save liaden/637584441614bec1e9b0525fac87ab9c to your computer and use it in GitHub Desktop.
Save liaden/637584441614bec1e9b0525fac87ab9c to your computer and use it in GitHub Desktop.
bpf-vm
# frozen_string_literal: true
# rubocop:disable Style/GlobalVars
$CPU = 4
$chruby_version = '0.3.9'
$ruby_install_version = '0.7.0'
$default_ruby_version = '2.7.1'
$ruby_versions = %w[
2.7.1
2.6.6
]
BPF_BCC = <<~BASH
apt-get -qq update
apt-get -qq install linux-headers-$(uname -r) binutils-dev
apt-get -qq install bison cmake flex g++ git libelf-dev zlib1g-dev libfl-dev systemtap-sdt-dev
apt-get -qq install llvm-8-dev llvm-8-runtime libclang-8-dev clang-8
apt-get -qq install bpftrace
apt-get -qq install bpfcc-tools
BASH
DOCKER_INSTALL = <<~BASH
curl -fsSL https://get.docker.com -o get-docker.sh | sh -
BASH
CHRUBY = <<~BASH
cd /tmp
wget -O chruby.tar.gz https://github.com/postmodern/chruby/archive/v#{$chruby_version}.tar.gz
tar -xzvf chruby.tar.gz
cd chruby-#{$chruby_version}
sudo make install
echo 'source /usr/local/share/chruby/chruby.sh' >> /home/vagrant/.bashrc
echo 'source /usr/local/share/chruby/auto.sh' >> /home/vagrant/.bashrc
BASH
RUBY_INSTALL = <<~BASH
cd /tmp
wget -O ruby-install.tar.gz https://github.com/postmodern/ruby-install/archive/v#{$ruby_install_version}.tar.gz
tar -xzvf ruby-install.tar.gz
cd ruby-install-#{$ruby_install_version}
sudo make install
BASH
DOTFILES = <<~BASH
git clone --bare https://github.com/liaden/dotfiles /home/vagrant/.cfg
git --git-dir=/home/vagrant/.cfg/ --work-tree=/home/vagrant checkout
./setup.sh
BASH
def install_ruby(version)
"ruby-install ruby #{version} -j#{$CPU} -- --enable-dtrace"
end
DEFAULT_RUBY_VERSION = <<~BASH
echo 'chruby #{$default_ruby_version}' >> /home/vagrant/.bashrc
BASH
Vagrant.configure('2') do |config|
config.vm.define 'bpf-vm' do |box|
box.vm.box = 'ubuntu/eoan64'
box.vm.provider 'virtualbox' do |v|
v.memory = 4096
v.cpus = $CPU
v.customize ['modifyvm', :id, '--uart1', '0x3F8', '4']
v.customize ['modifyvm', :id, '--uartmode1', 'file', './bpf-vm_tty50.log']
end
box.vm.provision :shell, inline: DOTFILES, privileged: false
box.vm.provision :shell, inline: BPF_BCC
box.vm.provision :shell, inline: DOCKER_INSTALL
box.vm.provision :shell, inline: CHRUBY
box.vm.provision :shell, inline: RUBY_INSTALL
box.vm.provision :shell, inline: DEFAULT_RUBY_VERSION
$ruby_versions.each do |version|
box.vm.provision :shell, inline: install_ruby(version)
end
end
end
# rubocop:enable Style/GlobalVars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment