-
Notifications
You must be signed in to change notification settings - Fork 0
/
rails4.rb
155 lines (122 loc) · 3.56 KB
/
rails4.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
inject_into_file 'Gemfile', after: %(source 'https://rubygems.org'\n) do <<-'STR'
ruby '2.0.0'
STR
end
gem 'haml-rails'
gem 'unicorn'
gem 'draper'
gem 'newrelic_rpm'
gem 'lograge'
gem 'rack-timeout'
gem 'rails_12factor', group: :production
gem 'rspec-rails', :group => [:test, :development]
gem_group :test do
gem "activerecord-nulldb-adapter"
end
run "bundle install"
application <<-GENERATORS
config.generators do |g|
g.template_engine :haml
g.test_framework :rspec, :fixture => true, :views => false
g.integration_tool :rspec, :fixture => true, :views => true
g.fixture_replacement :factory_girl, :dir => "spec/support/factories"
end
GENERATORS
generate "rspec:install"
inside("app/views/layouts") do
run "rm application.html.erb"
create_file "application.html.haml", <<-APPLICATION_STR
!!!
%html
%head
%title= @page_title
%meta{:charset => 'UTF-8'}
%meta{:name => 'description', :content => @meta_decription}
= stylesheet_link_tag 'application'
= javascript_include_tag 'application'
%body
#main{role: 'main'}
.container
= yield
%footer#footer
.container
APPLICATION_STR
end
create_file 'config/unicorn.rb', <<-UNICORN
# https://devcenter.heroku.com/articles/rails-unicorn
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout Integer(ENV["UNICORN_TIMEOUT"] || 15)
preload_app true
# https://devcenter.heroku.com/articles/forked-pg-connections
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
UNICORN
create_file 'Procfile', <<-PROCFILE
web: bundle exec unicorn -p $PORT -c config/unicorn.rb
PROCFILE
initializer 'timeout.rb', <<-TIMEOUT_STR
Rack::Timeout.timeout = Integer(ENV["RACK_TIMEOUT"] || 10)
# Don't log to stdout in test env. Very noisy.
if Rails.env.test?
Rack::Timeout.unregister_state_change_observer(:logger)
end
TIMEOUT_STR
inject_into_file 'app/controllers/application_controller.rb', after: " protect_from_forgery with: :exception\n" do <<-CONTROLLER_STR
# https://github.com/roidrage/lograge/issues/23
# http://apidock.com/rails/v3.2.8/ActionController/Instrumentation/append_info_to_payload
def append_info_to_payload(payload)
super
payload[:request_id] = request.env['HTTP_HEROKU_REQUEST_ID']
end
CONTROLLER_STR
end
application(nil, env: "production") do
%( # https://github.com/roidrage/lograge
config.lograge.enabled = true
config.lograge.custom_options = lambda do |event|
{
user: event.payload[:user],
request_id: event.payload[:request_id]
}
end)
end
run 'createuser --superuser rails'
remove_file 'config/database.yml'
create_file 'config/database.yml', <<-DB_TXT
development:
adapter: postgresql
encoding: unicode
database: #{app_name}_development
pool: 5
username: rails
password:
test:
adapter: postgresql
encoding: unicode
database: #{app_name}_test
pool: 5
username: rails
password:
DB_TXT
rake 'db:create'
get 'https://gist.github.com/rwdaigle/2253296/raw/newrelic.yml', 'config/newrelic.yml'
append_file 'public/robots.txt', <<-ROBOTS_TXT
User-agent: *
Allow: /
ROBOTS_TXT
route %(get '/__heartbeat__' => proc { |env| [200, {}, ["OK"]] })
git :init
say "#{app_const} Generated!"