Skip to content
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

chore: use nix for installing tools in Vagrant #3343

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ tmp
# Go workspace files
go.work
go.work.sum

# Local values files
values.local.yaml
swiatekm marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
There is a prepared Vagrant environment with [microk8s](https://microk8s.io/) set up for collection tests, for details see
[here](vagrant/README.md).

#### ARM hosts (Apple M1, and so on)

You'll need to use QEMU instead of VirtualBox to use Vagrant on ARM. The following instructions will assume an M1 Mac as the host:

1. Install QEMU: `brew install qemu`
2. Install the QEMU vagrant provider: `vagrant plugin install vagrant-qemu`
3. Provision the VM with the provider: `vagrant up --provider=qemu`

### Using nix

1. [Install nix](https://nixos.org/download.html)
Expand Down
16 changes: 9 additions & 7 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

unless Vagrant.has_plugin?("vagrant-disksize")
puts "vagrant-disksize plugin unavailable\n" +
"please install it via 'vagrant plugin install vagrant-disksize'"
exit 1
end

Vagrant.configure('2') do |config|
config.vm.box = 'ubuntu/focal64'
config.disksize.size = '50GB'
config.vm.disk :disk, size: "50GB", primary: true
config.vm.box_check_update = false
config.vm.host_name = 'sumologic-kubernetes-collection'
# Vbox 6.1.28+ restricts host-only adapters to 192.168.56.0/21
Expand All @@ -23,6 +17,14 @@ Vagrant.configure('2') do |config|
vb.name = 'sumologic-kubernetes-collection'
end

config.vm.provider "qemu" do |qe, override|
override.vm.box = "perk/ubuntu-2204-arm64"
qe.gui = false
qe.smp = 8
qe.memory = 16384
qe.name = 'sumologic-kubernetes-collection'
end

config.vm.provision 'shell', path: 'vagrant/provision.sh'

config.vm.synced_folder ".", "/sumologic"
Expand Down
79 changes: 22 additions & 57 deletions vagrant/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

set -euo pipefail

YQ_VERSION=4.33.2
PRETTIER_VERSION=2.8.4
HELM_3_VERSION=v3.11.2
SHELLCHECK_VERSION=v0.9.0
K9S_VERSION=v0.24.15
GO_VERSION=1.20
KIND_VERSION=v0.17.0
LSB_RELEASE="$(lsb_release -cs)"
ARCH="$(dpkg --print-architecture)"

export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get --yes upgrade
apt-get --yes install apt-transport-https jq make npm yamllint
apt-get --yes install apt-transport-https make ca-certificates curl gnupg

echo "export EDITOR=vim" >> /home/vagrant/.bashrc

Expand Down Expand Up @@ -53,71 +47,42 @@ echo "sudo iptables -P FORWARD ACCEPT" >> /home/vagrant/.bashrc

echo "export KUBECONFIG=/var/snap/microk8s/current/credentials/kubelet.config" >> /home/vagrant/.bashrc

mkdir /opt/helm3
curl "https://get.helm.sh/helm-${HELM_3_VERSION}-linux-amd64.tar.gz" | tar -xz -C /opt/helm3

ln -s /opt/helm3/linux-amd64/helm /usr/bin/helm3
ln -s /usr/bin/helm3 /usr/bin/helm

usermod -a -G microk8s vagrant

# install yq with access to file structure
curl "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" -L -o /usr/local/bin/yq-"${YQ_VERSION}"
chmod +x /usr/local/bin/yq-"${YQ_VERSION}"
ln -s /usr/local/bin/yq-"${YQ_VERSION}" /usr/local/bin/yq

# Install docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
"deb [arch=${ARCH}] https://download.docker.com/linux/ubuntu \
${LSB_RELEASE} \
stable"
apt-get install -y docker-ce docker-ce-cli containerd.io
usermod -aG docker vagrant

# Install nix
curl -L https://nixos.org/nix/install -o /tmp/install-nix.sh
command -v nix-shell || sh /tmp/install-nix.sh --daemon --yes
# shellcheck source=/dev/null
source "/etc/bashrc"

# install k9s and direnv
nix-env -i k9s direnv

# set up direnv and the nix shell environment
echo "eval \"\$(direnv hook bash)\"" >> /home/vagrant/.bashrc
echo "use nix /sumologic/shell.nix" > /home/vagrant/.envrc

echo "Building Nix shell environment"
sudo -u vagrant bash -c "source /etc/bashrc; direnv allow /home/vagrant; cd /home/vagrant; nix-shell /sumologic/shell.nix"

# K8s needs some time to bootstrap
while true; do
kubectl -n kube-system get services 1>/dev/null 2>&1 && break
echo 'Waiting for k8s server'
sleep 1
done

# install requirements for ci/build.sh
snap install ruby --channel=2.6/stable --classic
gem install bundler
apt install -y gcc g++ libsnappy-dev libicu-dev zlib1g-dev cmake pkg-config libssl-dev

curl -Lo- "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar -xJf -
sudo cp "shellcheck-${SHELLCHECK_VERSION}/shellcheck" /usr/local/bin
rm -rf "shellcheck-${SHELLCHECK_VERSION}/"

npm install -g markdownlint-cli
npm install -g "prettier@${PRETTIER_VERSION}"
# shellcheck disable=SC2016
echo 'export PATH="$PATH:$HOME/.gem/bin"' >> /home/vagrant/.bashrc

mkdir /opt/k9s
curl -Lo- "https://github.com/derailed/k9s/releases/download/${K9S_VERSION}/k9s_Linux_x86_64.tar.gz" | tar -C /opt/k9s -xzf -
ln -s /opt/k9s/k9s /usr/bin/k9s

ln -s /sumologic/vagrant/scripts/sumo-make.sh /usr/local/bin/sumo-make
ln -s /sumologic/vagrant/scripts/sumo-make-completion.sh /etc/bash_completion.d/sumo-make

# Install Go
curl -LJ "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" -o go.linux-amd64.tar.gz \
&& rm -rf /usr/local/go \
&& tar -C /usr/local -xzf go.linux-amd64.tar.gz \
&& rm go.linux-amd64.tar.gz \
&& ln -s /usr/local/go/bin/go /usr/local/bin

# Install Kind
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-amd64"
chmod +x ./kind
mv ./kind /usr/local/bin/kind

# install python with dependencies
apt install -y python3 python3-pip
pip install pyyaml
ln -sf /sumologic/vagrant/scripts/sumo-make.sh /usr/local/bin/sumo-make
ln -sf /sumologic/vagrant/scripts/sumo-make-completion.sh /etc/bash_completion.d/sumo-make

# print out summary
echo Dashboard local in-vagrant IP:
Expand All @@ -126,4 +91,4 @@ echo

echo Dashboard token:
/sumologic/vagrant/scripts/get-dashboard-token.sh
echo