-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
builder: vagrant: introduce Vagrantfile #237
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,70 @@ | ||
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/ubuntu2204" | ||
when "arm64" | ||
# unique 22.04 arm64 box available to date | ||
# sha256sum c209ab013280d3cd26a344def60b7b19fbb427de904ea285057d94ca6ac82dd5 | ||
# - http://old-releases.ubuntu.com/releases/jammy/SHA256SUMS | ||
# - http://old-releases.ubuntu.com/releases/jammy/ubuntu-22.04-live-server-arm64.iso | ||
# - https://gitlab.com/jnh3/m1-baseboxes/-/blob/main/ubuntu/ubuntu-22.04-arm64.pkr.hcl#L11-16 | ||
config.vm.box = "jharoian3/ubuntu-22.04-arm64" | ||
end | ||
|
||
config.vm.hostname = VM_NAME | ||
config.vm.synced_folder "./", "#{VM_SOURCE}" | ||
|
||
case HOSTOS | ||
when "Linux" | ||
config.vm.provider "virtualbox" do |vb| | ||
vb.name = VM_NAME | ||
vb.cpus = "4" | ||
vb.memory = "2048" | ||
end | ||
when "Darwin" | ||
config.vm.provider "parallels" do |prl| | ||
prl.name = VM_NAME | ||
end | ||
end | ||
|
||
setup_ssh(config) | ||
|
||
config.vm.provision :shell, inline: "echo INFO: Starting Provision" | ||
|
||
config.vm.provision :shell, inline: "ARCH=#{ARCH} #{VM_SOURCE}/builder/prepare-ubuntu.sh" | ||
|
||
config.vm.provision :shell, inline: "echo INFO: Provision finished, now connect via ssh" | ||
end | ||
|
||
def setup_ssh(config) | ||
config.ssh.extra_args = ["-t", "cd #{VM_SOURCE}; bash --login"] | ||
|
||
# workaround for ubuntu 22.04 disabled ssh-rsa support | ||
# - https://it-jog.com/khow/vag/vaguperror-ubuntu2204 | ||
if ARGV[0] == "up" then | ||
config.ssh.insert_key = false | ||
config.ssh.private_key_path = nil | ||
config.ssh.username = "vagrant" | ||
config.ssh.password = "vagrant" | ||
end | ||
config.vm.provision "shell", inline: <<-SHELL | ||
sudo echo PubkeyAcceptedAlgorithms +ssh-rsa >> /etc/ssh/sshd_config | ||
sudo sudo systemctl restart sshd | ||
SHELL | ||
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,90 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# This shell script is meant to prepare a building/exec environment for libbpfgo. | ||
# | ||
|
||
|
||
# variables | ||
|
||
[ -z "${GO_VERSION}" ] && GO_VERSION="1.17" | ||
[ -z "${CLANG_VERSION}" ] && CLANG_VERSION="12" | ||
[ -z "${ARCH}" ] && ARCH="amd64" | ||
|
||
|
||
# functions | ||
|
||
die() { | ||
echo "ERROR: ${*}" | ||
exit 1 | ||
} | ||
|
||
info() { | ||
echo "INFO: ${*}" | ||
} | ||
|
||
check_tooling() { | ||
local tools="sudo apt-get" | ||
for tool in ${tools} | ||
do | ||
command -v "${tool}" >/dev/null 2>&1 || die "missing required tool ${tool}" | ||
done | ||
} | ||
|
||
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 | ||
} | ||
|
||
setup_go() { | ||
info "Setting Go ${GO_VERSION} as default" | ||
|
||
local tools="go gofmt" | ||
for tool in ${tools} | ||
do | ||
sudo -E update-alternatives --install "/usr/bin/${tool}" "${tool}" "/usr/lib/go-${GO_VERSION}/bin/${tool}" 100 | ||
done | ||
|
||
info "Go ${GO_VERSION} set as default" | ||
} | ||
|
||
setup_clang() { | ||
info "Setting Clang ${CLANG_VERSION} as default" | ||
|
||
local tools="clang llc llvm-strip clang-format" | ||
for tool in ${tools} | ||
do | ||
sudo -E update-alternatives --install "/usr/bin/${tool}" "${tool}" "/usr/bin/${tool}-${CLANG_VERSION}" 100 | ||
done | ||
|
||
info "Clang ${CLANG_VERSION} set as default" | ||
} | ||
|
||
|
||
# startup | ||
|
||
info "Starting preparation" | ||
|
||
check_tooling | ||
|
||
install_pkgs \ | ||
coreutils bsdutils findutils \ | ||
build-essential pkgconf \ | ||
golang-"${GO_VERSION}"-go \ | ||
llvm-"${CLANG_VERSION}" clang-"${CLANG_VERSION}" clang-format-"${CLANG_VERSION}" \ | ||
linux-headers-generic \ | ||
linux-tools-generic linux-tools-"$(uname -r)" \ | ||
zlib1g-dev libelf-dev libbpf-dev | ||
|
||
setup_go | ||
setup_clang | ||
|
||
info "Preparation finished" |
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,45 @@ | ||
# Vagrantfile | ||
|
||
## Boxes | ||
|
||
Currently there are two boxes available in [Vagrantfile-ubuntu](./../builder/Vagrantfile-ubuntu): | ||
|
||
| Box | Providers | | ||
|----------------------------------------------------------------------------------------------|--------------------------| | ||
| [generic/ubuntu2204](https://app.vagrantup.com/generic/boxes/ubuntu2204) (amd64) | virtualbox, parallels | | ||
| [jharoian3/ubuntu-22.04-arm64](https://app.vagrantup.com/jharoian3/boxes/ubuntu-22.04-arm64) | parallels | | ||
|
||
It is recommended to use them through the respective [Makefile rules](../Readme.md#contributing) as they are or overriding the `ARCH` environment variable if your architecture and provider allow such virtualization. E.g.: `make vagrant-up ARCH=amd64`. | ||
|
||
## Requirements | ||
|
||
### Linux | ||
|
||
Install them as per your flavour. | ||
|
||
- Vagrant | ||
- VirtualBox | ||
|
||
### Darwin | ||
|
||
- Vagrant | ||
|
||
```shell | ||
brew install vagrant | ||
``` | ||
|
||
- Parallels | ||
|
||
```shell | ||
brew install --cask parallels | ||
vagrant plugin install vagrant-parallels | ||
``` | ||
|
||
## More information | ||
|
||
For further information check: | ||
|
||
- [Vagrant Documentation](https://www.vagrantup.com/docs) | ||
- [Vagrant Boxes](https://app.vagrantup.com/boxes/search) | ||
- [VirtualBox Documentation](https://www.virtualbox.org/wiki/Documentation) | ||
- [Parallels](https://www.parallels.com) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the
.
signify by convention?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for letting the reader know that's internal. But they are also not considered first targets: https://www.gnu.org/software/make/manual/make.html#How-Make-Works