Skip to content

Rails Setup

bri25yu edited this page Nov 29, 2022 · 1 revision

WIP.

For the most up-to-date instructions, see the hkn-rails README.

The Easy Way

Run in a Virtualbox VM, provisioned using Vagrant. All setup done for you during provisioning.

Dependencies

Install Git (or the Github client), VirtualBox and Vagrant.

Instructions

Clone the hkn-rails repository:

git clone https://github.com/compserv/hkn-rails

Then, with a terminal, cd into your newly cloned repository and run Vagrant:

cd hkn-rails
vagrant up

This will download the virtual machine, turn it on, then set it up. You will only need to wait for setup once; in the future, you may turn it on with vagrant up and it will already be setup.

Once the machine has booted, it will run in the background on your computer. To access the machine, you may ssh in, just as you might access the Berkeley lab machines:

vagrant ssh

To turn off the virtual machine, run

vagrant halt

which will attempt to safely shutdown the virtual machine, or kill it otherwise.

Developing

When you ssh into your machine, you may access the files with:

cd /vagrant

This folder in the virtual machine is synced with the copy on your computer: edits in one will be instantly transferred to the other. This means you can edit your computer's copy normally with Sublime Text (or some other editor / IDE), and run commands through your terminal's ssh.

Our current Vagrant boxes use the Debian Linux distribution, the same used on the OCF. Specifically, we use the debian/contrib-stretch64 VM box, which auto-syncs files in the VM /vagrant folder with your local hkn-rails/ folder.

Development

Our Ruby development works with bundler, which during VM setup (provisioning) should have installed all Ruby gem dependencies into a per-project environment. Running programs in this environment requires you prefix all commands with bundle exec.

To run the server in the Vagrant machine, run:

bundle exec rails server -b 0.0.0.0

Then the server will make the web site available through your web browser at localhost:3000, which is bound to the VM port 3000.

Why 0.0.0.0? If we make the server listen on localhost:3000 for requests, it will only listen for connections from the virtual machine (itself, localhost), but your browser (Firefox, Chrome, Safari, IE heaven forbid) is not running in your virtual machine, so it will not be allowed to connect.

The Hard Way

You know what you are doing. Alternatively, you are willing to spend some extra time to learn what's going on.

Dependencies

You will need the following system programs:

  • RVM
  • MySQL / MariaDB (production database)

As for how you install these system programs, this is up to you, but here are a few common OSs.

(NOTE: not guaranteed to work.)

Windows

Good luck. I'm serious, this is a pain, you're almost better off with the Vagrant (easy way). You'll need to install from the following websites:

Mac

I recommend [Homebrew][https://brew.sh/], a package manager for Mac OS. After installing it, run:

brew install mariadb mariadb-connector-c

Linux

You're on your own. You know what you're doing. I will make one exception for Ubuntu:

sudo apt install build-essential mariadb-client mariadb-server libmysqlclient-dev

Instructions

Setup RVM

Follow the rvm.io setup instructions. Probably something like

gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable

Then install the version of Ruby specified in the Gemfile:

rvm install 2.5.7

Bundler setup

Developing hkn-rails requires bundler, which will manage the Ruby gem environment. RVM will select the correct Ruby version.

bundle install

And setup the databases with

bundle exec rake db:setup

I don't trust you

Next steps

You're done! If everything works, you should be able to run

bundle exec rails server -b 0.0.0.0

Then the server will make the web site available through your web browser at localhost:3000.