Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add erlang support.

  • Loading branch information...
commit b6706b2efdcc0c5b66ff04cd15ca7b86206bfdfc 1 parent 3b24f5b
@paulj authored
View
4 cloud_controller/app/models/app.rb
@@ -19,8 +19,8 @@ class App < ActiveRecord::Base
AppStates = %w[STOPPED STARTED]
PackageStates = %w[PENDING STAGED FAILED]
- Runtimes = %w[ruby18 ruby19 java node]
- Frameworks = %w[sinatra rails3 spring grails node unknown]
+ Runtimes = %w[ruby18 ruby19 java node erlang]
+ Frameworks = %w[sinatra rails3 spring grails node erlang unknown]
validates_presence_of :name, :framework, :runtime
View
43 cloud_controller/staging/erlang/plugin.rb
@@ -0,0 +1,43 @@
+class ErlangPlugin < StagingPlugin
+ # TODO - Is there a way to avoid this without some kind of 'register' callback?
+ # e.g. StagingPlugin.register('sinatra', __FILE__)
+ def framework
+ 'erlang'
+ end
+
+ def stage_application
+ Dir.chdir(destination_directory) do
+ create_app_directories
+ copy_source_files
+ create_startup_script
+ end
+ end
+
+ # Let DEA fill in as needed..
+ def start_command
+ "%VCAP_LOCAL_RUNTIME% -pa ebin edit deps/*/ebin -boot start_sasl +B -noinput -s #{detect_app_name} $@"
+ end
+
+ private
+ def startup_script
+ vars = environment_hash
+ generate_startup_script(vars)
+ end
+
+ # Detect the name of the application by looking for .app files in ebin.
+ def detect_app_name
+ file, app_files = nil, app_files_matching_patterns
+
+ if app_files.length == 1
+ file = File.basename(app_files.first)[0..-5] # Remove the .app suffix
+ else
+ raise "Multiple Erlang .app files found. Cannot start application."
+ end
+
+ # TODO - Currently staging exceptions are not handled well.
+ # Convert to using exit status and return value on a case-by-case basis.
+ raise "Unable to determine Erlang startup command" unless file
+ file
+ end
+end
+
View
5 cloud_controller/staging/erlang/stage
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+require File.expand_path('../../common', __FILE__)
+plugin_class = StagingPlugin.load_plugin_for('erlang')
+plugin_class.validate_arguments!
+plugin_class.new(*ARGV).stage_application
View
13 cloud_controller/staging/manifests/erlang.yml
@@ -0,0 +1,13 @@
+---
+name: "erlang"
+runtimes:
+ - erlang:
+ version: 'R13B'
+ description: 'Erlang'
+ executable: erl
+ default: true
+app_servers:
+detection:
+ - "ebin/*.app": '.'
+staged_services:
+
View
5 dea/config/dea.yml
@@ -37,3 +37,8 @@ runtimes:
version: 1.6.0
version_flag: '-version'
environment:
+ erlang:
+ executable: erl
+ version: ".* 5.7.4"
+ version_flag: '-version'
+ environment:

11 comments on commit b6706b2

@trotter

You're my hero.

@trotter

It looks like this may just work if you also add apt-get install erlang to setup/vcap_setup.

@paulj
Owner

Oops. Missed that bit. Presumably I'll want erlang-nox to prevent the X dependent component coming in.

@trotter
@paulj
Owner

Applied now in abb59f4 (edited: the original commit wasn't printing a message properly, so I updated it)

@pbozeman

This is looking interesting.. :)

@tarcieri

Awesome. But shouldn't the associated framework be "otp" instead of "erlang"? Or are you intending "erlang" to support vanilla Erlang programs that don't have a .app file?

I'll have to pull this and play around with it...

@paulj
Owner

To be honest, I hadn't really thought about drawing that distinction.

The app file isn't particularly important, I'm mainly just using it as a signal to find the application, and also to work what to call -s on. Strictly speaking, I'm not even starting it in an OTP manner, since I'd need to use -exec 'application:start(name)' to do that.

Maybe I should look for .rel files, and use that to describe the startup sequence?

@tarcieri

That would definitely make sense.

I mention this only because OTP is always explicitly called out as the framework for Erlang programs and the system itself is typically described as Erlang/OTP. Given that I think "otp" would make the most sense as the name of the framework associated with Erlang programs.

@financeCoding

How well could this be used as a template for other frameworks? Does some kind of template exist for adding other languages/frameworks?

@paulj
Owner

@financeCoding this commit shows a starting point, but unfortunately the CloudFoundry codebase has moved on quite a bit, and you'd need to trace through the various refactorings that have been done in order to make it work with a recent codebase.

Perhaps @ciberch might be able to point you in good direction for a more recent template?

Please sign in to comment.
Something went wrong with that request. Please try again.