This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify the skeleton sinatra plugin to conform to the new staging plugin changes. Test plan: - Unit tests - Enabled the plugin on the stager, deployed the env app Change-Id: Ic600bf710320dfef53c94539838aa49e79c15f12
- Loading branch information
mpage
committed
Nov 18, 2011
1 parent
c092a1d
commit f78e2a4
Showing
10 changed files
with
137 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
--- | |||
ruby_paths: | |||
ruby18: ruby | |||
ruby19: ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,18 +1,4 @@ | |||
#!/bin/bash | |||
echo $$ > ./run.pid | echo $$ > ./run.pid | ||
|
cd <%= app_dir %> | ||
<% if uses_bundler %> | exec <%= ruby_path %> <%= sinatra_main %> $@ | ||
|
|||
export PATH="$PWD/app/rubygems/ruby/<%= library_version %>/bin:$PATH" | |||
export GEM_PATH="$PWD/app/rubygems/ruby/<%= library_version %>" | |||
export GEM_HOME="$PWD/app/rubygems/ruby/<%= library_version %>" | |||
export RUBYOPT="-I$PWD/ruby -rstdsync'" | |||
cd app | |||
exec ruby ./rubygems/ruby/<%= library_version %>/bin/bundle exec ruby ./<%= sinatra_main %> $@ | |||
|
|||
<% else %> | |||
|
|||
export RUBYOPT="-rubygems -I$PWD/ruby -rstdsync" | |||
cd app | |||
exec ruby ./<%= sinatra_main %> $@ | |||
|
|||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
require 'vcap/plugins/staging/sinatra/plugin' | |||
require 'vcap/plugins/staging/sinatra/version' |
4 changes: 4 additions & 0 deletions
4
plugins/staging/sinatra/lib/vcap/plugins/staging/sinatra/export.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
require 'vcap/plugin_registry' | |||
require 'vcap/plugins/staging/sinatra' | |||
|
|||
VCAP::PluginRegistry.register_plugins(VCAP::Plugins::Staging::Sinatra.new) |
96 changes: 96 additions & 0 deletions
96
plugins/staging/sinatra/lib/vcap/plugins/staging/sinatra/plugin.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,96 @@ | |||
require 'erb' | |||
require 'fileutils' | |||
|
|||
module VCAP | |||
module Plugins | |||
module Staging | |||
end | |||
end | |||
end | |||
|
|||
class VCAP::Plugins::Staging::Sinatra | |||
ASSET_DIR = File.expand_path('../../../../../../assets', __FILE__) | |||
STDSYNC_PATH = File.join(ASSET_DIR, 'stdsync.rb') | |||
START_TEMPLATE_PATH = File.join(ASSET_DIR, 'start.erb') | |||
STOP_SCRIPT_PATH = File.join(ASSET_DIR, 'stop') | |||
DEFAULT_CONFIG_PATH = File.join(ASSET_DIR, 'config.yml') | |||
SINATRA_DETECTION_REGEX = /require 'sinatra'|require "sinatra"/ | |||
|
|||
attr_reader :framework | |||
attr_reader :name | |||
|
|||
def initialize(config_path=DEFAULT_CONFIG_PATH) | |||
@framework = 'sinatra' | |||
@name = 'vcap_sinatra_staging_plugin' | |||
@ruby_paths = {} | |||
@start_template = ERB.new(File.read(START_TEMPLATE_PATH)) | |||
configure(config_path) | |||
end | |||
|
|||
def configure(config_path) | |||
config = YAML.load_file(config_path) | |||
@ruby_paths = config['ruby_paths'] | |||
unless @ruby_paths | |||
raise "ruby_paths missing from config at #{config_path}" | |||
end | |||
end | |||
|
|||
def stage(app_root, actions, app_props) | |||
sinatra_main = find_main_file(app_root) | |||
unless sinatra_main | |||
actions.abort_staging("Could not find main file in application root.") | |||
end | |||
|
|||
ruby_path = @ruby_paths[app_props['runtime']] | |||
unless ruby_path | |||
actions.abort_staging("No ruby executable for runtime #{app_props['runtime']}") | |||
end | |||
|
|||
actions.environment['RUBYOPT'] = '"-I$PWD/ruby -rstdsync"' | |||
copy_stdsync(actions.droplet_base_dir) | |||
generate_start_script(actions.start_script, File.basename(app_root), sinatra_main, ruby_path) | |||
generate_stop_script(actions.stop_script) | |||
end | |||
|
|||
# Finds the first file in the application root that requires sinatra. | |||
# | |||
# @param app_dir Path to the root of the application's source directory. | |||
def find_main_file(app_dir) | |||
for src_file in Dir.glob(File.join(app_dir, '*')) | |||
src_contents = File.read(src_file) | |||
return File.basename(src_file) if src_contents.match(SINATRA_DETECTION_REGEX) | |||
end | |||
nil | |||
end | |||
|
|||
# The file stdsync.rb contains a single line that sets stdout to synchronous mode. | |||
# The startup script we generate expects it to live at 'DROPLET_ROOT/ruby/stdsync.rb'. | |||
# Make sure we put it there. | |||
# | |||
# @param base_dir String Path to the base of the droplet being created. | |||
def copy_stdsync(base_dir) | |||
stdsync_dir = File.join(base_dir, 'ruby') | |||
stdsync_dst = File.join(stdsync_dir, 'stdsync.rb') | |||
FileUtils.mkdir(stdsync_dir) | |||
FileUtils.cp(STDSYNC_PATH, stdsync_dst) | |||
end | |||
|
|||
# Generates the startup script that will be run on the DEA. | |||
# | |||
# @param start_script File Open file that will house the start script. | |||
# @param app_dir String Basename of app dir relative to droplet root | |||
# @param sinatra_main String Name of 'main' sinatra file. | |||
# @param ruby_path String Path to ruby executable that should run the application | |||
def generate_start_script(start_script, app_dir, sinatra_main, ruby_path) | |||
contents = @start_template.result(binding()) | |||
start_script.write(contents) | |||
end | |||
|
|||
# Writes out the stop script | |||
# | |||
# @param stop_script File Open file that will house the stop script | |||
def generate_stop_script(stop_script) | |||
contents = File.read(STOP_SCRIPT_PATH) | |||
stop_script.write(contents) | |||
end | |||
end |
File renamed without changes.
2 changes: 0 additions & 2 deletions
2
plugins/staging/sinatra/lib/vcap/plugins/staging/sinatra_staging_plugin.rb
This file was deleted.
Oops, something went wrong.
75 changes: 0 additions & 75 deletions
75
plugins/staging/sinatra/lib/vcap/plugins/staging/sinatra_staging_plugin/plugin.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters