Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
62 changes: 37 additions & 25 deletions VAGRANT_UPGRADES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ system, the version Ruby or various other core components of the VM.
1) Update VirtualBox and Vagrant

It's recommended that you always update to the latest version of
VirtualBox and Vagrant at the start of this process.
[VirtualBox](https://www.virtualbox.org/wiki/Downloads) and [Vagrant](https://developer.hashicorp.com/vagrant/downloads) at the start of this process.

2) Destroy or set aside any old boxes.

Expand All @@ -27,13 +27,13 @@ and could cause issues with:

4) Update the Vagrantfile

For operating system upgrades, I generally go to the Vagrant Boxes
For operating system upgrades, I generally go to the [Vagrant Boxes](https://app.vagrantup.com/boxes/search)
search page on the HashiCorp website and search for the OS I'm looking
for.

When doing an OS upgrade I look first for a Hashicorp box and if I there
isn't one, then I'll look for an Ubuntu one. In the current
Vagrantfile we're using "ubuntu/focal64".
Vagrantfile we're using `ubuntu/focal64`.

For Ruby upgrades you will change the list that looks like:

Expand All @@ -42,60 +42,72 @@ For Ruby upgrades you will change the list that looks like:
IMPORTANT: You must either change the box names in the Vagrant file or
destroy any relevant boxes. Vagrant gets a lot of efficiency by
relying on cached copies of things, so make sure you clean out anything
you can. You can change "version_date" as a simple way to change the
you can. You can change `version_date` as a simple way to change the
name of the default box.

5) Build the "clean" box
5) Build the "clean" box.

In the current case I ran: "vagrant up clean-focal". You can find the current
names by looking in the Vagrantfile and searching for "config.vm.define".
In the current case I ran:

vagrant up clean-focal

You can find the current names by looking in the Vagrantfile and searching
for `config.vm.define`.

Currently builds generate a few red warnings/errors related signatures and
checksums, but everything seems to be working correctly.

6) Create "clean" package
6) Create "clean" package.

In the current case I ran:

In the current case I ran: "vagrant package clean-focal".
vagrant package clean-focal

This results in a file called package.box.
This results in a file called `package.box`.

Ultimately This should be uploaded to images.mushroomobserver.org and
moved to the directory /images/mo with the right ownership (mo:mo) and
permissions (644).
Ultimately this should be uploaded to `images.mushroomobserver.org` and
moved to the directory `/images/mo` with the right ownership (`mo:mo`) and
permissions (`644`).

Before doing this you may want to test it locally by changing the
mo.vm.box_url to refer to the local file. Just remember to
switch it back to the real URL after you have things working.

In the current case I moved package.box to mo-focal-2022-06-04.box and updated
In the current case I renamed `package.box` to `mo-focal-2022-06-04.box` and updated
the variable to point to:

file:///home/nathan/src/developer-startup/mo-focal-2022-06-04.box
file:///home/nathan/src/developer-startup/mo-focal-2022-06-04.box

7) Bring up the vagrant box
7) Bring up the vagrant box.

Run: vagrant up
Run:

This should bring up a version of the box with the new configuration.
vagrant up

Now run: vagrant ssh
This should bring up a version of the box with the new configuration. Now run:

vagrant ssh

This should connect you to the new box.

8) Setup the local build environment
8) Setup the local build environment.

Run:

Run: mo-dev /vagrant
mo-dev /vagrant

This will run bundler and the other bits needed to get the new box
setup to actually run MO.

9) Run the tests
9) Run the tests.

Run:

Run: cd /vagrant/mushroom-observer; rails test
cd /vagrant/mushroom-observer; rails test

If everything is green you great!

If stuff fails now you have to figure out how to fix it.

10) Don't forget to upload the new box to images.mushroomobserver.org
and update box_url in the Vagrantfile.
10) Don't forget to upload the new box to `images.mushroomobserver.org`
and update `box_url` in the Vagrantfile.
75 changes: 59 additions & 16 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,45 @@
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
#
# Use `apt-get`, not `apt`, in these commands to avoid warnings.
#
Vagrant.configure("2") do |config|
if ARGV[1] == "clean-focal"
config.vm.define "clean-focal" do |clean|
if ARGV[1] == "clean-jammy"
config.vm.define "clean-jammy" do |clean|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "ubuntu/focal64"
config.vm.box = "ubuntu/jammy64"

