Ruby terminal commands and GitHub workflow

Setting up your development machine is a headache. Here’s a little bit of research.

Project Requirements

  1. Virtual Box
  2. Text Editor
  3. Vagrant

— — —

Location

cd ~/Desktop/vagrant

Download vagrant files

$ vagrant up

Notes: This command creates and configures guest machines according to your Vagrantfile.

This is the single most important command in Vagrant, since it is how any Vagrant machine is created. Anyone using Vagrant must use this command on a day-to-day basis.

Launch your Web Dev environment

$ vagrant ssh

Notes: This will SSH into a running Vagrant machine and give you access to a shell.

On a simple vagrant project, the instance created will be named default.

Vagrant will ssh into this instance without the instance name:

$ vagrant ssh
Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
$ logout
Connection to 127.0.0.1 closed.

Shutdown environment

$ vagrant halt

Notes: This command shuts down the running machine Vagrant is managing.

Vagrant will first attempt to gracefully shut down the machine by running the guest OS shutdown mechanism. If this fails, or if the --force flag is specified, Vagrant will effectively just shut off power to the machine.

Accounts — Generate SSH Key

eval `ssh-agent -s`
ssh-keygen -t rsa -C "Firehose Vagrant" -N '' -f ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa

Configure Heroku and add SSH

wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh 
heroku login
heroku keys:add

Notes: If you don’t already use SSH and if you want to use SSH Git transport on Heroku, you’ll need to create a public/private key pair to deploy code. This keypair is used for the strong cryptography and that uniquely identifies you as a developer when pushing code changes.

Configure GitHub with SSH key

curl https://gist.githubusercontent.com/kenmazaika/fa8ea7dfbae413638cfd111b974bc74a/raw/ecb5e91c044d92389d0cfd3c2229e57187384d6d/github_auth.rb  > ~/.firehose-github.rb && ruby ~/.firehose-github.rb
git config --global user.email "you@example.com" 
git config --global user.name "Your Name"

Notes: Global level configuration is user-specific, meaning it is applied to an operating system user. Global configuration values are stored in a file that is located in a user’s home directory. ~ /.gitconfig on unix systems and C:\Users\<username>\.gitconfig on windows

Test — Run rails server

cd /vagrant/src/firehose-test-app
$ rails server -b 0.0.0.0 -p 3000

Notes: 0.0.0.0 means that Rails is listening on all interfaces, not just the loopback interface.

— — —

Create an app that uses postgres

Location

$ cd /vagrant/src 

New app that uses postgres

$ rails new splurty --database=postgresql

Notes: Rails expects the name of the database user to match the name of the application, but you can easily change that if need be.

We will now configure which database Rails will talk to. This is done using the database.yml file, located at:

RAILS_ROOT/config/database.yml

Note: RAILS_ROOT is the Rails root directory. In the above example, it would be at /myapp (relative to your current location).

— — —

Database

Location

$ cd /vagrant/src/splurty

Create database

$ rake db:create 

Notes: When you create your Rails application for the first time, it will not have a database yet. In order for it to start, you will need to make sure the database is up and running.

Outputs

Created database 'splurty_development'
Created database 'splurty_test'

Access rails console to access database

$ rails console

Notes: The console command lets you interact with your Rails application from the command line.rails console uses IRB (Interactive Ruby).

Database command example

> Quote.create(saying: 'Live life to the fullest', author: 'none')

Exit rails console

exit

— — —

Github workflow

If first-time, initialize.

$ git init

1. Add all to staging area

$ git add --all

2. Commit files and add comment

$ git commit -am "initial commmit"

3. Push files to master

$ git push origin master

push web app to heroku

$ git push heroku master