clarion/lib/tasks/bootstrap.rake

35 lines
1.0 KiB
Ruby
Raw Permalink Normal View History

2019-04-28 21:10:54 +03:00
require "fileutils"
require "yaml"
require "securerandom"
namespace :bootstrap do
2019-04-28 21:10:54 +03:00
desc "Copy over initial db config"
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")
FileUtils.cp example_config_file, new_config_file
end
2019-04-28 21:10:54 +03:00
desc "Generate new secret tokens"
task :secret_tokens do
2019-04-28 21:10:54 +03:00
secret_tokens_file = File.join Rails.root, "config", "secrets.yml"
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"] %>'},
}
2019-04-28 21:10:54 +03:00
File.open(secret_tokens_file, "w") do |f|
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",]