o2h 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/o2h.rb CHANGED
@@ -3,26 +3,21 @@ module O2h
3
3
 
4
4
  autoload :VERSION, 'o2h/version'
5
5
 
6
-
7
6
  def capistrano(required = :require)
8
7
  defined?(Capistrano) and Capistrano::Configuration.instance(required)
9
8
  end
10
9
 
11
10
  def initialize!
12
- if capistrano(false)
11
+ # use app mode only when we are not in capistrano
12
+ unless capistrano(false)
13
13
  app_mode
14
- else
15
- cap_mode
16
14
  end
17
15
  end
18
16
 
19
17
  def app_mode
20
- require 'o2h/recipes'
21
- end
22
-
23
- def cap_mode
24
18
  require 'newrelic_rpm'
25
19
  end
20
+
26
21
  end
27
22
 
28
23
  O2h.initialize!
@@ -0,0 +1,4 @@
1
+ require 'capistrano'
2
+
3
+ require 'o2h'
4
+ require 'o2h/recipes'
@@ -0,0 +1,32 @@
1
+ require 'capistrano/recipes/deploy/strategy/remote'
2
+
3
+ module Capistrano
4
+ module Deploy
5
+ module Strategy
6
+
7
+ # Implements the deployment strategy which does an SCM checkout on each
8
+ # target host. This is the default deployment strategy for Capistrano.
9
+ class Git < Remote
10
+ def clone!
11
+ scm_run clone
12
+ end
13
+
14
+ def deploy!
15
+ scm_run sync
16
+ end
17
+
18
+ protected
19
+
20
+ def clone
21
+ @clone ||= source.checkout(revision, configuration[:release_path])
22
+ end
23
+
24
+ # Returns the SCM's checkout command for the revision to deploy.
25
+ def sync
26
+ @sync ||= source.sync(revision, configuration[:release_path])
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
data/lib/o2h/recipes.rb CHANGED
@@ -1,5 +1,17 @@
1
1
  require File.dirname(__FILE__) + '/version'
2
2
 
