Compare commits

...

17 Commits

Author SHA1 Message Date
David Dollar
8c3ef1a7af 0.37.0 2012-01-29 01:13:27 -05:00
David Dollar
cf69c31ae3 raw changelog 2012-01-29 01:13:02 -05:00
David Dollar
e16a35da4b fix changelog script 2012-01-29 01:12:56 -05:00
David Dollar
2490dd2a5b put an entire line of output inside a single mutex so we don't cross the streams 2012-01-29 00:09:44 -05:00
David Dollar
2705520496 fix race condition with process termination 2012-01-29 00:09:28 -05:00
David Dollar
522fee5e9e pedantry 2012-01-29 00:08:58 -05:00
David Dollar
c462473a25 fix simplecov 2012-01-28 18:53:43 -05:00
David Dollar
224fe94dc2 add more tests 2012-01-28 18:48:26 -05:00
David Dollar
7cb73f5c36 rearrange tasks, add coverage 2012-01-28 18:48:13 -05:00
David Dollar
1537ddbcc9 tweak simplecov entry 2012-01-28 16:27:02 -05:00
David Dollar
b04c81dd06 add simplecov 2012-01-28 16:26:12 -05:00
David Dollar
ae22d34967 Merge pull request #144 from technomancy/debian
Drop the S3 publishing rake tasks.
2012-01-26 17:02:42 -08:00
Phil Hagelberg
9a359efbf7 Drop the S3 publishing rake tasks. 2012-01-26 17:00:07 -08:00
David Dollar
9632227d29 0.37.0.pre5 2012-01-24 08:34:48 -08:00
David Dollar
288d118ca4 Merge pull request #142 from apollo13/master
Fix bash string comparision
2012-01-24 08:29:38 -08:00
David Dollar
576455b8d7 rename readme 2012-01-24 08:14:50 -08:00
Florian Apolloner
e1d3955d3c Fix the test for an empty string in bin/runner 2012-01-24 09:51:16 +01:00
30 changed files with 629 additions and 270 deletions

2
.gitignore vendored
View File

