mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Rake task to migrate config.yml to a dotenv file
This commit is contained in:
parent
14a9d701f7
commit
78501b17ca
1 changed files with 41 additions and 0 deletions
41
lib/tasks/migrate_config.rake
Normal file
41
lib/tasks/migrate_config.rake
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
namespace :data do
|
||||
namespace :migrate do
|
||||
desc 'Create a dotenv file from config/config.yml'
|
||||
task config2dotenv: :environment do
|
||||
# Create the dotenv file
|
||||
dot_env = Rails.root.join(".env.#{Rails.env}")
|
||||
if File.exist?(dot_env)
|
||||
abort("Sorry can't migrate, #{dot_env} already exists")
|
||||
else
|
||||
dot_env = File.open(dot_env, 'w')
|
||||
end
|
||||
|
||||
# Load the configuration file
|
||||
config_yml = Rails.root.join('config', 'config.yml')
|
||||
begin
|
||||
CONFIG = YAML.load_file(config_yml)[Rails.env]
|
||||
rescue
|
||||
CONFIG = {}
|
||||
end
|
||||
|
||||
# Write the dotenv file
|
||||
dot_env.puts '# OSEM environment variables. Check INSTALL.md for more information'
|
||||
dot_env.puts "OSEM_NAME=\"#{CONFIG['name']}\""
|
||||
dot_env.puts "OSEM_HOSTNAME=\"#{CONFIG['url_for_emails']}\""
|
||||
dot_env.puts "OSEM_EMAIL_ADDRESS=\"#{CONFIG['sender_for_emails']}\""
|
||||
dot_env.puts "OSEM_ICHAIN_ENABLED=\"#{CONFIG['authentication']['ichain']['enabled']}\"" if CONFIG.has_key?(:authentication)
|
||||
dot_env.puts "OSEM_TRANSIFEX_APIKEY=\"#{CONFIG['transifex_live_api_key']}\""
|
||||
dot_env.puts "OSEM_ERRBIT_HOST=\"#{CONFIG['errbit_host']}\""
|
||||
dot_env.puts "OSEM_FACTORY_LINT=\"#{CONFIG['factory_girl_lint']}\""
|
||||
dot_env.puts "OSEM_SMTP_ADDRESS=\"#{CONFIG['mail_address']}\""
|
||||
dot_env.puts "OSEM_SMTP_PORT=\"#{CONFIG['mail_port']}\""
|
||||
dot_env.puts "OSEM_SMTP_USERNAME=\"#{CONFIG['mail_username']}\""
|
||||
dot_env.puts "OSEM_SMTP_PASSWORD=\"#{CONFIG['mail_password']}\""
|
||||
dot_env.puts "OSEM_SMTP_AUTHENTICATION=\"#{CONFIG['mail_authentication']}\""
|
||||
dot_env.puts 'OSEM_SMTP_DOMAIN=""'
|
||||
dot_env.close
|
||||
|
||||
puts "Migrated config/config.yml to .env.#{Rails.env}"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue