Skip to content


Subversion checkout URL

You can clone with
Download ZIP
100644 290 lines (207 sloc) 16.461 kB
2833436 @rwdaigle Draft of vulcan article
1 Title: Using Vulcan to Build Binary Dependencies for Heroku
2 Draft: true
3 Date: 15 June, 2012
5 Managing an application's code dependencies, which was once a source of constant pain and conflict, is now a solved problem in most modern languages. Ruby has [Bundler](, Node.js has [npm](, Python has [pip](, Clojure has [Leiningen](… the list continues.
7 What remains unsolved is how to declare and manage system-level dependencies -- external binaries that your application is dependent upon.
9 <!--
10 This post will explore explicitly managing and building system-level dependencies using the [Vulcan]( build server.
11 -->
13 ## The problem
15 It's common for an application to shell out to a local executable to perform some computationally intense work where compiled libraries are more performant or robust. Some common examples include [Ghostscript](, which your application might use to manipulate PDF or PostScript files, or [ImageMagick]( for resizing and cropping uploaded images.
17 Many deployment and hosting services attempt to fill this need by providing a set of common binaries bundled into every environment. This is a fragile approach that boxes you in to out-dated or incompatible versions more than it provides the exact version your app needs.
19 Additionally, having the ability to install system-wide binaries in your deployment environment is a poor solution. It merely shifts the burden of systems management from the service provider to you, the application developer. Without application-level isolation, installing binaries on a remote system still exposes you to dependency hell.
21 [Twelve-factor]( makes [the case]( to "not rely on the implicit existence of any system tools" for the deleterious effects it may have on future environment migration and upgrade efforts. Instead of solving system dependencies at a system level solve them at the application level by explicitly bundling binaries with the application that requires them.
23 ## Vulcan
25 Bundling a binary dependency requires that the binary be built specifically for the remote environment's operating system and processor architecture. This is a non-trivial task when you're faced with having to boot up a local host-VM just to simulate the remote server environment. Even then the processor architecture may be in conflict.
27 A better solution is to use the remote environment of your service provider to compile and build the required dependencies. Such a process would look something like this:
29 1. Specify the required library's source
30 2. Get a remote shell to your production environment
31 3. Download the library source in the remote shell
32 3. Compile the library remotely
33 4. Download the compiled library for use in your application's source-tree
35 While this process is not a lengthy one, your eye should spot that steps 2-4 are ripe for automation. That's where Vulcan comes in.
37 [Vulcan]( is a utility that bundles and uploads a source-tree to a remote environment, runs the necessary compilation commands on the source tree, and downloads the binary -- all in a single command. Vulcan consists of a Ruby-based CLI and Node.js server component and, though built by and for Heroku, is platform-agnostic.
39 **IMAGE(s)**
41 ## Setup
43 <p class="note">
44 These steps assume you have <a href="">git</a> and <a href="">ruby</a> available from the command line and have already signed up for a <a href="">Heroku account</a>. The <a href="">Heroku Toolbelt</a> can get you up and running if you're missing any components.
45 </p>
47 Installing the Vulcan CLI is simply a matter of installing the `vulcan` gem:
49 <pre lang="bash"><code>
50 $ gem install vulcan
51 Please run 'vulcan update' to update your build server.
52 Successfully installed vulcan-0.7.1
53 1 gem installed
54 </code></pre>
56 Vulcan's [build-server]( is a simple Node.js app that should be running _in the same remote environment your application will be deployed_. If your app runs on Heroku, Vulcan can deploy itself with `vulcan create appname`.
58 <pre lang="bash"><code>
59 $ vulcan create buildserver-you
60 Creating buildserver-you... done, stack is cedar
61 |
62 Initialized empty Git repository in /private/var/folders/Uz/UzRCgjzkGIi7Iqz9QNi6NUDrHf6/-Tmp-/d20120614-31875-1qjw1d6/.git/
63 Counting objects: 883, done.
64 ...
66 -----> Heroku receiving push
67 -----> Node.js app detected
68 ...
69 Dependencies installed
70 -----> Discovering process types
71 Procfile declares types -> web
72 -----> Compiled slug size is 4.1MB
73 -----> Launching... done, v3
74 deployed to Heroku
75 </code></pre>
77 The Vulcan build server is now running on Heroku at `` as a (free) single-dyno app.
79 <p class="note" markdown="1">
80 If you've manually deployed the build server to another provider you'll need to set its location so the CLI knows where to send build tasks. This is done by [setting]( the `VULCAN_HOST` env var: `$ export VULCAN_HOST=`
81 </p>
83 ## Build
85 The Ghostscript library was utilized in a tutorial on the [Heroku Dev Center]( for [processing PDF files]( It makes for a good example of building a binary application dependency.
87 ### Download source
89 First, download and expand the Linux x86 64-bit source for the [Ghostscript project]( At the time of this writing it is located at [](
91 <p class="note" markdown="1">
92 For the purpose of this article Heroku will be assumed to be the target environment. [Heroku's dynos]( run on 64-bit Linux kernel. If your target environment differs you will need to select the correct source distribution.
93 </p>
95 <pre lang="bash"><code>
96 $ wget
97 $ tar -xvzf ghostscript-9.05.tar.gz
98 x ghostscript-9.05/
99 x ghostscript-9.05/base/
100 x ghostscript-9.05/base/szlibxx.h
101 ...
102 </code></pre>
104 You now have a Ghostscript source directory at `./ghostscript-9.05`.
106 ### Remote compilation
108 Next, use the Vulcan CLI to initiate a build task on the build server. This will send the source to the target environment for compilation. The only required argument is `-s`, location of the Ghostscript source directory. The `-v` flag (verbose) will show the output from the compilation process and is recommended as, depending on the library, compilation can take some time and it's useful to see its progress.
110 <pre lang="bash"><code>
111 $ vulcan build -v -s ./ghostscript-9.05
112 Packaging local directory... done
113 Uploading source package... done
114 Building with: ./configure --prefix /app/vendor/ghostscript-9 &amp;&amp; make install
115 checking for gcc... gcc
116 checking whether the C compiler works... yes
117 ...
118 >> Downloading build artifacts to: /tmp/ghostscript-9.tgz
119 (available at
120 </code></pre>
122 On completion of the build process the resulting binaries are packages and downloaded for you. In this example the binary package can be found locally at `/tmp/ghostscript-9.tgz`. While the binary package is also available on your build server (here at ``) this is a temporary location. Due to the ephemeral nature of cloud filesystems the file is likely not to exist at that location for an extended period of time and should not be relied on.
124 Keep in mind, while the result are the library binaries they will not be executable on your local machine due to the difference in processor architecture of your local and target environments.
126 <p class="warning" markdown="1">
127 Although the [Vulcan source]( indicates the ability to fetch source packages directly from a URL (i.e. `$ vulcan build -s` this tends to result in build errors. The most reliable method is to manually download and expand the source before passing to vulcan.
128 </p>
130 ## Customization
132 Looking at the output from the Ghostscript example build you can see that a sensible build command is chosen for you: `./configure --prefix /app/vendor/ghostscript-9 && make install`. If you need to specify a non-default build command you can do so with the `-c` flag. Here is an example adding the `--without-ssl` configure option when building `wget`.
134 <pre lang="bash"><code>
135 $ vulcan build -v -s ./wget-1.13 -c "./configure --prefix /app/vendor/wget-1.13 --without-ssl &amp;&amp; make install" -p /app/vendor/wget-1.13
136 Packaging local directory... done
137 Uploading source package... done
138 Building with: ./configure --without-ssl &amp;&amp; make install
139 configure: configuring for GNU Wget 1.13
140 ...
141 >> Downloading build artifacts to: /tmp/wget-1.tgz
142 (available at
143 </code></pre>
145 The `-p` (prefix) flag is also used here to tell Vulcan where to look on the build server for the compiled artifacts (`/app/vendor/wget-1.13`). To avoid ambiguities it's best to specify this value and to set it to the same value as the `--prefix` flag passed to `./configure`.
147 ## Visibility
149 There are several utilities available to you to introspect the remote compilation process.
151 ### Logging
153 Outside of using the `-v` flag to force see the build output ou can also use the logs of the Vulcan build server to gain better visibility into the process. Since the Vulcan build server is just a Node.js app running in your target environment this is a trivial task. On Heroku use `heroku logs` and the `-a` flag with the name of your build server app.
155 <pre lang="bash"><code>
156 $ heroku logs -t -a buildserver-you
157 2012-07-04T15:29:20+00:00 app[web.1]: [7f3a7510-400a-44d4-9132-66a2e6c878a5] spawning build
158 2012-07-04T15:29:20+00:00 app[web.1]: valid socket
159 2012-07-04T15:29:21+00:00 heroku[run.1]: Awaiting client
160 2012-07-04T15:29:21+00:00 heroku[run.1]: Starting process with command `bin/make "7f3a7510-400a-44d4-9132-66a2e6c878a5"`
161 2012-07-04T15:29:22+00:00 heroku[run.1]: State changed from starting to up
162 2012-07-04T15:30:10+00:00 heroku[run.1]: Process exited with status 1
163 2012-07-04T15:30:10+00:00 heroku[run.1]: State changed from up to complete
164 </code></pre>
166 By default Vulcan will spawn a [on-off dyno]( to perform the build command. This is evident by the `run.1` dyno in the log output. In some circumstances this can result in a billable event if your web and one-off dyno usage combined [exceeds 750 hours for any one month](
168 If this small overage is meaningful to you you can sacrifice compilation concurrency and force Vulcan to execute the compilation command in-process with the `SPAWN_ENV` [config var](
170 <pre lang="bash"><code>
171 $ heroku config:add SPAWN_ENV=local -a buildserver-you
172 Setting config vars and restarting buildserver-you... done, v11
173 SPAWN_ENV: local
174 </code></pre>
176 The build command will then execute within the web process:
178 <pre lang="bash"><code>
179 $ heroku logs -t -a buildserver-you
180 2012-07-04T15:35:43+00:00 app[web.1]: [bbeab2b8-3941-4d41-94af-24c4f0fa65c0] spawning build
181 2012-07-04T15:36:33+00:00 app[web.1]: - - [Wed, 04 Jul 2012 15:36:33 GMT] "GET /output/bbeab2b8-3941-4d41-94af-24c4f0fa65c0 HTTP/1.1" 200 - "-" "Ruby"
182 2012-07-04T15:36:33+00:00 heroku[router]: GET dyno=web.1 queue=0 wait=0ms service=35ms status=200 bytes=75
183 </code></pre>
185 While this fails to adhere to the [background job]( pattern it may be acceptable for your use-case.
187 ### Remote shell
189 If a build fails it is often useful to be able to view the failed artefacts. Since Vulcan performs its work in temporary directories their contents are cleaned up after each build. However, a remote shell can be used to manually invoke the build command and navigate the build results.
191 At the start of every build request Vulcan outputs log statements resembling the following:
193 <pre lang="bash"><code>
194 2012-07-04T18:57:10+00:00 app[web.1]: [6869e68a-492d-4a7e-8b27-64352811d7dc] saving to couchdb
195 2012-07-04T18:57:10+00:00 app[web.1]: [6869e68a-492d-4a7e-8b27-64352811d7dc] saving attachment - [id:6869e68a-492d-4a7e-8b27-64352811d7dc rev:1-722a96f6734a3511efd73b7cfb9a2aed]
196 </code></pre>
198 The attachment id, here `6869e68a-492d-4a7e-8b27-64352811d7dc`, is all that's needed to manually invoke the build yourself. Establish a remote shell to the Vulcan buildserver environment. On Heroku you can use `heroku run bash`:
200 <pre lang="bash"><code>
201 $ heroku run bash -a buildserver-you
202 ~ $
203 </code></pre>
205 Then invoke the `bin/make` command with the attachment id. You will see the output of the build process and can then browse the output directory yourself.
207 <pre lang="bash"><code>
208 $ bin/make "6869e68a-492d-4a7e-8b27-64352811d7dc"
209 configure: configuring for GNU Wget 1.13
210 checking for a BSD-compatible install... /usr/bin/install -c
211 checking whether build environment is sane... yes
212 ...
213 $ cd /app/vendor/wget-1.13
214 </code></pre>
216 ## Vendoring
218 ## Heroku binaries
220 Many binaries were compiled in the course of writing this article for use on Heroku. Here is a list in case they're useful to you:
222 <p class="note" markdown="1">
223 If you'd like to list a binary compiled for Heroku here, please send a pull request [for this article]().
224 </p>
226 <table>
227 <tr>
228 <th>Library</th>
229 <th>Source</th>
230 <th>Build command</th>
231 <th>Binary</th>
232 </tr>
233 <tr>
234 <td><a href="">GNU Wget</a> v1.13</td>
235 <td><a href=""></a></td>
236 <td><code>vulcan build -v -s ./wget-1.13 -c "./configure --prefix /app/vendor/wget-1.13 --without-ssl && make install" -p /app/vendor/wget-1.13</code>
237 /vendor/wget-1.13</td>
238 <td><a href=""></a></td>
239 </tr>
240 </table>
242 #### Notes
246 repo of Heroku builds
248 specify output dir -p /tmp/name w/ configure --prefix (must be writable on dyno)
250 Update w/ gem install vulcan && vulcan update
252 If already have buildserver,
254 In practice: switch between local dev and remote (using the bin/ env)
256 [web.1]: [672b5df6-ad8c-49ed-9831-515207e2dc4f] ERROR: invalid secret
257 2012-07-04T17:39:47+00:00 app[web.1]: invalid secret
258 heroku config -s | grep SECRET
259 ~/.vulcan
260 ---
261 :app: buildserver-you
262 :host:
263 :secret: f575054501266d29eac5fcf9d8811dfb846f2520
266 <!--
268 ## Dependencies
270 Unlike Ghostscript, many libraries themselves have dependencies that are not available in your target environment. `wget` is a useful utility that requires the [GNU transport layer security library (gnutls)]( for SSL connections. To compile wget first compile gnutls.
272 <p class="note" markdown="1">
273 Recent versions of gnutls are [distributed]( with [XZ]( file compression. It will be left as an excercise for the reader to download and decompress the gnutls source.
274 </p>
276 <pre lang="bash"><code>
277 $ vulcan build -v -s ./gnutls-3.0.21
278 Packaging local directory... done
279 Uploading source package... done
280 Building with: ./configure --prefix /app/vendor/ghostscript-9 && make install
281 checking for gcc... gcc
282 checking whether the C compiler works... yes
283 ...
284 </code></pre>
286 xz compressions:
288 wget as example, requires gnutils
290 -->
Something went wrong with that request. Please try again.