In the previous post we set up a simple Smalltalk application on the client that could be pushed to the cloud. We are using the AidaWeb One-Click for Pharo as the “framework” and CogVM as the “runtime,” though you should be able to modify this process to use other frameworks and Smalltalk dialects. Now we look at changes needed to Cloud Foundry to receive that Smalltalk application. Much of this will be similar to the earlier process of adding Perl as a runtime and framework. (Peter McLain was particularly helpful in figuring out how to deploy a new runtime and framework on Cloud Foundry.)

The interesting part will come at the end when we deal with staging and starting an application.


Before starting, you should create a private cloud (following the instructions here), and set up a client environment with VMC that recognizes Aida as a framework (as described here). Start the server, create a tunnel, open shells on the server and on the client, create a user, and view the list of frameworks and runtimes.

Adding Smalltalk to Cloud Foundry involves modifying five files and creating nine files. All modifications are relatively minor, and most of the new files are generally boilerplate. From a shell on the server, navigate to the VCAP directory:

cd ~/cloudfoundry/vcap/

Minor Modifications to VCAP

Edit cloud_controller/app/models/app.rb to add CogVM and Aida to lines 26 and 27:

Runtimes = %w[cog ruby18 ruby19 java node php erlangR14B02 python26]
Frameworks = %w[aida sinatra rails3 java_web spring grails node php otp_rebar lift wsgi django unknown]

Then add the following three lines starting at line 541:

when "aida/1.0"
  self.framework = 'aida'
  self.runtime = 'cog'

Next we edit dev_setup/cookbooks/cloud_controller/attributes/default.rb to add one line at line 10:

default[:cloud_controller][:staging][:aida] = "aida.yml"

Next we edit
dev_setup/cookbooks/cloud_controller/templates/default/cloud_controller.yml.erb to add two lines starting at line 110:

  version: 3.9

Next we edit dev_setup/cookbooks/dea/attributes/default.rb to add cog as a runtime in line 3:

default[:dea][:runtimes] = ["cog", "ruby18", "ruby19", "nodejs", "java", "erlang", "php"]

The last modification to an existing file is to dev_setup/cookbooks/dea/templates/default/dea.yml.erb where we add the following lines starting at line 46:

<% if node[:dea][:runtimes].include?("cog") %>
    executable: /opt/smalltalk/cog/CogVM
    version: 3.9
    version_flag: '-version'
<% end %>

New Directories and Files

We will need several new directories:

mkdir dev_setup/cookbooks/cog/ 
mkdir dev_setup/cookbooks/cog/attributes/ 
mkdir dev_setup/cookbooks/cog/recipes/ 
mkdir staging/lib/vcap/staging/plugin/aida/

We need several new files that are fairly “boilerplate,” starting with dev_setup/cookbooks/cloud_controller/templates/default/aida.yml.erb:

name: "aida"
  - "cog":
      version: "3.9"
      description: "CogVM"
      executable: "/opt/smalltalk/cog/CogVM"
      default: true
  - ""

Next we copy a blank README:

cp dev_setup/cookbooks/erlang/README.rdoc dev_setup/cookbooks/cog/README.rdoc

Next we create dev_setup/cookbooks/cog/attributes/default.rb:

include_attribute "deployment"
default[:cog][:version] = "3.9"
default[:cog][:source] = \
default[:cog][:path] = \
  File.join(node[:deployment][:home], "deploy", "cog")

Next is dev_setup/cookbooks/cog/metadata.rb:

maintainer "VMware"
maintainer_email ""
license "Apache 2.0"
description "Installs/Configures CogVM"
long_description, 'README.rdoc'))
version "0.0.1"

Next is staging/lib/vcap/staging/plugin/manifests/aida.yml:

name: "aida"
  - cog:
      version: '3.9'
      description: 'CogVM for Smalltalk'
      executable: /opt/smalltalk/cog/CogVM
      default: true
  - "": '.'

Adding CogVM and Aida to Cloud Foundry

Next we create dev_setup/cookbooks/cog/recipes/default.rb. This is where CogVM and Aida are added to the deployment so they can be used later:

# Cookbook Name:: cog 
# Recipe:: default 
# Copyright 2012, VMware 
Chef::Log.debug("Installing ia32-libs for CogVM")
package "ia32-libs"
if not File.exists?("/opt/smalltalk")
  Dir.mkdir "/opt/smalltalk"
bash "Install CogVM from" do
  code <<-EOH
mkdir /opt/smalltalk/cog; cd /opt/smalltalk/cog
curl \
unzip; rm
  not_if do
bash "Install Aida" do
  code <<-EOH
mkdir /opt/smalltalk/aida; cd /opt/smalltalk/aida
curl \
unzip; rm
mv $resources/AidaOneClickPharo.image Aida.image
mv $resources/AidaOneClickPharo.changes Aida.changes
mv $resources/PharoV10.sources PharoV10.sources
rm -rf
  not_if do

As you can see, we are installing the 32-bit libraries (since we are using a 32-bit version of CogVM and are running on a 64-bit version of Ubuntu). Then we download a current version of the CogVM and the Aida runtime (much like we did here for the client). We copy the desired files from the Aida one-click Pharo directory, and delete the rest.

