Create a task for easily bootstrapping a project

This commit is contained in:
Petko Bordjukov 2014-07-28 13:17:48 +03:00
parent 45270b5c11
commit 857ff1a7a1
1 changed files with 34 additions and 0 deletions

34
lib/tasks/bootstrap.rake Normal file
View File

@ -0,0 +1,34 @@
require 'fileutils'
require 'yaml'
require 'securerandom'
namespace :bootstrap do
desc 'Copy over initial db config'
task :db_config do
example_config_file = File.join(Rails.root, 'config', 'database.yml.example')
new_config_file = File.join(Rails.root, 'config', 'database.yml')
FileUtils.cp example_config_file, new_config_file
end
desc 'Generate new secret tokens'
task :secret_tokens do
secret_tokens_file = File.join Rails.root, 'config', 'secrets.yml'
secrets = {
'development' => {'secret_key_base' => SecureRandom.hex(64)},
'test' => {'secret_key_base' => SecureRandom.hex(64)},
'production' => {'secret_key_base' => '<%= ENV["SECRET_KEY_BASE"] %>'}
}
File.open(secret_tokens_file, 'w') do |f|
f.puts secrets.to_yaml
end
end
end
desc 'Perform initial setup of the application'
task bootstrap: ['bootstrap:secret_tokens',
'bootstrap:db_config',
'db:create',
'db:migrate',
'db:test:prepare']