3
+ def rake_task(taskname)
4
+ rake = fetch(:rake, "rake")
5
+ rake_env = fetch(:rake_env, "")
6
+ in_rails_root("#{rake} #{rake_env} #{taskname}")
7
+ end
8
+
9
+ def in_rails_root(taskname)
10
+ rails_env = fetch(:rails_env, "production")
11
+ directory = current_release
12
+ run %{cd #{directory}; RAILS_ENV=#{rails_env} #{taskname}}
13
+ end
14
+
3
15
  Dir[File.join(File.dirname(__FILE__), 'recipes', '*.rb')].each do |recipe|
4
16
  O2h.capistrano.load recipe
5
17
  end
@@ -1,11 +1,12 @@
1
1
  set(:domain) { abort "You need to set the :domain variable, e.g set :domain 'www.example.com'" }
2
2
  set(:application) { domain.split('.').first } # TODO - find proper 2nd level domain
3
3
 
4
+ set :user, 'deployer'
5
+ set :group, 'www'
4
6
  set :use_sudo, false
5
7
  set :sudo, 'sudo -n'
6
8
  set :sudo_prompt, ''
7
9
  set :password, ''
8
10
 
9
- default_run_options[:pty] = true
10
-
11
11
  ssh_options[:forward_agent] = true
12
+
@@ -0,0 +1,5 @@
1
+ namespace :copycopter do
2
+ task :deploy do
3
+ run_locally "rake copycopter:deploy"
4
+ end
5
+ end
@@ -1,7 +1,20 @@
1
+ set(:strategy) do
2
+ require 'o2h/capistrano/deploy/strategy/git'
3
+ Capistrano::Deploy::Strategy::Git.new(self)
4
+ end
5
+
1
6
  set(:deploy_to) { "/var/www/#{domain}" }
2
7
  set :group, :www
3
8
 
4
- after :deploy, 'deploy:set_permissions', :roles => :web
9
+ set(:latest_release) { fetch(:current_path) }
10
+ set(:release_path) { fetch(:current_path) }
11
+ set(:current_release) { fetch(:current_path) }
12
+
13
+ set(:current_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
14
+ set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
15
+ set(:previous_revision) { capture("cd #{current_path}; git rev-parse --short HEAD@{1}").strip }
16
+
17
+ #after :'deploy:update_code', :'deploy:set_permissions', :roles => :web
5
18
 
6
19
  namespace :deploy do
7
20
  task :set_permissions do
@@ -9,4 +22,67 @@ namespace :deploy do
9
22
  # deployment directory to webadmin and apache
10
23
  try_sudo "chgrp -R #{group} #{deploy_to}"
11
24
  end
25
+
26
+ desc find_task(:default).description
27
+ task :default do
28
+ update
29
+ restart
30
+ end
31
+
32
+ desc find_task(:setup).description
33
+ task :setup, :except => { :no_release => true } do
34
+ dirs = [deploy_to, shared_path]
35
+ dirs += shared_children.map { |d| File.join(shared_path, d) }
36
+ run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
37
+ strategy.clone!
38
+ end
39
+
40
+ desc find_task(:cold).description
41
+ task :cold do
42
+ update
43
+ migrate
44
+ start
45
+ end
46
+
47
+ desc "Resets to HEAD of branch"
48
+ task :update do
49
+ transaction do
50
+ update_code
51
+ end
52
+ end
53
+
54
+ desc find_task(:update_code).description
55
+ task :update_code, :except => { :no_release => true } do
56
+ strategy.deploy!
57
+ finalize_update
58
+ end
59
+
60
+ desc find_task(:migrations).description
61
+ task :migrations do
62
+ set :migrate_target, :latest
63
+ update
64
+ migrate
65
+ restart
66
+ end
67
+
68
+ task :celanup do
69
+ nil
70
+ end
71
+
72
+ task :symlink do
73
+ nil
74
+ end
75
+
76
+ namespace :rollback do
77
+ desc "Moves the repo back to the previous version of HEAD"
78
+ task :revision, :except => { :no_release => true } do
79
+ set :branch, "HEAD@{1}"
80
+ deploy.update_code
81
+ end
82
+
83
+ desc "Rewrite reflog so HEAD@{1} will continue to point to at the next previous release."
84
+ task :cleanup, :except => { :no_release => true } do
85
+ run "cd #{current_path}; git reflog delete --rewrite HEAD@{1}; git reflog delete --rewrite HEAD@{1}"
86
+ end
87
+ end
12
88
  end
@@ -1,9 +1,10 @@
1
1
  set :scm, :git
2
2
  set :branch, :master
3
3
 
4
- set :deploy_via, :remote_cache
4
+ set :migrate_target, :current
5
+ set :deploy_via, :remote_git
5
6
 
6
- set :git_shallow_clone, true
7
+ #set :git_shallow_clone, true
7
8
  set :git_enable_submodules, true
8
9
 
9
10
  set(:repository) { "git.o2h.cz:#{fetch(:application)}" }
@@ -0,0 +1,16 @@
1
+ namespace :deploy do
2
+ desc "Zero-downtime restart of Unicorn"
3
+ task :restart, :except => { :no_release => true } do
4
+ run "kill -s USR2 `cat /tmp/unicorn.my_site.pid`"
5
+ end
6
+
7
+ desc "Start unicorn"
8
+ task :start, :except => { :no_release => true } do
9
+ run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D"
10
+ end
11
+
12
+ desc "Stop unicorn"
13
+ task :stop, :except => { :no_release => true } do
14
+ run "kill -s QUIT `cat /tmp/unicorn.my_site.pid`"
15
+ end
16
+ end
data/lib/o2h/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module O2h
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -79,6 +79,5 @@ describe "bluepill" do
79
79
  end
80
80
  end
81
81
 
82
-
83
82
  end
84
83
  end
@@ -27,6 +27,8 @@ shared_context :capistrano do
27
27
  end
28
28
 
29
29
  def recipe name
30
- "lib/o2h/recipes/#{name}"
30
+ Dir["lib/o2h/recipes/**/*.rb"].find do |recipe|
31
+ File.basename(recipe, '.rb') == name
32
+ end
31
33
  end
32
34
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: o2h
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michal Cichra
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-11-16 00:00:00 Z
13
+ date: 2011-12-05 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: newrelic_rpm
@@ -63,15 +63,19 @@ files:
63
63
  - README.md
64
64
  - Rakefile
65
65
  - lib/o2h.rb
66
+ - lib/o2h/capistrano.rb
67
+ - lib/o2h/capistrano/deploy/strategy/git.rb
66
68
  - lib/o2h/recipes.rb
67
69
  - lib/o2h/recipes/bundler.rb
68
70
  - lib/o2h/recipes/config.rb
71
+ - lib/o2h/recipes/copycopter.rb
69
72
  - lib/o2h/recipes/database.rb
70
73
  - lib/o2h/recipes/deploy.rb
71
74
  - lib/o2h/recipes/git.rb
72
75
  - lib/o2h/recipes/host/bluepill.rb
73
76
  - lib/o2h/recipes/host/passenger.rb
74
77
  - lib/o2h/recipes/host/static.rb
78
+ - lib/o2h/recipes/host/unicorn.rb
75
79
  - lib/o2h/recipes/rvm.rb
76
80
  - lib/o2h/version.rb
77
81
  - o2h.gemspec
@@ -106,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
110
  requirements: []
107
111
 
108
112
  rubyforge_project:
109
- rubygems_version: 1.8.5
113
+ rubygems_version: 1.8.11
110
114
  signing_key:
111
115
  specification_version: 3
112
116
  summary: Collection of recipes and gem dependencies for o2h deployment
@@ -119,3 +123,4 @@ test_files:
119
123
  - test/Capfile
120
124
  - test/Gemfile
121
125
  - test/config/deploy.rb
126
+ has_rdoc: