forked from synbioz/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.rb
257 lines (207 loc) · 6.17 KB
/
template.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
require 'etc'
GITHUB_BASE_URL = "https://raw.githubusercontent.com/jobygoude/rails-template/master".freeze
RUBY_VERSION = "2.2.0".freeze
username = Etc.getlogin
# create .rbenv file
create_file ".ruby-version", RUBY_VERSION
# add gems
gem 'pg'
gem 'slim-rails'
if yes?("Do you want to use devise ?")
gem 'devise'
gem 'devise-i18n'
# setup devise
generate "devise:install"
generate "devise User"
generate "devise:views"
end
%w(whenever kaminari cancan).each do |g|
gem g if yes?("Do you need #{g} ?")
end
if yes?("Do you need mootools?")
gem 'mootools-rails'
elsif yes?("Do you need jquery?")
if yes?("Do you need jquery-ui ?")
gem 'jquery-ui-rails'
end
end
if yes?("Do you want to use rspec instead of minitest ?")
gem_group :test do
gem 'rspec-rails'
gem 'spork-rails'
gem 'guard-spork'
gem 'guard-rspec'
gem 'shoulda-matchers'
end
else
gem_group :test do
gem 'minitest-spec-rails'
gem 'guard-minitest'
gem 'turn'
end
run "guard init minitest"
environment "config.minitest_spec_rails.mini_shoulda = true", env: "test"
# Add require and config for minitest
insert_into_file 'test/test_helper.rb', "require 'turn/autorun'", :after => "require 'rails/test_help'\n"
insert_into_file 'test/test_helper.rb', "Turn.config.format = :progress\n\n", :after => "require 'turn/autorun'\n"
end
gem 'puma'
gem 'hipchat'
gem 'airbrake'
gem 'capistrano', '~> 3.2.0', require: false
gem 'capistrano-rbenv', '~> 2.0', require: false
gem 'capistrano-bundler', '~> 1.1.2', require: false
gem 'capistrano-rails', '~> 1.1.1', require: false
gem 'capistrano3-puma', require: false
gem 'rack-cache', :require => 'rack/cache'
gem "capistrano-redmine", :git => "https://github.com/synbioz/capistrano-redmine.git", require: false
gem_group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'awesome_print'
gem 'pry-rails'
gem 'debugger2'
gem 'ruby-prof'
end
gem_group :doc do
gem 'yard'
gem 'rails-erd'
end
# install gems
run 'bundle install --without=production'
run 'bundle exec cap install'
run 'mkdir config/deploy'
# edit database config file
remove_file 'config/database.yml'
file 'config/database.yml', <<-END
development:
adapter: postgresql
database: #{app_name}_development
host: localhost
username: #{username}
password:
encoding: utf8
test:
adapter: postgresql
database: #{app_name}_test
host: localhost
username: #{username}
password:
encoding: utf8
END
remove_file 'README.rdoc'
file 'README.md', <<-END
# README
## TODO
- Complete puma configuration
- Complete capistrano configuration
- Complete redmine configuration (deploy/staging.rb)
- You may have to change lock version in deploy.rb
END
rake "db:create"
environment "config.action_mailer.default_url_options = {host: 'http://localhost:3000'}", env: 'development'
rake "db:create"
# remove defaults files
remove_file 'public/index.html'
remove_file 'app/assets/images/rails.png'
# copy database.yml file
run 'cp config/database.yml config/database.example.yml'
# add database.yml to .gitignore
run "echo 'config/database.yml' >> .gitignore"
run "echo 'vendor/bundle' >> .gitignore"
# copy default rake tasks
run "mkdir -p lib/capistrano/tasks"
get "#{GITHUB_BASE_URL}/capistrano/tasks/no-robot.rake", "lib/capistrano/tasks/no-robot.rake"
get "#{GITHUB_BASE_URL}/capistrano/tasks/version.rake", "lib/capistrano/tasks/version.rake"
get "#{GITHUB_BASE_URL}/capistrano/tasks/remote.rake", "lib/capistrano/tasks/remote.rake"
# copy puma configuration
run "mkdir -p config/puma"
get "#{GITHUB_BASE_URL}/config/puma/production.rb", "config/puma/production.rb"
get "#{GITHUB_BASE_URL}/config/puma/staging.rb", "config/puma/staging.rb"
remove_file 'config/deploy/staging.rb'
file 'config/deploy/staging.rb', <<-END
server '', user: 'synbioz', roles: %w{web app db}
set :rails_env, 'staging'
set :branch, 'develop'
set :redmine_site, "https://redmine.site"
set :redmine_token, "token_utilisateur"
set :redmine_options, { ssl: { cert: nil, key: nil } }
set :redmine_projects, "mon_project"
# resolved
set :redmine_from_status, 3
# deployed
set :redmine_to_status, 7
after 'deploy', 'copy_no_robots_file'
after "deploy", "redmine:update"
END
remove_file 'config/deploy.rb'
file 'config/deploy.rb', <<-END
lock '3.2.0'
set :user, "synbioz"
set :application, ''
set :repo_url, ''
set :deploy_to, ''
set :log_level, :debug
set :pty, false
set :ssh_options, { forward_agent: true }
set :linked_files, %w{
config/database.yml
config/secrets.yml
}
set :linked_dirs, %w{
log
tmp/pids
tmp/cache
tmp/sockets
vendor/bundle
public/system
}
set :default_env, { path: "~/.rbenv/bin:~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH" }
set :bundle_flags, "--quiet"
set :rbenv_type, :user
set :rbenv_ruby, "#{RUBY_VERSION}"
set :puma_conf, -> { File.join(release_path, 'config', 'puma', fetch(:stage) + '.rb') }
# Do not perform the puma's check task because the config file
# is in the source tree. The check method will try to upload
# a config file but will never succeed.
Rake::Task['puma:check'].clear
set :hipchat_token, ""
set :hipchat_room_name, ""
set :hipchat_announce, false
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
Rake::Task["puma:restart"].invoke
end
end
after :publishing, :restart
desc 'Runs rake db:seed'
task :seed => [:set_rails_env] do
on primary fetch(:migration_role) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "db:seed"
end
end
end
end
after :migrate, :seed
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
end
end
end
after "deploy", "deploy:generate_version"
after "deploy:finished", "airbrake:deploy"
END
# Get latest fr.yml from github
get "https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/fr.yml", "config/locales/fr.yml"
# Sets some default config per env
environment "config.i18n.default_locale = :fr"
environment "config.time_zone = 'Paris'"
# setup git and git-flow then initial commit
git :init
git flow: "init"
git add: "."
git commit: "-a -m 'Initial commit'"