o2h 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --drb
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - ree
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ script: rspec spec
7
+ bundler_args: --without darwin development
data/Gemfile ADDED
@@ -0,0 +1,28 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+
8
+ gem 'guard'
9
+ gem 'guard-rspec'
10
+ gem 'guard-spork'
11
+ gem 'guard-bundler'
12
+
13
+ gem 'ruby-debug', :platforms => :mri_18
14
+ gem 'ruby-debug19', :platforms => :mri_19
15
+ end
16
+
17
+ group :test do
18
+ gem 'spork', '>= 0.9.0.rc9', :require => false
19
+
20
+ gem 'rspec'
21
+
22
+ gem 'capistrano-spec'
23
+ end
24
+
25
+ group :darwin do
26
+ gem 'rb-fsevent'
27
+ gem 'growl_notify'
28
+ end
@@ -0,0 +1,19 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard 'spork' do
7
+ watch('Gemfile')
8
+ watch('Gemfile.lock')
9
+ watch('spec/spec_helper.rb')
10
+ end
11
+
12
+ guard 'rspec', :version => 2 do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/o2h/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
15
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
16
+ watch('spec/spec_helper.rb') { "spec" }
17
+ end
18
+
19
+
@@ -0,0 +1,6 @@
1
+ # o2h deployment recipes
2
+
3
+ [![Build Status](https://secure.travis-ci.org/mikz/o2h.png)](http://travis-ci.org/#!/mikz/o2h)
4
+
5
+ Collection of capistrano recipes and gem dependencies to simplify o2h
6
+ deployment.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,28 @@
1
+ module O2h
2
+ extend self
3
+
4
+ autoload :VERSION, 'o2h/version'
5
+
6
+
7
+ def capistrano(required = :require)
8
+ Capistrano::Configuration.instance(required)
9
+ end
10
+
11
+ def initialize!
12
+ if capistrano(false)
13
+ app_mode
14
+ else
15
+ cap_mode
16
+ end
17
+ end
18
+
19
+ def app_mode
20
+ require 'o2h/recipes'
21
+ end
22
+
23
+ def cap_mode
24
+ require 'newrelic_rpm'
25
+ end
26
+ end
27
+
28
+ O2h.initialize!
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/version'
2
+
3
+ Dir[File.join(File.dirname(__FILE__), 'recipes', '*.rb')].each do |recipe|
4
+ O2h.capistrano.load recipe
5
+ end
@@ -0,0 +1,41 @@
1
+ set :bluepill, "`which system_bluepill`"
2
+
3
+ before "deploy:update", "bluepill:stop"
4
+ after "deploy:update", "bluepill:start"
5
+
6
+ namespace :bluepill do
7
+
8
+ desc "Stop processes that bluepill is monitoring and quit bluepill"
9
+ task :quit, :roles => [:app] do
10
+ sudo "#{fetch(:bluepill)} stop"
11
+ sudo "#{fetch(:bluepill)} quit"
12
+ end
13
+
14
+ desc "Stop processes that bluepill is monitoring"
15
+ task :stop, :roles => [:app] do
16
+ transaction do
17
+ on_rollback { start }
18
+ sudo "#{fetch(:bluepill)} stop; true"
19
+ end
20
+ end
21
+
22
+ desc "Load bluepill configuration and start it"
23
+ task :start, :roles => [:app] do
24
+ app = fetch(:application)
25
+ cmd = []
26
+
27
+ if fetch(:silverlight, false)
28
+ cmd << fetch(:bluepill_silverlight, %{LM_CONTAINER_NAME=background_jobs LM_TAG_NAMES=background_jobs:bluepill:#{app}})
29
+ end
30
+
31
+ cmd << fetch(:bluepill) << 'load' << File.join(current_path, 'config', 'bluepill', "#{rails_env}.pill")
32
+
33
+ sudo cmd.compact.join(" ")
34
+ end
35
+
36
+ desc "Prints bluepills monitored processes statuses"
37
+ task :status, :roles => [:app] do
38
+ sudo "#{fetch(:bluepill)} status"
39
+ end
40
+
41
+ end
@@ -0,0 +1 @@
1
+ require 'bundler/capistrano'
@@ -0,0 +1,11 @@
1
+ set(:domain) { abort "You need to set the :domain variable, e.g set :domain 'www.example.com'" }
2
+ set(:application) { domain.split('.').first } # TODO - find proper 2nd level domain
3
+
4
+ set :use_sudo, false
5
+ set :sudo, 'sudo -n'
6
+ set :sudo_prompt, ''
7
+ set :password, ''
8
+
9
+ default_run_options[:pty] = true
10
+
11
+ ssh_options[:forward_agent] = true
@@ -0,0 +1,64 @@
1
+ namespace :deploy do
2
+
3
+ namespace :db do
4
+
5
+ desc <<-DESC
6
+ Creates the database.yml configuration file in shared path.
7
+
8
+ By default, this task uses a template unless a template \
9
+ called database.yml.erb is found either is :template_dir \
10
+ or /config/deploy folders. The default template matches \
11
+ the template for config/database.yml file shipped with Rails.
12
+
13
+ When this recipe is loaded, db:setup is automatically configured \
14
+ to be invoked after deploy:setup. You can skip this task setting \
15
+ the variable :skip_db_setup to true. This is especially useful \
16
+ if you are using this recipe in combination with \
17
+ capistrano-ext/multistaging to avoid multiple db:setup calls \
18
+ when running deploy:setup for all stages one by one.
19
+ DESC
20
+ task :setup, :except => { :no_release => true } do
21
+
22
+ default_template = <<-EOF
23
+ login: &login
24
+ adapter: postgresql
25
+ username: #{application}
26
+
27
+ production:
28
+ <<: *login
29
+ database: #{application}
30
+
31
+ development:
32
+ <<: *login
33
+ database: #{application}_dev
34
+
35
+ test: &test
36
+ <<: *login
37
+ database: #{application}_test
38
+
39
+ cucumber:
40
+ <<: *test
41
+ EOF
42
+ location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
43
+ template = File.file?(location) ? File.read(location) : default_template
44
+
45
+ config = ERB.new(template)
46
+
47
+ run "mkdir -p #{shared_path}/config"
48
+ put config.result(binding), "#{shared_path}/config/database.yml"
49
+ end
50
+
51
+ desc <<-DESC
52
+ [internal] Updates the symlink for database.yml file to the just deployed release.
53
+ DESC
54
+ task :symlink, :except => { :no_release => true } do
55
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
56
+ end
57
+
58
+ end
59
+
60
+ after "deploy:setup", "deploy:db:setup" unless fetch(:skip_db_setup, false)
61
+ after "deploy:finalize_update", "deploy:db:symlink"
62
+
63
+ end
64
+
@@ -0,0 +1,12 @@
1
+ set(:deploy_to) { "/var/www/#{domain}" }
2
+ set :group, :www
3
+
4
+ after :deploy, 'deploy:set_permissions', :roles => :web
5
+
6
+ namespace :deploy do
7
+ task :set_permissions do
8
+ # Change the owner and group of everything under the
9
+ # deployment directory to webadmin and apache
10
+ try_sudo "chgrp -R #{group} #{deploy_to}"
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ set :scm, :git
2
+ set :branch, :master
3
+
4
+ set :deploy_via, :remote_cache
5
+
6
+ set :git_shallow_clone, true
7
+ set :git_enable_submodules, true
8
+
9
+ set(:repository) { "git.o2h.cz:#{fetch(:application)}" }
@@ -0,0 +1,11 @@
1
+ namespace :deploy do
2
+
3
+ task :start do ; end
4
+ task :stop do ; end
5
+
6
+ desc "Restart Application"
7
+ task :restart, :roles => :app, :except => { :no_release => true } do
8
+ run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
9
+ end
10
+
11
+ end
@@ -0,0 +1,7 @@
1
+ namespace :deploy do
2
+
3
+ task :start do ; end
4
+ task :stop do ; end
5
+ task :restart do ; end
6
+
7
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
2
+ require "rvm/capistrano" # Load RVM's capistrano plugin.
3
+
4
+ set(:rvm_ruby, "ree")
5
+ set(:rvm_gemset) { fetch(:application) }
6
+ set(:rvm_ruby_string) { [fetch(:rvm_ruby), fetch(:rvm_gemset)].compact.join('@') }
@@ -0,0 +1,3 @@
1
+ module O2h
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/o2h/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Michal Cichra"]
6
+ gem.email = ["michal@o2h.cz"]
7
+ gem.description = %q{Collection of recipes and gem dependencies for o2h deployment}
8
+ gem.summary = gem.description
9
+ gem.homepage = "http://o2h.cz"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "o2h"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = O2h::VERSION
17
+
18
+ gem.add_dependency 'newrelic_rpm', '~> 3.3.0'
19
+ gem.add_dependency 'capistrano', '~> 2.9.0'
20
+ gem.add_dependency 'rvm', '~> 1.9.2'
21
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe "bluepill" do
4
+ include_context :capistrano
5
+
6
+ it "should have bluepill tasks" do
7
+ subject.find_task("bluepill:start").should_not be_nil
8
+ end
9
+
10
+ it "performs bluepill:stop before deploy" do
11
+ subject.should callback('bluepill:stop').before('deploy')
12
+ end
13
+
14
+ it "performs bluepill:start after deploy" do
15
+ subject.should callback('bluepill:start').after('deploy')
16
+ end
17
+
18
+ it "should set :bluepill" do
19
+ subject[:bluepill].should_not be_nil
20
+ end
21
+
22
+ context 'configured' do
23
+
24
+ before {
25
+ subject.load 'deploy'
26
+ subject.set :bluepill, "bluepill"
27
+ subject.set :use_sudo, false
28
+ subject.set :sudo_prompt, ''
29
+ subject.set :sudo, 'sudo -n'
30
+ }
31
+
32
+ context "start task" do
33
+
34
+ before {
35
+ subject.set :application, "my-app"
36
+ subject.set :current_path, "current-path"
37
+ subject.set :rails_env, 'my-env'
38
+ }
39
+
40
+ it "runs bluepill command" do
41
+ subject.execute_task(task)
42
+ subject.should have_run("#{subject.sudo} bluepill load current-path/config/bluepill/my-env.pill")
43
+ end
44
+
45
+ it "runs bluepill command in with silverlight env" do
46
+ subject.set :silverlight, true
47
+ subject.execute_task(task)
48
+ env = "LM_CONTAINER_NAME=background_jobs LM_TAG_NAMES=background_jobs:bluepill:#{subject.application}"
49
+ subject.should have_run("#{subject.sudo} #{env} bluepill load current-path/config/bluepill/my-env.pill")
50
+ end
51
+
52
+ end
53
+
54
+ context 'status task' do
55
+ it "runs status command" do
56
+ subject.execute_task(task)
57
+ subject.should have_run("#{subject.sudo} bluepill status")
58
+ end
59
+ end
60
+
61
+ context 'stop task' do
62
+ it "runs status command" do
63
+ subject.execute_task(task)
64
+ subject.should have_run("#{subject.sudo} bluepill stop; true")
65
+ end
66
+ end
67
+
68
+ context 'quit task' do
69
+ it "runs status command" do
70
+ subject.execute_task(task)
71
+ subject.should have_run("#{subject.sudo} bluepill stop")
72
+ subject.should have_run("#{subject.sudo} bluepill quit")
73
+ end
74
+
75
+ it "assings rollback" do
76
+ pending 'no way how to check rollback requests during transaction'
77
+ subject.execute_task(task)
78
+ subject.rollback_requests
79
+ end
80
+ end
81
+
82
+
83
+ end
84
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe "deploy" do
4
+ include_context :capistrano
5
+
6
+ context "domain my-domain.com" do
7
+ before {
8
+ subject.set :domain, 'my-domain.com'
9
+ }
10
+
11
+ its(:deploy_to) { should == '/var/www/my-domain.com' }
12
+ its(:group) { should == :www }
13
+
14
+ it "performs set_permissions after deploy" do
15
+ subject.should callback('deploy:set_permissions').after('deploy')
16
+ end
17
+
18
+ context 'set_permissions task' do
19
+
20
+ it "changes permissions of deploy directory" do
21
+ subject.load 'deploy'
22
+ subject.set :group, 'my-group'
23
+ subject.set :use_sudo, false
24
+ subject.execute_task(task)
25
+ subject.should have_run("chgrp -R my-group #{subject.fetch(:deploy_to)}")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe "git" do
4
+ include_context :capistrano
5
+
6
+ its(:scm) { should == :git }
7
+ its(:branch) { should == :master }
8
+ its(:deploy_via) { should == :remote_cache }
9
+ its(:git_shallow_clone) { should == true }
10
+ its(:git_enable_submodules) { should == true }
11
+
12
+ context 'without application set' do
13
+ it 'call to repository should abort' do
14
+ subject.set(:application) { raise "Not defined" }
15
+ expect { subject[:repository] }.to raise_error("Not defined")
16
+ end
17
+ end
18
+
19
+ context 'with application set' do
20
+ it "should set proper repository" do
21
+ subject.set(:application, 'my-app')
22
+ subject.repository == 'git.o2h.cz:my-app'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ require 'spork'
2
+
3
+ Spork.prefork do
4
+
5
+ require 'rspec'
6
+ require 'pathname'
7
+ require 'capistrano'
8
+
9
+ #Bundler.require :default, :test
10
+
11
+ RSpec.configure do |config|
12
+ # some (optional) config here
13
+ end
14
+
15
+ end
16
+
17
+ Spork.each_run do
18
+
19
+ Dir[Pathname.pwd.join(*%w{spec support ** *.rb}).expand_path].each do |file|
20
+ require file
21
+ end
22
+
23
+ end
@@ -0,0 +1,32 @@
1
+ require 'capistrano'
2
+ require 'capistrano-spec'
3
+
4
+ shared_context :capistrano do
5
+ include Capistrano::Spec::Matchers
6
+
7
+ let(:capistrano) { Capistrano::Configuration.new }
8
+ let(:recipe_name) { self.class.top_level_description }
9
+ let(:recipe_path) { recipe(recipe_name) }
10
+
11
+ let(:task) do
12
+ task = self.class.ancestors.map do |example|
13
+ break $1 if /^(.+?) task$/ =~ example.description
14
+ end
15
+
16
+ if task
17
+ task = "#{recipe_name}:#{task}"
18
+ subject.find_task(task) or raise "Task #{task} not found"
19
+ end
20
+ end
21
+
22
+ subject { capistrano }
23
+
24
+ before do
25
+ capistrano.extend Capistrano::Spec::ConfigurationExtension
26
+ capistrano.load recipe_path
27
+ end
28
+
29
+ def recipe name
30
+ "lib/o2h/recipes/#{name}"
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ require 'o2h/recipes'
2
+
3
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
4
+
5
+ # Uncomment if you are using Rails' asset pipeline
6
+ # load 'deploy/assets'
7
+
8
+ Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
9
+
10
+ load 'config/deploy' # remove this line to skip loading any of the default tasks
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gem 'o2h', :path => '../'
@@ -0,0 +1,19 @@
1
+ set :domain, 'mydomain.cz'
2
+
3
+ server self[:domain], :app, :web, :db, :primary => true
4
+
5
+ # Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
6
+
7
+ role :web, "your web-server here" # Your HTTP server, Apache/etc
8
+ role :app, "your app-server here" # This may be the same as your `Web` server
9
+ role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
10
+ role :db, "your slave db-server here"
11
+
12
+ # if you're still using the script/reaper helper you will need
13
+ # these http://github.com/rails/irs_process_scripts
14
+
15
+ # If you are using Passenger mod_rails uncomment this:
16
+ # namespace :deploy do
17
+ #
18
+ # task :stop do ; end#
19
+ # end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: o2h
3
+ version: !ruby/object:Gem::Version
4
+ hash: 1889055196096400351
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Michal Cichra
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-16 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: newrelic_rpm
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 1510912537727578012
30
+ segments:
31
+ - 3
32
+ - 3
33
+ - 0
34
+ version: 3.3.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: capistrano
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 1156501143490752456
46
+ segments:
47
+ - 2
48
+ - 9
49
+ - 0
50
+ version: 2.9.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rvm
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 2853305934664562034
62
+ segments:
63
+ - 1
64
+ - 9
65
+ - 2
66
+ version: 1.9.2
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: Collection of recipes and gem dependencies for o2h deployment
70
+ email:
71
+ - michal@o2h.cz
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - .gitignore
80
+ - .rspec
81
+ - .travis.yml
82
+ - Gemfile
83
+ - Guardfile
84
+ - README.md
85
+ - Rakefile
86
+ - lib/o2h.rb
87
+ - lib/o2h/recipes.rb
88
+ - lib/o2h/recipes/bluepill.rb
89
+ - lib/o2h/recipes/bundler.rb
90
+ - lib/o2h/recipes/config.rb
91
+ - lib/o2h/recipes/database.rb
92
+ - lib/o2h/recipes/deploy.rb
93
+ - lib/o2h/recipes/git.rb
94
+ - lib/o2h/recipes/host/passenger.rb
95
+ - lib/o2h/recipes/host/static.rb
96
+ - lib/o2h/recipes/rvm.rb
97
+ - lib/o2h/version.rb
98
+ - o2h.gemspec
99
+ - spec/recipes/bluepill_spec.rb
100
+ - spec/recipes/deploy_spec.rb
101
+ - spec/recipes/git_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/support/shared_contexts/capistrano.rb
104
+ - test/Capfile
105
+ - test/Gemfile
106
+ - test/config/deploy.rb
107
+ has_rdoc: true
108
+ homepage: http://o2h.cz
109
+ licenses: []
110
+
111
+ post_install_message:
112
+ rdoc_options: []
113
+
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 2002549777813010636
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 2002549777813010636
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.5.2
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Collection of recipes and gem dependencies for o2h deployment
141
+ test_files:
142
+ - spec/recipes/bluepill_spec.rb
143
+ - spec/recipes/deploy_spec.rb
144
+ - spec/recipes/git_spec.rb
145
+ - spec/spec_helper.rb
146
+ - spec/support/shared_contexts/capistrano.rb
147
+ - test/Capfile
148
+ - test/Gemfile
149
+ - test/config/deploy.rb