clean.vm.provider "virtualbox" do |vb|
# Use VBoxManage to customize the VM. For example to change memory:
vb.customize ["modifyvm", :id, "--memory", "2048"]
# Open the gui for debugging, while updating this Vagrantfile
# vb.gui="true"
end

clean.vm.network "forwarded_port", guest: 3000, host: 3000

clean.vm.provision :shell, inline: <<-SHELL
# Silence dpkg warnings "dpkg-preconfigure: unable to re-open stdin"
# Must come before any `apt-get` Also: Doesn't work!
config.vm.provision :shell, inline: <<-SHELL
update-locale LANG=en_US.UTF-8
apt-get -y update
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
export DEBIAN_FRONTEND=noninteractive
SHELL

# Update repositories
config.vm.provision :shell, inline: "apt-get -y update"

# Upgrade installed packages?
# config.vm.provision :shell, inline: "apt-get upgrade -y"

# Add Debian and MySQL server
clean.vm.provision :shell, inline: <<-SHELL
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
apt-get -y install mysql-server
Expand All @@ -35,28 +52,54 @@ Vagrant.configure("2") do |config|
ln -fs /vagrant/mo-dev /usr/local/bin/mo-dev
apt-get -y install git build-essential wget curl vim ruby \
imagemagick libmagickcore-dev libmagickwand-dev libjpeg-dev \
libgmp3-dev gnupg2
libgmp3-dev
SHELL

# Add public key for rvm and install rvm for multi-user
clean.vm.provision :shell, privileged: false, inline: <<-SHELL
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.7.6
rvm install 3.0.4
# Note: rvm's listed keyservers (incl. MIT.edu) are extremely
# unreliable. Hours of inexplicable failure to find the public keys.
# Some say use the ipv4 subdomain! Nope, doesn't work. Grr - AN 11/2022
# sudo gpg --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

# These may be less secure than keyservers, but at least they load.
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -
# Trust them keys
echo 409B6B1796C275462A1703113804BB82D39DC0E3:6: | gpg --import-ownertrust # mpapis@gmail.com
echo 7D2BAF1CF37B13E2069D6956105BD0E739499BDB:6: | gpg --import-ownertrust # piotr.kuczynski@gmail.com

curl -sSL https://get.rvm.io | bash -s stable
source $HOME/.rvm/scripts/rvm
rvm install 3.1.2
shift
rvm cleanup all
SHELL

# Uncomment these to add Google Chrome's repository & chrome itself
# config.vm.provision :shell, inline: "wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub|sudo apt-key add -"
# config.vm.provision :shell, inline: "sudo sh -c 'echo \"deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'"
# # Add Google Chrome for selenium tests
# config.vm.provision :shell, inline: "sudo apt install -y google-chrome-stable"

# NOTE: This simpler way to add Google Chrome didn't work:
# config.vm.provision :shell, inline: "wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -P ~/"
# config.vm.provision :shell, inline: "dpkg -i ~/google-chrome*.deb"
# config.vm.provision :shell, inline: "apt-get install -f -y"

# Add Firefox for selenium. Slow: Do this last in case troubleshooting.
config.vm.provision :shell, inline: "apt-get install -y firefox"

clean.trigger.after [:provision] do |t|
t.name = "Reboot after provisioning"
t.run = { :inline => "vagrant reload clean" }
end
end
else
version_date = "2022-06-04"
config.vm.define "mo-focal-#{version_date}", primary: true do |mo|
mo.vm.box = "mo-focal-#{version_date}"
mo.vm.box_url = "https://images.mushroomobserver.org/mo-focal-#{version_date}.box"
version_date = "2022-11-30"
config.vm.define "mo-jammy-#{version_date}", primary: true do |mo|
mo.vm.box = "mo-jammy-#{version_date}"
mo.vm.box_url = "https://images.mushroomobserver.org/mo-jammy-#{version_date}.box"
mo.vm.network "forwarded_port", guest: 3000, host: 3000
mo.vm.provider "virtualbox" do |vb|
# Use VBoxManage to customize the VM. For example to change memory:
Expand Down