shayarnett (owner)

Revisions

gist: 180365 Download_button fork
public
Public Clone URL: git://gist.github.com/180365.git
Embed All Files: show embed
deploy.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
set :application, "example.com"
set :deploy_to, "/var/www/#{application}"
 
role :app, "example.com"
role :web, "example.com"
role :db, "example.com", :primary => true
 
set :scm, :git
set :repository, "ssh://shay@example.com/git/example.com"
set :branch, "origin/master"
 
namespace :deploy do
  desc "Deploy app"
  task :default do
    update
    restart
    cleanup
  end
 
  desc "Setup a GitHub-style deployment."
  task :setup, :except => { :no_release => true } do
    run "git clone #{repository} #{current_path}"
  end
 
  desc "Update the deployed code."
  task :update_code, :except => { :no_release => true } do
    run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"
  end
 
  desc "Deploy and run migrations"
  task :migrations, :except => { :no_release => true } do
    update
    migrate
    restart
    cleanup
  end
 
  desc "Run pending migrations on already deployed code"
  task :migrate, :except => { :no_release => true } do
    run "cd #{current_path}; rake RAILS_ENV=production db:migrate"
  end
 
  namespace :rollback do
    desc "Rollback"
    task :default do
      code
    end
    
    desc "Rollback a single commit."
    task :code, :except => { :no_release => true } do
      set :branch, "HEAD^"
      default
    end
  end
    
  desc "Make all the symlinks"
  task :symlink, :roles => :app, :except => { :no_release => true } do
    set :normal_symlinks, %w(
public/system
config/database.yml
)
    commands = normal_symlinks.map do |path|
      "rm -rf #{current_path}/#{path} && \
ln -s #{shared_path}/#{path} #{current_path}/#{path}"
    end
    
    # set :weird_symlinks, {
    # "path_on_disk" => "path_to_symlink"
    # }
    # commands += weird_symlinks.map do |from, to|
    # "rm -rf #{current_path}/#{to} && \
    # ln -s #{shared_path}/#{from} #{current_path}/#{to}"
    # end
 
    # needed for some of the symlinks
    run "mkdir -p #{current_path}/tmp && \
mkdir -p #{current_path}/public/system && \
mkdir -p #{current_path}/config"
 
    run <<-CMD
cd #{current_path} &&
#{commands.join(" && ")}
CMD
  end
  
  # override default tasks to make capistrano happy
  desc "Kick Passenger"
  task :start do
    run "touch #{current_path}/tmp/restart.txt"
  end
 
  desc "Kick Passenger"
  task :restart do
    stop
    start
  end
 
  desc "Kick Passenger"
  task :stop do
  end
end