From f13ad108a4bb216e207e8f8b5da5b7cabe0d7ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Thu, 19 Oct 2023 18:46:32 +0200 Subject: [PATCH 1/3] chore: use nix for installing tools in Vagrant --- .gitignore | 3 ++ Vagrantfile | 8 +---- vagrant/provision.sh | 79 ++++++++++++-------------------------------- 3 files changed, 26 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 1c83e47815..c9f78d66fd 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ tmp # Go workspace files go.work go.work.sum + +# Local values files +values.local.yaml \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile index f5bdb9ee08..e4e69b2c0d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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 diff --git a/vagrant/provision.sh b/vagrant/provision.sh index 294e339fa2..32978ed278 100644 --- a/vagrant/provision.sh +++ b/vagrant/provision.sh @@ -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 @@ -53,28 +47,33 @@ 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 @@ -82,42 +81,8 @@ while true; do 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: @@ -126,4 +91,4 @@ echo echo Dashboard token: /sumologic/vagrant/scripts/get-dashboard-token.sh -echo + From 6355e2b3065eb2341721699b52a3b49ed052776d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Fri, 20 Oct 2023 17:42:25 +0200 Subject: [PATCH 2/3] Add QEMU support for vagrant --- CONTRIBUTING.md | 8 ++++++++ Vagrantfile | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d1bb9bc798..00399b7bd9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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) diff --git a/Vagrantfile b/Vagrantfile index e4e69b2c0d..944850efc6 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -17,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" From c124efe92a1b8b494077a5043ab618876b49b37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Mon, 23 Oct 2023 14:12:24 +0200 Subject: [PATCH 3/3] Update .gitignore Co-authored-by: Dominik Rosiek <58699848+sumo-drosiek@users.noreply.github.com> --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c9f78d66fd..6daf8c0dc2 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,4 @@ go.work go.work.sum # Local values files -values.local.yaml \ No newline at end of file +values.local.yaml