Saturday, March 11, 2023

Vagrant as CI Server

 Use Vagrant to create a virtual machine and install the required packages to run the tests for sidekiq-throttled ruby gem.

Here's a high-level overview of the steps to create a virtual machine using Vagrant and install the required packages to run the tests for sidekiq-throttled ruby gem:

  1. Install VirtualBox: First, you'll need to install VirtualBox, which is the virtualization software that Vagrant uses to create and manage virtual machines. You can download it from the VirtualBox website.

  2. Install Vagrant: Next, you'll need to install Vagrant itself. You can download it from the Vagrant website.

  3. Create a Vagrantfile: In order to configure the virtual machine, you'll need to create a Vagrantfile. This file defines the configuration for the virtual machine, including the operating system, network settings, and any software to be installed. Here's an example Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/focal64"

  config.vm.network "forwarded_port", guest: 3000, host: 3000
  config.vm.network "forwarded_port", guest: 6379, host: 6379

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "2048"
    vb.cpus = "2"
  end

  config.vm.provision "shell", inline: <<-SHELL
    sudo apt-get update
    sudo apt-get install -y build-essential
    sudo apt-get install -y git
    sudo apt-get install -y redis-server
    curl -sSL https://get.rvm.io | bash -s stable
    source /home/vagrant/.rvm/scripts/rvm
    rvm install 3.0.4
    rvm use 3.0.4 --default
    gem install bundler
  SHELL
end

This Vagrantfile sets up an Ubuntu 20.04 virtual machine with 2GB of RAM and 2 CPUs, and installs the required packages to run the tests for sidekiq-throttled ruby gem: build-essential, git, redis-server, RVM, Ruby 3.0.4, and bundler. It also forwards ports 3000 and 6379 from the virtual machine to the host machine. Start the virtual machine: Once you've created the Vagrantfile, you can start the virtual machine by running the following command in the same directory as the Vagrantfile:

vagrant up

This will download the Ubuntu 20.04 base image, create a new virtual machine based on that image, and run the provisioning scripts defined in the Vagrantfile to install the required packages.

  1. Connect to the virtual machine: You can connect to the virtual machine by running the following command:

vagrant ssh

This will open a terminal window connected to the virtual machine.

  1. Clone the sidekiq-throttled gem: Once you're connected to the virtual machine, you can clone the sidekiq-throttled gem by running the following commands:
cd /vagrant
git clone https://github.com/sensortower/sidekiq-throttled.git
cd sidekiq-throttled

cd /vagrant git clone https://github.com/sensortower/sidekiq-throttled.git cd sidekiq-throttled

  1. Install dependencies and run the tests: Finally, you can install the gem dependencies and run the tests by running the following commands:
bundle install
bundle exec appraisal install
bundle exec appraisal update
bundle exec appraisal rspec
bundle exec rubocop

You now have a virtual machine running Ubuntu 20.04 with all the required packages to run the tests for sidekiq-throttled ruby gem.