Skip to content

Instantly share code, notes, and snippets.

@atombender
Last active January 2, 2016 20:49
Show Gist options
  • Save atombender/8359763 to your computer and use it in GitHub Desktop.
Save atombender/8359763 to your computer and use it in GitHub Desktop.
Development environment setup

Preliminaries

Install Ruby

Either using brew, or via rbenv.

To avoid issues with gem installation, configure gem with --no-ri. Here is a sample ~/.gemrc that has some sensible settings:

install: --no-rdoc --no-ri --env-shebang
update: --no-rdoc --no-ri --env-shebang
verbose: true
update_sources: true
sources: 
- http://rubygems.org/
backtrace: false
bulk_threshold: 1000
benchmark: false

Install RabbitMQ

brew install rabbitmq

Then read what it says about loading with launchctl, and do it.

Install Memcached

brew install memcached

Then read what it says about loading with launchctl, and do it.

Disable local web server

Don't have anything running on port 80, or 8080 and upwards.

Get Grove

Clone repo

git clone https://github.com/t11e/grove.git
git checkout -b consolidated_pull_requests origin/consolidated_pull_requests  # Need this branch at the moment
bundle install

Create database user

createuser -SdP grove
cp config/database-example.yml config/database.yml
# Now edit database.yml with the password you set with `createuser`

Create database, schema and test database

createdb -O grove grove_development
bundle exec rake db:migrate
bundle exec rake db:test:prepare

Try out the unit tests

rspec

Get Checkpoint

Clone repo

git clone https://github.com/bengler/checkpoint.git
bundle install

Create database user

createuser -SdP checkpoint
cp config/database-example.yml config/database.yml
# Now edit database.yml with the password you set with `createuser`

Create database, schema and test database

createdb -O checkpoint checkpoint_development
bundle exec rake db:migrate
bundle exec rake db:test:prepare

Try out the unit tests

rspec

Get Brow

Clone it

git clone https://github.com/atombender/brow.git
cd brow
git checkout -b localdev_hack origin/localdev_hack  # This is the most correct branch at the moment
bundle install

Install the gem

cd brow; rake install

Install Nginx

Nginx needs the gzip module, so edit /usr/local/Library/Formula/nginx.rb and find the args = [... line, and add:

"--with-http_stub_status_module"

at the bottom of the array. Then:

brew install --build-from-source nginx

Install HAProxy

brew install haproxy

Install lsof (maybe)

See if you have lsof installed (by running which lsof). If not, you will have to do:

brew install lsof

Add your apps

mkdir ~/.brow
cd ~/dev  # Or wherever you keep your stuff
ln -s $PWD/grove ~/.brow/
ln -s $PWD/checkpoint ~/.brow/

Make the Apple syslog daemon log stuff

echo "? [S Sender bengler] [<= Level debug] file /var/log/system.log" | sudo tee -a /etc/asl.conf
sudo pkill -f syslogd

Start your apps

Watch system.log for output from Unicorn and apps.

brow up

If you get a permission error about /etc/hosts, you will have to chmod a+w /etc/hosts. :-(

Creating an API key

To create a Checkpoint "session key", which acts like an API key in many places (including Grove), you need to cheat a little bit, because Checkpoint itself does not have an API to do it.

To do this, create a script create_session_key.rb in the root of the Checkpoint project:

require './config/environment'

realm_name = ARGV.shift
abort "Specify realm name" unless realm_name

realm = Realm.where(label: realm_name).first
realm ||= Realm.create!(label: realm_name)
realm.service_keys = {
  google_oauth2: {
    client_id: 'ADD KEY HERE',
    client_secret: 'ADD SECRET HERE'
  }
}
realm.save!

domain = Domain.where(name: 'homesdotcom.dev').first
domain ||= Domain.create!(name: 'homesdotcom.dev', realm: realm)

realm.primary_domain = domain
realm.save!

domain = Domain.where(name: 'development-homes.t11e.com').first
domain ||= Domain.create!(name: 'development-homes.t11e.com', realm: realm)

identity = Identity.where(realm_id: realm.id, god: true).first
identity ||= Identity.create!(god: true, realm: realm)

session = identity.sessions.first
session ||= Session.create!(identity: identity)

puts session.key

Run this with:

bundle exec ruby create_session_key.rb endeavor-homes

Now you have a special privileged ("god") identity and a session key for it.

To make testing simpler, add homesdotcom.dev to your /etc/hosts, pointing to 127.0.0.1.

Testing Grove

Try posting a document (replace the key with your key):

export KEY=<key>
curl -vs -XPOST -b "checkpoint.session=$KEY" \
  -H "Content-Type: application/json" \
  -d'{"post":{"title": "Hello world"}}' \
  "http://grove.dev/api/grove/v1/posts/post.ad:homesdotcom.ads"

It should output a document with a uid field. The uid field should be something like post.ad:homesdotcom.ads$1. Now you can retrieve it by the same UID:

curl -vs -b "checkpoint.session=$KEY" \
  "http://grove.dev/api/grove/v1/posts/post.ad:homesdotcom.ads$1"

Grove example

Remember to replace your key below. Put this in the Grove root to make it easier to run (needs the pebblebed gem).

require 'pp'
require 'pebblebed'

Pebblebed.config do
  host 'homesdotcom.dev'
  service :checkpoint
  service :grove
end

key = '<key>'

pebblebed = ::Pebblebed::Connector.new(key, {})

grove = pebblebed.grove

posts = grove.get('/posts/post.ad:homesdotcom.ads', limit: 100)['posts']
posts.each do |post|
  pp post.to_hash
end

grove.post('/posts/post.ad:homesdotcom.ads', {
  post: {
    document: {
      title: "This is a test. #{Time.now}"
    }
  }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment