-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
builder: vagrant: introduce Vagrantfile
The contributor can make use of a VM box (arm64/amd64) using the following Makefile rules: vagrant-up, vagrant-ssh, vagrant-halt and vagrant-destroy. One can override the ARCH env var: make vagrant-up ARCH=arm64 Whether the override will work depends on the availability of online boxes and compatibility of architecture and providers (vbox, parallels). Tested in Darwin (M1) and Linux (amd64).
- Loading branch information
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
ARCH = ENV["ARCH"] || "amd64" | ||
HOSTOS = ENV["HOSTOS"] || "undefined" | ||
|
||
if ! %w(amd64 arm64).include?(ARCH) then | ||
puts "ERROR: ARCH #{ARCH} not supported" | ||
abort | ||
end | ||
|
||
if ! %w(Linux Darwin).include?(HOSTOS) then | ||
puts "ERROR: HOSTOS #{HOSTOS} not supported" | ||
abort | ||
end | ||
|
||
VM_NAME = "libbpfgo_#{ARCH}_vm" | ||
VM_SOURCE = "/vagrant" | ||
|
||
Vagrant.configure("2") do |config| | ||
case ARCH | ||
when "amd64" | ||
config.vm.box = "generic/ubuntu2004" | ||
when "arm64" | ||
config.vm.box = "jeffnoxon/ubuntu-20.04-arm64" | ||
end | ||
|
||
config.vm.synced_folder "./", "#{VM_SOURCE}" | ||
config.ssh.extra_args = ["-t", "cd #{VM_SOURCE}; bash --login"] | ||
|
||
case HOSTOS | ||
when "Linux" | ||
config.vm.provider "virtualbox" do |vb| | ||
vb.name = VM_NAME | ||
end | ||
when "Darwin" | ||
config.vm.provider "parallels" do |prl| | ||
prl.name = VM_NAME | ||
end | ||
end | ||
|
||
config.vm.provision :shell, inline: "ARCH=#{ARCH} #{VM_SOURCE}/builder/prepare-ubuntu.sh vagrant" | ||
config.vm.provision :shell, inline: "echo FINISHED provision: now connect via ssh" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# This shell script is meant to prepare a building/exec environment for libbpfgo. | ||
# | ||
|
||
die() { | ||
echo "ERROR: ${*}" | ||
exit 1 | ||
} | ||
|
||
info() { | ||
echo "INFO: ${*}" | ||
} | ||
|
||
USER="${1}" | ||
[ -z "${USER}" ] && USER="root" | ||
USERHOME=$(eval echo ~"${USER}") | ||
[ -d "${USERHOME}" ] || die "directory ${USERHOME} doesn't exist" | ||
|
||
[ -z "${GOVERSION}" ] && GOVERSION="1.17.13" | ||
[ -z "${ARCH}" ] && ARCH="amd64" | ||
|
||
CMDS="wget rm tar chown apt-get" | ||
for cmd in ${CMDS}; do | ||
command -v "${cmd}" >/dev/null 2>&1 || die "missing required tool ${cmd}" | ||
done | ||
|
||
install_go() { | ||
info "Installing Go ${GOVERSION}" | ||
|
||
local file="go${GOVERSION}.linux-${ARCH}.tar.gz" | ||
local link="https://golang.org/dl/${file}" | ||
sudo wget --progress=bar:force "${link}" -P /tmp || die "could not download ${link}" | ||
|
||
local dest="/usr/local" | ||
sudo rm -rf "${dest}/go" | ||
sudo tar -C "${dest}" -xzf "/tmp/${file}" || die "could not untar ${file} in ${dest}" | ||
sudo chown -R root:root "${dest}/go" || die "could not chown" | ||
|
||
local home_profile="${USERHOME}/.profile" | ||
echo "export PATH=${PATH}:${dest}/go/bin" | sudo tee -a "${home_profile}" | ||
|
||
info "Go ${GOVERSION} installed" | ||
} | ||
|
||
install_pkgs() { | ||
# silence 'dpkg-preconfigure: unable to re-open stdin: No such file or directory' | ||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
sudo -E apt-get update || die "coud not update package list" | ||
for pkg in "${@}" | ||
do | ||
info "Installing ${pkg}" | ||
sudo -E apt-get install -y "${pkg}" || die "could not install ${pkg}" | ||
info "${pkg} installed" | ||
done | ||
} | ||
|
||
# startup | ||
|
||
info "Starting preparation" | ||
|
||
install_go | ||
|
||
install_pkgs \ | ||
coreutils bsdutils findutils \ | ||
build-essential pkgconf \ | ||
llvm-12 clang-12 \ | ||
clang-format-12 \ | ||
linux-headers-generic linux-tools-"$(uname -r)" \ | ||
zlib1g-dev libelf-dev libbpf-dev | ||
|
||
for tool in "clang" "llc" "llvm-strip" "clang-format" | ||
do | ||
sudo rm -f /usr/bin/${tool} | ||
sudo ln -s /usr/bin/${tool}-12 /usr/bin/${tool} | ||
done | ||
|
||
info "Preparation finished" |