@@ -5,4 +5,4 @@
/man/*.markdown
/pkg
/tags
/vendor
/vendor

View File

@@ -1,11 +0,0 @@
0.26.1 12/05/2011 6160246da0fafe9cf8fde188d94bbc6babc667dc
==========================================================
Merge pull request #103 from csquared/load_env_from_irb [David Dollar]
refactor load_env to apply_environment [Chris Continanza]
rename load! to load_env! [Chris Continanza]
use ./.env as default [Chris Continanza]
load contents from env file [Chris Continanza]
refactor engine to expose env methods [Chris Continanza]
disable email notifications [David Dollar]
add travis config [David Dollar]

190
Changelog.md Normal file
View File

@@ -0,0 +1,190 @@
## 0.37.0.pre5 2012-01-24 9632227
0.37.0.pre5 [David Dollar]
Merge pull request #142 from apollo13/master [David Dollar]
rename readme [David Dollar]
Fix the test for an empty string in bin/runner [Florian Apolloner]
## 0.37.0.pre4 2012-01-24 a040324
0.37.0.pre4 [David Dollar]
Merge pull request #130 from clowder/foreman [David Dollar]
Don't expose the options hash. [Chris Lowder]
Simplify subclassing by adding all arguments to the initializer. Also, clean up the method signatures for existing exporters. [Chris Lowder]
Add ZenTest as a development dependency, there is an autotest folder but the gem is missing. [Chris Lowder]
Attempt to require the custom export class. [Chris Lowder]
Catching more than we need to. [Chris Lowder]
Extract commonality into the base class, make life easy for our plugin writers. [Chris Lowder]
Removing the hard coding of export formats allowing the user to 'plug-in' their own export format. [Chris Lowder]
Update README.markdown [David Dollar]
Revert "try on more rubies" [David Dollar]
try on more rubies [David Dollar]
fix webhook url [David Dollar]
Update README.markdown [David Dollar]
Update README.markdown [David Dollar]
ensure we have non-nil data, fixes #111 [David Dollar]
make sure error method exists. fixes #104 [David Dollar]
Merge pull request #136 from fnichol/foreman [David Dollar]
remove other from install instructions [David Dollar]
cleanup [David Dollar]
Revert "tweak authors" [David Dollar]
tweak authors [David Dollar]
fix authors [David Dollar]
readme tweaks [David Dollar]
readme tweaks [David Dollar]
fix up authors [David Dollar]
Update README.markdown [David Dollar]
fix up specs [David Dollar]
we're not chdiring any more [David Dollar]
use strings rather than symbols to better emulate the real thing [David Dollar]
Merge pull request #139 from brainopia/foreman [David Dollar]
Add specs for Foreman::Process#run [brainopia]
Implement Foreman::Process#kill,detach,alive?,dead? [brainopia]
- Use explicit fakefs tag in specs - Clean up trailing whitespace [brainopia]
Simplify Foreman::Process#with_environment [brainopia]
Add specs for options of Foreman::Process#run [brainopia]
Add specs for initialization of Foreman::Process [brainopia]
runit creates a full path to export directory. [Fletcher Nichol]
## 0.37.0.pre3 2012-01-22 51eee01
0.37.0.pre3 [David Dollar]
normalize platform names [David Dollar]
windows support [David Dollar]
add windows support [David Dollar]
dont need pty [David Dollar]
fix specs [David Dollar]
## 0.37.0.pre2 2012-01-22 2995a60
0.37.0.pre2 [David Dollar]
0.37.0.pre1 [David Dollar]
remove unnecessary stdout/stderr flattening [David Dollar]
use PLATFORM=jruby instead of JRUBY=true [David Dollar]
## 0.37.0.pre1 2012-01-22 3e98170
fix java build bug [David Dollar]
dont do rubygems/bundler in the Rakefile [David Dollar]
switch to posix-spawn for jruby [David Dollar]
add jruby build [David Dollar]
spork is in the gemspec now [David Dollar]
remove debugging [David Dollar]
move the spoon require into the jruby branch [David Dollar]
pass basedir along to the runner script [David Dollar]
beef up the runner script to allow a working directory to be set [David Dollar]
Merge pull request #140 from jc00ke/foreman [David Dollar]
Move spoon dep to Gemfile [jc00ke]
Using spoon for JRuby support [jc00ke]
use default bucket for storage [David Dollar]
Merge pull request #138 from technomancy/debian [David Dollar]
Add Debian packaging. [Phil Hagelberg]
Ignore vendor dir. [Phil Hagelberg]
## 0.36.1 2012-01-18 1485eeb
0.36.1 [David Dollar]
bump term-ansicolor in gemspec [David Dollar]
## 0.36.0 2012-01-17 a73dce5
0.36.0 [David Dollar]
sync the writer stream [David Dollar]
capture stderr as well [David Dollar]
## 0.35.0 2012-01-16 2bfc065
update rake [David Dollar]
0.35.0 [David Dollar]
Merge pull request #132 from Viximo/feature/concurrency [David Dollar]
Fix export specs [Matt Griffin]
Merge branch 'master' of https://github.com/michaeldwan/foreman into feature/concurrency [Matt Griffin]
default process concurrency is 0 when concurrency options specified, otherwise default concurrency is 1 [Michael Dwan]
## 0.34.1 2012-01-16 d4c2332
0.34.1 [David Dollar]
fix missing start desc [David Dollar]
## 0.34.0 2012-01-16 a278755
0.34.0 [David Dollar]
update man page [David Dollar]
update docs for -d [David Dollar]
Merge pull request #101 from ndbroadbent/foreman [David Dollar]
Wrap around to the first colour when all the colours are used [Craig R Webster]
run specs in random order [David Dollar]
update rspec [David Dollar]
pedantry [David Dollar]
Set executable bit on runit run scripts. [Matthijs Langenberg]
Merge pull request #114 from gburt/master [David Dollar]
add more colors [Gabriel Burt]
Added option to specify app_root, if executing a Procfile from a shared location [Nathan Broadbent]
## 0.33.1 2012-01-16 533139e
0.33.1 [David Dollar]
Merge pull request #129 from fnichol/resolve-home-template [David Dollar]
Expand template path under user's home directory. [Fletcher Nichol]
## 0.33.0 2012-01-15 cf269c3
0.33.0 [David Dollar]
Revert "Merge pull request #125 from brainopia/master" [David Dollar]
## 0.32.0 2012-01-12 83748cb
0.32.0 [David Dollar]
Merge pull request #125 from brainopia/master [David Dollar]
Merge pull request #121 from Viximo/feature/run [David Dollar]
Return some whitespace that was accidentally removed [Matt Griffin]
Steal the run method back from Thor so that it can be used in place for exec for running commands in the foreman environment. [Matt Griffin]
Remove old cruft [brainopia]
In case someone wants to use bin/runner directly [brainopia]
Fix for double fork [brainopia]
Use ruby exec which works with escaped cmd and replaces shell [brainopia]
Fix foreman to work with cmds containing pipes and redirects [brainopia]
Add "exec" action to allow execution of arbitrary commands with the app's environment. [Matt Griffin]
tweak readme [David Dollar]
## 0.31.0 2012-01-04 342d30b
0.31.0 [David Dollar]
make fork more robust [David Dollar]
remove unnecessary debug [David Dollar]
add more information when shutting down [David Dollar]
Merge pull request #110 from lstoll/master [David Dollar]
Use different port ranges for each process type [Lincoln Stoll]
## 0.30.1 2011-12-23 fcfa913
0.30.1 [David Dollar]
require thread for mutex [David Dollar]
## 0.30.0 2011-12-22 fc95936
0.30.0 [David Dollar]
compatibility with ruby 1.8 [David Dollar]
## 0.29.0 2011-12-22 356c61f
0.29.0 [David Dollar]
## 0.28.0.pre2 2011-12-08 dcff4da
0.28.0.pre2 [David Dollar]
fix pipe error [David Dollar]
## 0.28.0.pre1 2011-12-08 c7b6b33
0.28.0.pre1 [David Dollar]
Merge branch 'fork' [David Dollar]
wip [David Dollar]
wip [David Dollar]
wip [David Dollar]
wip [David Dollar]
wip [David Dollar]
## 0.27.0 2011-12-05 914a1ee
0.27.0 [David Dollar]
add changelog [David Dollar]
Merge pull request #103 from csquared/load_env_from_irb [David Dollar]
refactor load_env to apply_environment [Chris Continanza]
rename load! to load_env! [Chris Continanza]
use ./.env as default [Chris Continanza]
load contents from env file [Chris Continanza]
refactor engine to expose env methods [Chris Continanza]
disable email notifications [David Dollar]
add travis config [David Dollar]
## 0.26.1 2011-12-05 a5e0943
Merge pull request #103 from csquared/load_env_from_irb [David Dollar]
refactor load_env to apply_environment [Chris Continanza]
rename load! to load_env! [Chris Continanza]
use ./.env as default [Chris Continanza]
load contents from env file [Chris Continanza]
refactor engine to expose env methods [Chris Continanza]
disable email notifications [David Dollar]
add travis config [David Dollar]

View File

@@ -15,10 +15,10 @@ group :development do
gem 'rake'
gem 'ronn'
gem 'fakefs', '~> 0.3.2'
gem 'rcov', '~> 0.9.8'
gem 'rr', '~> 1.0.2'
gem 'rspec', '~> 2.0'
gem 'ZenTest'
gem 'aws-s3'
gem "rubyzip"
gem "simplecov", :require => false
end

View File

@@ -1,7 +1,7 @@
PATH
remote: .
specs:
foreman (0.37.0.pre4)
foreman (0.37.0)
term-ansicolor (~> 1.0.7)
thor (>= 0.13.6)
@@ -20,6 +20,7 @@ GEM
hpricot (0.8.2)
hpricot (0.8.2-java)
mime-types (1.16)
multi_json (1.0.4)
mustache (0.11.2)
parka (0.6.2)
crack
@@ -27,8 +28,6 @@ GEM
thor
posix-spawn (0.3.6)
rake (0.9.2.2)
rcov (0.9.8)
rcov (0.9.8-java)
rdiscount (1.6.5)
rest-client (1.6.1)
mime-types (>= 1.16)
@@ -46,6 +45,10 @@ GEM
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
rubyzip (0.9.4)
simplecov (0.5.4)
multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
term-ansicolor (1.0.7)
thor (0.14.6)
win32console (1.3.0-x86-mingw32)
@@ -64,9 +67,9 @@ DEPENDENCIES
parka
posix-spawn (~> 0.3.6)
rake
rcov (~> 0.9.8)
ronn
rr (~> 1.0.2)
rspec (~> 2.0)
rubyzip
simplecov
win32console (~> 1.3.0)

190
Rakefile
View File

@@ -1,192 +1,6 @@
require "rake"
require "rspec"
require "rspec/core/rake_task"
$:.unshift File.expand_path("../lib", __FILE__)
require "foreman"
task :default => :spec
task :release => :man
desc "Run all specs"
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/**/*_spec.rb'
end
desc "Generate RCov code coverage report"
task :rcov => "rcov:build" do
%x{ open coverage/index.html }
end
RSpec::Core::RakeTask.new("rcov:build") do |t|
t.pattern = 'spec/**/*_spec.rb'
t.rcov = true
t.rcov_opts = [ "--exclude", ".bundle", "--exclude", "spec" ]
end
desc 'Build the manual'
task :man do
ENV['RONN_MANUAL'] = "Foreman Manual"
ENV['RONN_ORGANIZATION'] = "Foreman #{Foreman::VERSION}"
sh "ronn -w -s toc -r5 --markdown man/*.ronn"
end
desc "Commit the manual to git"
task "man:commit" => :man do
sh "git add README.markdown"
sh "git commit -m 'update readme' || echo 'nothing to commit'"
end
desc "Generate the Github docs"
task :pages => "man:commit" do
sh %{
cp man/foreman.1.html /tmp/foreman.1.html
git checkout gh-pages
rm ./index.html
cp /tmp/foreman.1.html ./index.html
git add -u index.html
git commit -m "saving man page to github docs"
git push origin -f gh-pages
git checkout master
}
end
task :authors do
authors = %x{ git log --pretty=format:"%an" | sort -u }.split("\n")
puts authors.join(", ")
end
## dist
require "erb"
require "fileutils"
require "tmpdir"
def assemble(source, target, perms=0644)
FileUtils.mkdir_p(File.dirname(target))
File.open(target, "w") do |f|
f.puts ERB.new(File.read(source)).result(binding)
end
File.chmod(perms, target)
end
def assemble_distribution(target_dir=Dir.pwd)
distribution_files.each do |source|
target = source.gsub(/^#{project_root}/, target_dir)
FileUtils.mkdir_p(File.dirname(target))
FileUtils.cp(source, target)
end
end
GEM_BLACKLIST = %w( bundler foreman )
def assemble_gems(target_dir=Dir.pwd)
lines = %x{ bundle show }.strip.split("\n")
raise "error running bundler" unless $?.success?
%x{ env BUNDLE_WITHOUT="development:test" bundle show }.split("\n").each do |line|
if line =~ /^ \* (.*?) \((.*?)\)/
next if GEM_BLACKLIST.include?($1)
puts "vendoring: #{$1}-#{$2}"
gem_dir = %x{ bundle show #{$1} }.strip
FileUtils.mkdir_p "#{target_dir}/vendor/gems"
%x{ cp -R "#{gem_dir}" "#{target_dir}/vendor/gems" }
end
end.compact
end
def beta?
Foreman::VERSION.to_s =~ /pre/
end
def clean(file)
rm file if File.exists?(file)
end
def distribution_files(type=nil)
require "foreman/distribution"
base_files = Foreman::Distribution.files
type_files = type ?
Dir[File.expand_path("../dist/resources/#{type}/**/*", __FILE__)] :
[]
base_files.concat(type_files)
end
def mkchdir(dir)
FileUtils.mkdir_p(dir)
Dir.chdir(dir) do |dir|
yield(File.expand_path(dir))
end
end
def pkg(filename)
File.expand_path("../pkg/#{filename}", __FILE__)
end
def project_root
File.dirname(__FILE__)
end
def resource(name)
File.expand_path("../dist/resources/#{name}", __FILE__)
end
def s3_connect
return if @s3_connected
require "aws/s3"
unless ENV["DAVID_RELEASE_ACCESS"] && ENV["DAVID_RELEASE_SECRET"]
puts "please set DAVID_RELEASE_ACCESS and DAVID_RELEASE_SECRET in your environment"
exit 1
end
AWS::S3::Base.establish_connection!(
:access_key_id => ENV["DAVID_RELEASE_ACCESS"],
:secret_access_key => ENV["DAVID_RELEASE_SECRET"]
)
@s3_connected = true
end
def store(package_file, filename, bucket="assets.foreman.io")
s3_connect
puts "storing: #{filename}"
AWS::S3::S3Object.store(filename, File.open(package_file), bucket, :access => :public_read)
end
def tempdir
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
yield(dir)
end
end
end
def version
require "foreman/version"
Foreman::VERSION
end
Dir[File.expand_path("../dist/**/*.rake", __FILE__)].each do |rake|
import rake
end
task :changelog do
timestamp = Time.now.utc.strftime('%m/%d/%Y')
sha = `git log | head -1`.split(' ').last
changelog = ["#{version} #{timestamp} #{sha}"]
changelog << ('=' * changelog[0].length)
changelog << ''
last_sha = `cat Changelog | head -1`.split(' ').last
shortlog = `git log #{last_sha}..HEAD --pretty=format:'%s [%an]'`
changelog << shortlog.split("\n")
changelog.concat ['', '', '']
old_changelog = File.read('Changelog')
File.open('Changelog', 'w') do |file|
file.write(changelog.join("\n"))
file.write(old_changelog)
end
Dir[File.expand_path("../tasks/*.rake", __FILE__)].each do |task|
load task
end

View File

@@ -29,7 +29,7 @@ shift $((OPTIND-1))
command=$1
if [ "$1" == "" ]; then
if [ -z "$1" ]; then
usage
fi

15
dist/deb.rake vendored
View File

@@ -20,12 +20,6 @@ file pkg("/apt-#{version}/foreman-#{version}.deb") => distribution_files("deb")
deb = File.basename(t.name)
sh "ar -r #{t.name} debian-binary control.tar.gz data.tar.gz"
touch "Sources"
sh "apt-ftparchive packages . > Packages"
sh "gzip -c Packages > Packages.gz"
sh "apt-ftparchive release . > Release"
sh "gpg -abs -u 0F1B0520 -o Release.gpg Release"
end
end
@@ -37,12 +31,3 @@ task "deb:clean" do
clean pkg("foreman-#{version}.deb")
FileUtils.rm_rf("pkg/apt-#{version}") if Dir.exists?("pkg/apt-#{version}")
end
desc "Publish .deb to S3."
task "deb:release" => "deb:build" do |t|
Dir["pkg/apt-#{version}/*"].each do |file|
unless File.directory?(file)
store file, "apt/#{File.basename(file)}"
end
end
end

View File

@@ -40,22 +40,11 @@ class Foreman::CLI < Thor
method_option :port, :type => :numeric, :aliases => "-p"
method_option :user, :type => :string, :aliases => "-u"
method_option :template, :type => :string, :aliases => "-t"
method_option :concurrency, :type => :string, :aliases => "-c",
:banner => '"alpha=5,bar=3"'
method_option :concurrency, :type => :string, :aliases => "-c", :banner => '"alpha=5,bar=3"'
def export(format, location=nil)
check_procfile!
begin
require "foreman/export/#{ format.tr('-', '_') }"
classy_format = classify(format)
formatter = constantize("Foreman::Export::#{ classy_format }")
rescue NameError => ex
error "Unknown export format: #{format} (no class Foreman::Export::#{ classy_format })."
rescue LoadError => ex
error "Unknown export format: #{format} (unable to load file 'foreman/export/#{ format.tr('-', '_') }')."
end
formatter = Foreman::Export.formatter(format)
formatter.new(location, engine, options).export
rescue Foreman::Export::Exception => ex
error ex.message
@@ -65,7 +54,7 @@ class Foreman::CLI < Thor
def check
error "no processes defined" unless engine.procfile.entries.length > 0
display "valid procfile detected (#{engine.procfile.process_names.join(', ')})"
puts "valid procfile detected (#{engine.procfile.process_names.join(', ')})"
end
desc "run COMMAND", "Run a command using your application's environment"
@@ -95,19 +84,11 @@ private ######################################################################
options[:procfile] || "Procfile"
end
def display(message)
puts message
end
def error(message)
puts "ERROR: #{message}"
exit 1
end
def procfile_exists?(procfile)
File.exist?(procfile)
end
def options
original_options = super
return original_options unless File.exists?(".foreman")

View File

@@ -78,9 +78,17 @@ private ######################################################################
end
def terminate_gracefully
return if @terminating
@terminating = true
info "sending SIGTERM to all processes"
kill_all "SIGTERM"
Timeout.timeout(5) { Process.waitall }
Timeout.timeout(5) do
while running_processes.length > 0
pid, status = Process.wait2
process = running_processes.delete(pid)
info "process terminated", process.name
end
end
rescue Timeout::Error
info "sending SIGKILL to all processes"
kill_all "SIGKILL"
@@ -112,16 +120,16 @@ private ######################################################################
process = running_processes.delete(pid)
info "process terminated", process.name
terminate_gracefully
kill_all
rescue Errno::ECHILD
end
def info(message, name="system", color=Term::ANSIColor.white)
print color
print "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
print Term::ANSIColor.reset
print message.chomp
puts ""
output = ""
output += color
output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
output += Term::ANSIColor.reset
output += message.chomp
puts output
end
def print(message=nil)

View File

@@ -1,9 +1,30 @@
require "foreman"
require "foreman/helpers"
module Foreman::Export
extend Foreman::Helpers
class Exception < ::Exception; end
def self.formatter(format)
begin
require "foreman/export/#{ format.tr('-', '_') }"
classy_format = classify(format)
formatter = constantize("Foreman::Export::#{ classy_format }")
rescue NameError => ex
error "Unknown export format: #{format} (no class Foreman::Export::#{ classy_format })."
rescue LoadError => ex
error "Unknown export format: #{format} (unable to load file 'foreman/export/#{ format.tr('-', '_') }')."
end
end
def self.error(message)
raise Foreman::Export::Exception.new(message)
end
end
require "foreman/export/base"
require "foreman/export/inittab"
require "foreman/export/upstart"

View File

@@ -24,12 +24,12 @@ class Foreman::Export::Inittab < Foreman::Export::Base
inittab = inittab.join("\n") + "\n"
if fname
if location == "-"
puts inittab
else
FileUtils.mkdir_p(log_root) rescue error "could not create #{log_root}"
FileUtils.chown(user, nil, log_root) rescue error "could not chown #{log_root} to #{user}"
write_file(fname, inittab)
else
puts inittab
write_file(location, inittab)
end
end

View File

@@ -6,9 +6,8 @@ module Foreman::Helpers
# classify('job-name') # => 'JobName'
def classify(dashed_word)
dashed_word.split('-').each { |part| part[0] = part[0].chr.upcase }.join
end
end # Tries to find a constant with the name specified in the argument string:
# Tries to find a constant with the name specified in the argument string:
#
# constantize("Module") # => Module
# constantize("Test::Unit") # => Test::Unit
@@ -28,10 +27,6 @@ module Foreman::Helpers
def constantize(camel_cased_word)
camel_cased_word = camel_cased_word.to_s
if camel_cased_word.include?('-')
camel_cased_word = classify(camel_cased_word)
end
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
@@ -47,4 +42,4 @@ module Foreman::Helpers
end
constant
end
end
end

View File

@@ -63,7 +63,7 @@ private
$stderr.reopen writer
reader.close
exec Foreman.runner, "-d", basedir, command
end
end
end
[ reader, pid ]
end

View File

@@ -1,5 +1,5 @@
module Foreman
VERSION = "0.37.0.pre4"
VERSION = "0.37.0"
end

View File

@@ -27,6 +27,15 @@ describe "Foreman::CLI", :fakefs do
describe "export" do
describe "options" do
it "uses .foreman" do
write_procfile
File.open(".foreman", "w") { |f| f.puts "concurrency: alpha=2" }
mock_export = mock(Foreman::Export::Upstart)
mock(Foreman::Export::Upstart).new("/upstart", is_a(Foreman::Engine), { "concurrency" => "alpha=2" }) { mock_export }
mock_export.export
foreman %{ export upstart /upstart }
end
it "respects --env" do
write_procfile
write_env("envfile")
@@ -49,10 +58,18 @@ describe "Foreman::CLI", :fakefs do
describe "with a Procfile" do
before(:each) { write_procfile }
describe "with an invalid formatter" do
describe "with a formatter with a generic error" do
before do
mock(Foreman::Export).formatter("errorful") { Class.new(Foreman::Export::Base) do
def export
raise Foreman::Export::Exception.new("foo")
end
end }
end
it "prints an error" do
mock_error(subject, "Unknown export format: invalidformatter (unable to load file 'foreman/export/invalidformatter').") do
subject.export("invalidformatter")
mock_error(subject, "foo") do
subject.export("errorful")
end
end
end
@@ -76,7 +93,7 @@ describe "Foreman::CLI", :fakefs do
before { write_procfile }
it "displays the jobs" do
mock(subject).display("valid procfile detected (alpha, bravo)")
mock(subject).puts("valid procfile detected (alpha, bravo)")
subject.check
end
end

View File

@@ -0,0 +1,22 @@
require "spec_helper"
require "foreman/export/base"
describe "Foreman::Export::Base" do
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
let(:location) { "/tmp/init" }
let(:engine) { Foreman::Engine.new(procfile) }
let(:subject) { Foreman::Export::Base.new(location, engine) }
it "has a say method for displaying info" do
mock(subject).puts("[foreman export] foo")
subject.send(:say, "foo")
end
it "export needs to be overridden" do
lambda { subject.export }.should raise_error("export method must be overridden")
end
it "raises errors as a Foreman::Export::Exception" do
lambda { subject.send(:error, "foo") }.should raise_error(Foreman::Export::Exception, "foo")
end
end

View File

@@ -17,7 +17,14 @@ describe Foreman::Export::Bluepill, :fakefs do
normalize_space(File.read("/tmp/init/app.pill")).should == normalize_space(example_export_file("bluepill/app.pill"))
end
context "with concurrency" do
it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.pill")
bluepill.export
bluepill.export
end
context "with concurrency" do
let(:options) { Hash[:concurrency => "alpha=2"] }
it "exports to the filesystem with concurrency" do

View File

@@ -0,0 +1,40 @@
require "spec_helper"
require "foreman/engine"
require "foreman/export/inittab"
require "tmpdir"
describe Foreman::Export::Inittab, :fakefs do
let(:location) { "/tmp/inittab" }
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
let(:location) { "/tmp/inittab" }
let(:engine) { Foreman::Engine.new(procfile) }
let(:options) { Hash.new }
let(:inittab) { Foreman::Export::Inittab.new(location, engine, options) }
before(:each) { load_export_templates_into_fakefs("inittab") }
before(:each) { stub(inittab).say }
it "exports to the filesystem" do
inittab.export
File.read("/tmp/inittab").should == example_export_file("inittab/inittab.default")
end
context "to stdout" do
let(:location) { "-" }
it "exports to stdout" do
mock(inittab).puts example_export_file("inittab/inittab.default")
inittab.export
end
end
context "with concurrency" do
let(:options) { Hash[:concurrency => "alpha=2"] }
it "exports to the filesystem with concurrency" do
inittab.export
File.read("/tmp/inittab").should == example_export_file("inittab/inittab.concurrency")
end
end
end

View File

@@ -22,6 +22,17 @@ describe Foreman::Export::Upstart, :fakefs do
File.read("/tmp/init/app-bravo-1.conf").should == example_export_file("upstart/app-bravo-1.conf")
end
it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.conf")
mock(FileUtils).rm("/tmp/init/app-alpha.conf")
mock(FileUtils).rm("/tmp/init/app-alpha-1.conf")
mock(FileUtils).rm("/tmp/init/app-bravo.conf")
mock(FileUtils).rm("/tmp/init/app-bravo-1.conf")
upstart.export
upstart.export
end
context "with concurrency" do
let(:options) { Hash[:concurrency => "alpha=2"] }

View File

@@ -1,2 +1,24 @@
require "spec_helper"
require "foreman/export"
describe "Foreman::Export" do
subject { Foreman::Export }
describe "with a formatter that doesn't declare the appropriate class" do
it "prints an error" do
mock(subject).require("foreman/export/invalidformatter")
mock_export_error("Unknown export format: invalidformatter (no class Foreman::Export::Invalidformatter).") do
subject.formatter("invalidformatter")
end
end
end
describe "with an invalid formatter" do
it "prints an error" do
mock_export_error("Unknown export format: invalidformatter (unable to load file 'foreman/export/invalidformatter').") do
subject.formatter("invalidformatter")
end
end
end
end

View File

@@ -0,0 +1,26 @@
require "spec_helper"
require "foreman/helpers"
describe "Foreman::Helpers" do
before do
module Foo
class Bar; end
end
end
after do
Object.send(:remove_const, :Foo)
end
subject { o = Object.new; o.extend(Foreman::Helpers); o }
it "should classify words" do
subject.classify("foo").should == "Foo"
subject.classify("foo-bar").should == "FooBar"
end
it "should constantize words" do
subject.constantize("Object").should == Object
subject.constantize("Foo::Bar").should == Foo::Bar
end
end

View File

@@ -25,4 +25,10 @@ describe Foreman do
ENV['FOO'].should == 'bar'
end
end
describe "runner" do
it "should exist" do
File.exists?(Foreman.runner).should == true
end
end
end

View File

@@ -0,0 +1,4 @@
# ----- foreman app processes -----
AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-1.log 2>&1'
AP02:4:respawn:/bin/su - app -c 'PORT=5001 ./alpha >> /var/log/app/alpha-2.log 2>&1'
# ----- end foreman app processes -----

View File

@@ -0,0 +1,4 @@
# ----- foreman app processes -----
AP01:4:respawn:/bin/su - app -c 'PORT=5000 ./alpha >> /var/log/app/alpha-1.log 2>&1'
AP02:4:respawn:/bin/su - app -c 'PORT=5100 ./bravo >> /var/log/app/bravo-1.log 2>&1'
# ----- end foreman app processes -----

View File

@@ -1,10 +1,20 @@
require "rubygems"
require "simplecov"
SimpleCov.start do
add_filter "/spec/"
end
require "rspec"
require "fakefs/safe"
require "fakefs/spec_helpers"
$:.unshift File.expand_path("../../lib", __FILE__)
def mock_export_error(message)
lambda { yield }.should raise_error(Foreman::Export::Exception, message)
end
def mock_error(subject, message)
mock_exit do
mock(subject).puts("ERROR: #{message}")
@@ -37,9 +47,11 @@ def write_procfile(procfile="Procfile", alpha_env="")
File.expand_path(procfile)
end
def write_env(env=".env")
def write_env(env=".env", options={"FOO"=>"bar"})
File.open(env, "w") do |file|
file.puts "FOO=bar"
options.each do |key, val|
file.puts "#{key}=#{val}"
end
end
end

113
tasks/dist.rake Normal file
View File

@@ -0,0 +1,113 @@
require "erb"
require "fileutils"
require "tmpdir"
def assemble(source, target, perms=0644)
FileUtils.mkdir_p(File.dirname(target))
File.open(target, "w") do |f|
f.puts ERB.new(File.read(source)).result(binding)
end
File.chmod(perms, target)
end
def assemble_distribution(target_dir=Dir.pwd)
distribution_files.each do |source|
target = source.gsub(/^#{project_root}/, target_dir)
FileUtils.mkdir_p(File.dirname(target))
FileUtils.cp(source, target)
end
end
GEM_BLACKLIST = %w( bundler foreman )
def assemble_gems(target_dir=Dir.pwd)
lines = %x{ bundle show }.strip.split("\n")
raise "error running bundler" unless $?.success?
%x{ env BUNDLE_WITHOUT="development:test" bundle show }.split("\n").each do |line|
if line =~ /^ \* (.*?) \((.*?)\)/
next if GEM_BLACKLIST.include?($1)
puts "vendoring: #{$1}-#{$2}"
gem_dir = %x{ bundle show #{$1} }.strip
FileUtils.mkdir_p "#{target_dir}/vendor/gems"
%x{ cp -R "#{gem_dir}" "#{target_dir}/vendor/gems" }
end
end.compact
end
def beta?
Foreman::VERSION.to_s =~ /pre/
end
def clean(file)
rm file if File.exists?(file)
end
def distribution_files(type=nil)
require "foreman/distribution"
base_files = Foreman::Distribution.files
type_files = type ?
Dir[File.expand_path("../dist/resources/#{type}/**/*", __FILE__)] :
[]
base_files.concat(type_files)
end
def mkchdir(dir)
FileUtils.mkdir_p(dir)
Dir.chdir(dir) do |dir|
yield(File.expand_path(dir))
end
end
def pkg(filename)
File.expand_path("../pkg/#{filename}", __FILE__)
end
def project_root
File.dirname(__FILE__)
end
def resource(name)
File.expand_path("../dist/resources/#{name}", __FILE__)
end
def s3_connect
return if @s3_connected
require "aws/s3"
unless ENV["DAVID_RELEASE_ACCESS"] && ENV["DAVID_RELEASE_SECRET"]
puts "please set DAVID_RELEASE_ACCESS and DAVID_RELEASE_SECRET in your environment"
exit 1
end
AWS::S3::Base.establish_connection!(
:access_key_id => ENV["DAVID_RELEASE_ACCESS"],
:secret_access_key => ENV["DAVID_RELEASE_SECRET"]
)
@s3_connected = true
end
def store(package_file, filename, bucket="assets.foreman.io")
s3_connect
puts "storing: #{filename}"
AWS::S3::S3Object.store(filename, File.open(package_file), bucket, :access => :public_read)
end
def tempdir
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
yield(dir)
end
end
end
def version
require "foreman/version"
Foreman::VERSION
end
Dir[File.expand_path("../../dist/**/*.rake", __FILE__)].each do |rake|
import rake
end

81
tasks/release.rake Normal file
View File

@@ -0,0 +1,81 @@
require "time"
desc "Build the manual"
task :man do
ENV['RONN_MANUAL'] = "Foreman Manual"
ENV['RONN_ORGANIZATION'] = "Foreman #{Foreman::VERSION}"
sh "ronn -w -s toc -r5 --markdown man/*.ronn"
end
desc "Commit the manual to git"
task "man:commit" => :man do
sh "git add README.markdown"
sh "git commit -m 'update readme' || echo 'nothing to commit'"
end
desc "Generate the Github docs"
task :pages => "man:commit" do
sh %{
cp man/foreman.1.html /tmp/foreman.1.html
git checkout gh-pages
rm ./index.html
cp /tmp/foreman.1.html ./index.html
git add -u index.html
git commit -m "saving man page to github docs"
git push origin -f gh-pages
git checkout master
}
end
desc "Generate an authors list"
task :authors do
authors = %x{ git log --pretty=format:"%an" | sort -u }.split("\n")
puts authors.join(", ")
end
def latest_release
latest = File.read("Changelog.md").split("\n").first.split(" ").last
end
def newer_release
release = %x{ git tag --contains #{latest_release} }.split("\n")[1]
end
desc "Generate a Changelog"
task :changelog do
while release = newer_release
entry = %x{ git show --format="%h %cd" #{release} | head -n 1 }
commit, date_raw = entry.split(" ", 2)
date = Time.parse(date_raw).strftime("%Y-%m-%d")
message = "## #{release[1..-1]} #{date} #{commit}\n"
message += %x{ git log --format="%s [%an]" #{latest_release}..#{release} }
changelog = File.read("Changelog.md")
changelog = message + "\n" + changelog
File.open("Changelog.md", "w") do |file|
file.puts changelog
end
end
# date =
# message = "## #{release[1..-1]}
# timestamp = Time.now.utc.strftime('%m/%d/%Y')
# sha = `git log | head -1`.split(' ').last
# changelog = ["#{version} #{timestamp} #{sha}"]
# changelog << ('=' * changelog[0].length)
# changelog << ''
# last_sha = `cat Changelog | head -1`.split(' ').last
# shortlog = `git log #{last_sha}..HEAD --pretty=format:'%s [%an]'`
# changelog << shortlog.split("\n")
# changelog.concat ['', '', '']
# old_changelog = File.read('Changelog')
# File.open('Changelog', 'w') do |file|
# file.write(changelog.join("\n"))
# file.write(old_changelog)
# end
end

8
tasks/rspec.rake Normal file
View File

@@ -0,0 +1,8 @@
require "rspec/core/rake_task"
task :default => :spec
desc "Run all specs"
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/**/*_spec.rb'
end