From 857ff1a7a16480df3013a7ec06dcfba318be5231 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Mon, 28 Jul 2014 13:17:48 +0300 Subject: [PATCH] Create a task for easily bootstrapping a project --- lib/tasks/bootstrap.rake | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/tasks/bootstrap.rake diff --git a/lib/tasks/bootstrap.rake b/lib/tasks/bootstrap.rake new file mode 100644 index 0000000..94ae034 --- /dev/null +++ b/lib/tasks/bootstrap.rake @@ -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']