Now we get to the interesting work of staging and starting the application!

Staging Plugin for Aida

As we discussed earlier, Smalltalk does not fit the Cloud Foundry model of having a clean separation between the application code, the framework, and the runtime. While the image-based model is a challenge, it should not be too difficult. The approach we are taking is to have a file ( that contains Smalltalk code to load the application into a provided image (this way there is less copied from the client to the server). Cloud Foundry provides a “staging” step that is invoked as part of “pushing” an application from the client to the server. The staging step takes the various pieces from the client, mixes them with pieces from the server, creates any additional files, and bundles them all into a “droplet” that can be rapidly deployed when you want to start additional instances of your application (possibly on distributed machines).

In Cloud Foundry, staging is done by a staging “plugin” that is called when an application is pushed or updated from the client. The minimal plugin consists of a executable file, stage, and any files it expects. One approach is to create a Ruby script that calls a subclass of StagingPlugin to do the work. We create staging/lib/vcap/staging/plugin/aida/stage:

#!/usr/bin/env ruby
require File.expand_path('../../common', __FILE__)
plugin_class = StagingPlugin.load_plugin_for('aida')

With this, the interesting activity happens in staging/lib/vcap/staging/plugin/aida/plugin.rb:

class AidaPlugin < StagingPlugin
  include GemfileSupport
  def framework
  def stage_application
    Dir.chdir(destination_directory) do
  def do_staging
    Dir.chdir("app") {|dir|
      `cp /opt/smalltalk/aida/Aida.changes Aida.changes`
      `cp /opt/smalltalk/aida/Aida.image Aida.image`
      `ln -s /opt/smalltalk/aida/PharoV10.sources PharoV10.sources`
      staging = <<EOF
| file contents |
AIDASite default stop.
Author fullName: 'CloudFoundry'.
file := FileStream readOnlyFileNamed: ''.
contents := file contentsOfEntireFile.
Compiler evaluate: contents.
SmalltalkImage current snapshot: true andQuit: true.
EOF"", "w") {|f| f.write(staging) }
      run = "/opt/smalltalk/cog/CogVM -vm-display-null -vm-sound-null " +
      puts system(run)
      `chmod 400 Aida.image`
      main = <<EOF
AIDASite default
port: (SmalltalkImage current getSystemAttribute: 3) asNumber;
EOF"", "w") {|f| f.write( main ) }
  def start_command
    "/opt/smalltalk/cog/CogVM " +
      "-vm-display-null -vm-sound-null " +
      "Aida.image $VCAP_APP_PORT $@"
  def startup_script
    vars = environment_hash
    # PWD here is after we change to the 'app' directory.
    generate_startup_script(vars) do
      "# aida startup script"
  def stop_script
    vars = environment_hash

Most of the interesting work here is in the “staging” when Cloud Foundry takes the application from the client and creates a “droplet” that can later be deployed. We could, of course, wait till an instance is started to copy the extent and load the application code, but this means it would happen on each startup. Instead, we can copy the image, changes, and sources, launch Smalltalk, execute the developer’s script, and then save the image and make it read-only. This means that the only thing that needs to be done at launch time is change the listening port.

Deploying VCAP

With these modifications and additions to VCAP, we can update the cloud:

vcap stop; dev_setup/bin/vcap_dev_setup -d ~/cloudfoundry

Next we update the files that aren’t updated by the above (for whatever reason!?):

fromDir=`find ~/cloudfoundry/vcap/staging/ | grep pip_support.rb`
fromDir=`dirname $fromDir`
toDir=`find ~/cloudfoundry/.deployments/devbox/ | grep pip_support.rb`
toDir=`dirname $toDir`
cp -r $fromDir/aida $toDir
cp $fromDir/manifests/aida.yml $toDir/manifests/aida.yml

Then we can restart the cloud:

vcap start

Trying it Out!

Now from the client, get a list of the runtimes and frameworks:

vmc info; vmc runtimes; vmc frameworks

From the client, navigate to the application directory created here:

cd ~/cloud/aida/app

Make sure that there is a file named and that it does not have the code we added to test changing the port (since this is now handled on the server). Here is a sample file:

Author fullName: 'CloudFoundry'. "Developer's name"
WebDemoApp compile: 'introductionElement
  | e |
  e := WebElement new.
  e addText: self observee introduction.
  e addText: ''<p>Listening on port: '' , 
  session parent site port printString , ''</p>''.

From this directory with only this file (and possibly a manifest.yml), push the application to your cloud:

vmc push

Just as with the Perl application, there are a series of questions. We can name the application ‘aida-env‘ and otherwise accept the defaults. When the application has staged and started, we can navigate to and (if all went well!) see AidaWeb in the cloud.


We have deployed a Pharo Smalltalk application to Cloud Foundry. While the above does work with a recent Cloud Foundry development setup, things are changing rapidly and I suspect that several parts of the above are either redundant or could be done better. But, following the “make it work, make it right, make it fast” principle, we now have it working.

A limitation of the Cloud Foundry architecture is that Smalltalk’s image based persistence is not supported. Instead, we should look to using an external database as a Cloud Foundry service. More on that later!