Blue highlight courtesy of Autotrace

Bindle 2 is fresh out of the oven; one of the main areas of focus was making Bindles more intuitive to create & navigate—to that end we’re making use of a binary called Autotrace which helps us calculate the boundaries of items [1].  Unfortunately there is no ruby interface for this library in rails just yet, so we needed to get a binary running on our Heroku Cedar instance. Luckily it was pretty easy to do.

Here’s how to use binaries with Rails on Heroku:

Running binaries on heroku is possible if they are in the bin/ directory of your app. This is not officially supported, so use at your own risk. Heroku runs on Ubuntu 10.04 LTS 64bit, so you’ll want to download it to compile your program on a VM. Install Ubuntu as normal, then download the source code for the program you are interested in.

If your program doesn’t have any dependencies which aren’t already installed on ubuntu (or only depend on header files) you are probably good to go with the normal compilation process. If, like autotrace, it depends on libraries which don’t come installed on Ubuntu, then they won’t be on your Heroku instance, and you’ll need to compile a statically linked version.

Don’t worry, it’s not super difficult. Here’s what I did:

# download and unpack source into a directory and cd in there:
cd autotrace-0.31.1/
 
# install ubuntu packages which the program requires
sudo apt-get install libmagick++-dev
 
# configure to be statically linked
./configure --enable-shared=no
 
# compile
make

The make process creates an executable, which you can then place into the bin/ directory of your heroku app. I put it in the bin/x86_64-linux/ directory just to be clear about what can run where. Statically linked autotrace comes in at around 400k, so in order to keep your slug size down you’ll probably want to use your discretion here.

Finally, to test, you can open up a heroku console (heroku run console) and check that it is running successfully:

irb(main):006:0> `bin/x86_64-linux/autotrace`
Usage: bin/x86_64-linux/autotrace [options] .
(Missing .)
For more information, use ``-help''.

Success!

  1. This makes dragging items more intuitive: click on the item to drag it, click on the negative space to pan. So no more rectangles to confine your images! []
Tom Coleman

Co-creator of bindle.me, searching for simplicity, quality and elegance in technology, products and code.

See all Tom Coleman's posts

5 Responses to “Running binaries on Heroku”

  1. Tom Coleman says:

    Oh, I just remembered.

    You need to compile from source so you get a statically compiled binary which will run on a fresh machine (every time you spin up a new dyno you have to expect it to be a clean install).

  2. Tom Coleman says:

    Hey Corey,

    I don’t think you are going to be able to get a GUI program like Inkscape working on heroku which runs without an X environment (or is it a commandline tool too?).

    I’m pretty sure heroku don’t mind what we are doing here, the binary runs in a very restricted environment within your app container.

    I can’t remember the details on why I compiled autotrace from source rather than using the apt package, sorry! Either it wasn’t included in the version of Ubuntu that I mentioned above, or I needed a manually compiled version for some other reason.

    Cheers,
    Tom

  3. Cory Simmons says:

    Also, it seems like the package you installed wasn’t a listed req for Autotrace (http://packages.ubuntu.com/lucid/autotrace). What’s the deal with that? :)

    Sorry for so many questions. Getting Inkscape on Heroku is driving me batty. ;)

  4. Cory Simmons says:

    Hey Tom, I’m trying to do this with Inkscape. Could you just do `sudo apt-get build-dep inkscape`, `cd ~/inkscape_source_code`, build?

    Also, do you have any additional thoughts on this technique now that it’s been over a year? Is Heroku still cool with this?

  5. Cory Simmons says:

    Always 20 steps behind you Tom. Kudos on this. I’m going to try it with Inkscape.

Leave a Reply

  • Search: