This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
/
deploy.example.rb
98 lines (81 loc) · 3.04 KB
/
deploy.example.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
set :application, "watchdog"
set :use_sudo, false
set :repository, "git://github.com/vigetlabs/watch-dog.git"
set :scm, :git
set :ssh_options, {:forward_agent => true}
set :branch, 'origin/master'
set :user, "watchdog-deploy"
set :deploy_to, "/var/www/#{application}"
set :rake, "/usr/local/bin/rake"
set(:latest_release) { fetch(:current_path) }
set(:release_path) { fetch(:current_path) }
set(:current_release) { fetch(:current_path) }
set(:current_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
set(:previous_revision) { capture("cd #{current_path}; git rev-parse --short HEAD@{1}").strip }
set(:moinitrc_path) { File.join(shared_path, 'monitrc') }
default_run_options[:shell] = 'bash'
default_environment["RACK_ENV"] = 'production'
role :web, "your.server.com"
role :app, "your.server.com"
role :db, "your.server.com", :primary => true
after "deploy:update_code", "app:symlinks"
namespace :deploy do
desc "Deploy"
task :default do
update
restart
end
desc "Setup a GitHub-style deployment."
task :setup, :except => { :no_release => true } do
dirs = [deploy_to, shared_path]
dirs += shared_children.map { |d| File.join(shared_path, d) }
dirs += [File.join(moinitrc_path, 'development'), File.join(moinitrc_path, 'test'), File.join(moinitrc_path, 'production')]
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
run "git clone #{repository} #{current_path}"
end
task :update do
transaction do
update_code
end
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}"
finalize_update
end
desc "Restart the application"
task :restart, :except => { :no_release => true } do
run "cd #{current_path}; touch tmp/restart.txt"
end
desc "Run the database migrations"
task :migrations, :except => { :no_release => true } do
update_code
run "cd #{current_path}; #{rake} RACK_ENV=production db:migrate"
restart
end
namespace :rollback do
desc "Moves the repo back to the previous version of HEAD"
task :repo, :except => { :no_release => true } do
set :branch, "HEAD@{1}"
deploy.default
end
desc "Rewrite reflog so HEAD@{1} will continue to point to at the next previous release."
task :cleanup, :except => { :no_release => true } do
run "cd #{current_path}; git reflog delete --rewrite HEAD@{1}; git reflog delete --rewrite HEAD@{1}"
end
desc "Rolls back to the previously deployed version."
task :default do
rollback.repo
rollback.cleanup
end
end
end
namespace :app do
desc "Make symlinks"
task :symlinks do
run "ln -nfs #{shared_path}/monitrc #{current_path}/"
run "ln -nfs #{shared_path}/config/database.yml #{current_path}/config/database.yml"
run "ln -nfs #{shared_path}/config/settings.yml #{current_path}/config/settings.yml"
end
end