This repository has been archived by the owner on Jul 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrails.rb
100 lines (83 loc) · 2.84 KB
/
rails.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
dep "setup-rails-app", :domain, :domain_aliases, :username, :path, :listen_host, :listen_port, :proxy_host, :proxy_port, :env, :nginx_prefix, :enable_http, :enable_https, :force_https, :data_required do
requires "benhoskings:rails app".with(domain, domain_aliases, username, path, listen_host, listen_port, proxy_host, proxy_port, env, nginx_prefix, enable_http, enable_https, force_https, data_required),
"setup-ssl-vhost.nginx".with(domain, path, listen_host, listen_port, nginx_prefix),
"rails-app.logrotate".with(username),
"setup-bluepill".with(username),
"delayed_job.bluepill".with(username, env),
"unicorn.bluepill".with(username, env)
end
dep "migrate-db.task", :root, :env do
run {
cd(root) {
shell "bundle exec rake db:migrate RAILS_ENV=#{env}"
}
}
end
dep "regenerate-assets.task", :root, :env do
run {
cd(root) {
shell "bundle exec rake assets:precompile RAILS_ENV=#{env}"
}
}
end
dep "expire-all-fragments.task", :root, :env do
run {
cd(root) {
shell "bundle exec rake cleanup:expire_fragments RAILS_ENV=#{env}"
}
}
end
dep "restart-delayed-job", :root, :env do
met? {
cd(root) {
pid = "tmp/pids/delayed_job.pid".p.read
@old_pid && !pid.blank? && pid != @old_pid
}
}
meet {
cd(root) {
@old_pid = "tmp/pids/delayed_job.pid".p.read
log_shell "Restarting delayed job",
"/usr/bin/env RAILS_ENV=#{env} bundle exec script/delayed_job restart"
}
}
end
dep "update-crontab.task", :root, :env do
run {
cd(root) {
shell "bundle exec whenever -w -s 'environment=#{env}'"
}
}
end
dep "stop-bluepill.task", :username do
username.default!(shell('whoami'))
run {
Dir[File.join(File.expand_path("~#{username}/pills"), "*.pill")].each do |path|
shell "bluepill #{username}-#{File.basename(path, ".pill")} quit --no-privileged"
end
}
end
dep "start-bluepill.task", :username do
username.default!(shell('whoami'))
run {
Dir[File.join(File.expand_path("~#{username}/pills"), "*.pill")].each do |path|
shell "bluepill load #{path} --no-privileged"
end
}
end
dep "bundle app" do
shell "bundle"
end
dep "create app dbs", :app_name, :number_of_test_dbs, :new_password do
create_db = "CREATE DATABASE IF NOT EXISTS"
log_shell "Create development DB",
"mysql -u root --password=#{new_password} -e '#{create_db} #{app_name}_development'"
"#{number_of_test_dbs}".to_i.times do |i|
index = i + 1
index_to_append = (index == 1 ? "" : index.to_s)
log_shell "Create test DB #{index}",
"mysql -u root --password=#{new_password} -e '#{create_db} #{app_name}_test#{index_to_append}'"
log_shell "Create cucumber DB #{index}",
"mysql -u root --password=#{new_password} -e '#{create_db} #{app_name}_cucumber#{index_to_append}'"
end
end