Sunday, February 19, 2012

Installing Sproutcore (stable and dev) on Linux

This is just a note-to-self kind of post. Official instruction, available here, do not explain how to setup the development version (which currently is 1.7.1.beta).

This is the full list of command (ran and tested on Ubuntu Lucid Lynx 10.04), just need to type the occasional yes.

For those cases when bundle fails (happened to me) to create the bin directory with the beta version of sc-* tools just type the longer variant:

bundle exec sc-server

Saturday, February 11, 2012


I'm writing this post just to share an interesting conversation that popped up on #sproutcore this week. Sproutcore is a huge framework and there is no amount of documentation that will explain it all, that's why I suggest you hang out in IRC. Even if you don't have questions to ask you'll learn a lot from others'.

In this case the question was: how do I make my custom view update whenever one of the content object properties change?
The perfect case for this, I think, would be if we were writing a custom SC.ListItemView.

In my case, prior to discovering SC.ContentDisplay I used the following configuration in a custom ListItemView:

Maps.OpenLayersLayer = SC.View.extend({
content: null,
displayProperties: ["content", "content.order", "content.visible", "content.opacity", "content.cql_filter"],

While it works (it was, I quote, described as funny though) this is the recommended way to do it:

Maps.OpenLayersLayer = SC.View.extend(SC.ContentDisplay, {
content: null,
contentDisplayProperties: ["order", "visible", "opacity", "cql_filter"],

Thanks to jdooley who pointed to the solution.

Sunday, February 05, 2012

Testing provisioning scripts with throw-away VMs

Using expendable virtual machines for testing purposes is hardly a new concept.
Now pretty-please-with-sugar-on-top would be automating the whole create-provision-test-destroy cycle.

Enter Vagrant. Vagrant is a tool for building and distributing virtualized development environments. It allows automated creation, provisioning (with Puppet, Chef or shell scripts) and tear down.

Installing Vagrant on Ubuntu 10.04 LTS (which I'm still running) requires the following:

  1. a 4.1.x VirtualBox distribution (the 3.1 bundled with Ubuntu will not work)
  2. a recent version of ruby (you guessed it: the 1.8.x bundled with Ubuntu will not work)
To install VirtualBox add the following repo to /etc/apt/sources.list:

deb lucid contrib non-free
then issue the usual apt-get update and install with (remove stock packages first):
sudo apt-get update
sudo apt-get remove virtualbox-ose virtualbox-ose-dkms
sudo apt-get install virtualbox-4.1
Ruby is a more complicated and longer issue because, in case your system still ships with 1.8, it requires a full build of ruby 1.9. If you already have ruby 1.9 you can skip this section.
To install ruby 1.9 alongside any other existing ruby we'll use rvm. Rvm will install a separate version of ruby without replacing or breaking the one that came with our system. Unfortunately this requires a full build, so you might want to launch it before you go out (following instructions were taken from here):
curl -s -o rvm-installer
chmod +x rvm-installer
./rvm-installer --version latest
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session
rvm install ruby-1.9.2
rvm use 1.9.2
rvm --default use 1.9.2
gem install vagrant
Now we're ready to use Vagrant. First we need to download a virtual machine image that vagrant will use as a template to jumpstart our throw-away vms:
vagrant box add base
This will take some time depending on your connection speed. When it's done we need to tell vagrant to generate a template configuration file with the command:
vagrant init

The configuration file is called a Vagrantfile and it provides vagrant with all the information needed to assemble the vm. The parts of the Vagrantfile we'll want to change are:
  • networking: by bridging one vm interface to our LAN so that the VM can access resources beyond the localsystem. Set the network option as follows: :bridged
  • a shared (read-write) folder from the host for caching and file distribution: config.vm.share_folder "v-data", "/vagrant_data", "install-data"
  • a provisioning method between Chef, Puppet and shell
After that the vm can be created with:
vagrant up
The up command will also run the configured provisioning method after the vm has completely booted-up. In my case I chose to run just a shell script.
We can now login into the vm (as the vagrant user, use sudo to issue commands as root) to check if everything's allright:
vagrant ssh
To destroy the vm:
vagrant destroy
Now whenever we need/want to recreate the vm we just run vagrant up again and Vagrant will take care of booting the vm, setting up networking and then running the configured provision method. And it's quick too as on my laptop the whole process, including the complete run of the provision script takes roughly 2 mins.