2019-04-28 21:10:54 +03:00
|
|
|
require "fileutils"
|
|
|
|
require "yaml"
|
|
|
|
require "securerandom"
|
2014-07-28 13:17:48 +03:00
|
|
|
|
|
|
|
namespace :bootstrap do
|
2019-04-28 21:10:54 +03:00
|
|
|
desc "Copy over initial db config"
|
2014-07-28 13:17:48 +03:00
|
|
|
task :db_config do
|
2019-04-28 22:53:49 +03:00
|
|
|
example_config_file = File.join(Rails.root, "config", "database.yml.postgres")
|
2019-04-28 21:10:54 +03:00
|
|
|
new_config_file = File.join(Rails.root, "config", "database.yml")
|
2014-07-28 13:17:48 +03:00
|
|
|
FileUtils.cp example_config_file, new_config_file
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
desc "Generate new secret tokens"
|
2014-07-28 13:17:48 +03:00
|
|
|
task :secret_tokens do
|
2019-04-28 21:10:54 +03:00
|
|
|
secret_tokens_file = File.join Rails.root, "config", "secrets.yml"
|
2014-07-28 13:17:48 +03:00
|
|
|
|
|
|
|
secrets = {
|
2019-04-28 21:10:54 +03:00
|
|
|
"development" => {"secret_key_base" => SecureRandom.hex(64)},
|
|
|
|
"test" => {"secret_key_base" => SecureRandom.hex(64)},
|
|
|
|
"production" => {"secret_key_base" => '<%= ENV["SECRET_KEY_BASE"] %>'},
|
2014-07-28 13:17:48 +03:00
|
|
|
}
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
File.open(secret_tokens_file, "w") do |f|
|
2014-07-28 13:17:48 +03:00
|
|
|
f.puts secrets.to_yaml
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
desc "Perform initial setup of the application"
|
|
|
|
task bootstrap: ["bootstrap:secret_tokens",
|
|
|
|
"bootstrap:db_config",
|
|
|
|
"db:create",
|
|
|
|
"db:migrate",
|
|
|
|
"db:test:prepare",]
|