Skip to content

Commit

Permalink
Load configurations from env files instead of setup_conf.yml
Browse files Browse the repository at this point in the history
First step in reorganizing the configuration files.
Now seeds.yml is used to set information used when seeding the db, .env
files are used for configurations loaded every time the application
starts and configatron is soon to be removed.
  • Loading branch information
daronco committed Mar 3, 2017
1 parent 450c4d6 commit b4211af
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 174 deletions.
11 changes: 11 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Database configurations
MCONF_DATABASE_DEV_ADAPTER='mysql2'
MCONF_DATABASE_DEV='mconf_web_dev'
MCONF_DATABASE_DEV_USERNAME='root'
MCONF_DATABASE_DEV_PASSWORD=''

# Scope for all URLs related to conferences
MCONF_CONFERENCE_SCOPE='nothing'

# Scope for the short URLs of web conference rooms
MCONF_CONFERENCE_SCOPE_ROOMS='lol'
4 changes: 4 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MCONF_DATABASE_PROD_ADAPTER='mysql2'
MCONF_DATABASE_PROD='mconf_web_production'
MCONF_DATABASE_PROD_USERNAME='root'
MCONF_DATABASE_PROD_PASSWORD=''
4 changes: 4 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MCONF_DATABASE_TEST_ADAPTER='mysql2'
MCONF_DATABASE_TEST='mconf_web_test'
MCONF_DATABASE_TEST_USERNAME='root'
MCONF_DATABASE_TEST_PASSWORD=''
4 changes: 4 additions & 0 deletions .env.travis
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MCONF_DATABASE_ADAPTER='mysql2'
MCONF_DATABASE='mconf_test'
MCONF_DATABASE_USERNAME='travis'
MCONF_DATABASE_PASSWORD=''
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ private/uploads/*
app/assets/images/tmp/*
public/images/tmp/*
*~
config/setup_conf.yml
config/deploy/conf.yml
db/*.sqlite3*
tmp/*
Expand All @@ -22,3 +21,6 @@ public/uploads/*
public/capybara.html
.vagrant/
cookbooks/
.env.development.local
.env.test.local
.env.production.local
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
- redis-server
bundler_args: "--without production development"
before_script:
- "cp config/database.yml.travis config/database.yml"
- "cp config/.env.travis config/.env.test"
- "mysql -e 'create database mconf_test;'"
- "cp config/setup_conf.yml.example config/setup_conf.yml"
script: bundle exec rake
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ gem 'mini_magick', '~> 3.8.1'

# global configurations
gem 'configatron', '~> 2.13.0'
gem 'dotenv-rails'

# for bootstrap
gem 'bootstrap-sass', '~> 3.3'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ GEM
devise (>= 2.1.0)
diff-lcs (1.2.5)
docile (1.1.5)
dotenv (2.2.0)
dotenv-rails (2.2.0)
dotenv (= 2.2.0)
railties (>= 3.2, < 5.1)
dotiw (2.0)
actionpack (>= 3)
i18n
Expand Down Expand Up @@ -568,6 +572,7 @@ DEPENDENCIES
devise (~> 3.5.4)
devise-async
devise-encryptable
dotenv-rails
dotiw
epic-editor-rails
exception_notification (~> 4.0.0)
Expand Down
1 change: 0 additions & 1 deletion config/.gitignore

This file was deleted.

36 changes: 5 additions & 31 deletions config/configatron/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,10 @@
# This file is licensed under the Affero General Public License version
# 3 or later. See the LICENSE file.

# Put all your default configatron settings here.

# Example:
# configatron.emails.welcome.subject = 'Welcome!'
# configatron.emails.sales_reciept.subject = 'Thanks for your order'
#
# configatron.file.storage = :s3

# Make sure the config file exists and load it
CONFIG_FILE = File.join(::Rails.root, "config", "setup_conf.yml")
unless File.exists? CONFIG_FILE
puts
puts "ERROR"
puts "The configuration file does not exist!"
puts "Path: #{CONFIG_FILE}"
puts
exit
end

# Load the configuration file into configatron
full_config = YAML.load_file(CONFIG_FILE)
config = full_config["default"]
config_env = full_config[Rails.env]
config.merge!(config_env) unless config_env.nil?
configatron.configure_from_hash(config)

# Defaults for redis
configatron.redis.host = 'localhost' if configatron.redis.host.nil?
configatron.redis.port = 6379 if configatron.redis.port.nil?
configatron.redis.db = 0 if configatron.redis.db.nil?
configatron.redis.host = ENV['MCONF_REDIS_HOST'] || 'localhost'
configatron.redis.port = ENV['MCONF_REDIS_PORT'] || 6379
configatron.redis.db = ENV['MCONF_REDIS_DB'] || 0

# Translations for the languages available. The names of the languages are not
# translated, so it's better to have them here than in the locale files.
Expand All @@ -50,6 +24,6 @@
}

# Scope for all URLs related to conferences
configatron.conf.scope = 'conf'
configatron.conf.scope = ENV['MCONF_CONFERENCE_SCOPE'] || 'conf'
# Scope for the short URLs of web conference rooms
configatron.conf.scope_rooms = 'conf'
configatron.conf.scope_rooms = ENV['MCONF_CONFERENCE_SCOPE_ROOMS'] || 'conf'
25 changes: 25 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# MySQL (default setup). Versions 4.1 and 5.0 are recommended.

development:
adapter: <%= ENV['MCONF_DATABASE_DEV_ADAPTER'] || 'mysql2' %>
database: <%= ENV['MCONF_DATABASE_DEV'] || 'mconf_web_dev' %>
username: <%= ENV['MCONF_DATABASE_DEV_USERNAME'] %>
password: <%= ENV['MCONF_DATABASE_DEV_PASSWORD'] %>
socket: <%= ENV['MCONF_DATABASE_DEV_SOCKET'] || '/var/run/mysqld/mysqld.sock' %>
encoding: utf8

test:
adapter: <%= ENV['MCONF_DATABASE_TEST_ADAPTER'] || 'mysql2' %>
database: <%= ENV['MCONF_DATABASE_TEST'] || 'mconf_web_test' %>
username: <%= ENV['MCONF_DATABASE_TEST_USERNAME'] %>
password: <%= ENV['MCONF_DATABASE_TEST_PASSWORD'] %>
socket: <%= ENV['MCONF_DATABASE_TEST_SOCKET'] || '/var/run/mysqld/mysqld.sock' %>
encoding: utf8

production:
adapter: <%= ENV['MCONF_DATABASE_PROD_ADAPTER'] || 'mysql2' %>
database: <%= ENV['MCONF_DATABASE_PROD'] || 'mconf_web_production' %>
username: <%= ENV['MCONF_DATABASE_PROD_USERNAME'] %>
password: <%= ENV['MCONF_DATABASE_PROD_PASSWORD'] %>
socket: <%= ENV['MCONF_DATABASE_PROD_SOCKET'] || '/var/run/mysqld/mysqld.sock' %>
encoding: utf8
25 changes: 0 additions & 25 deletions config/database.yml.example

This file was deleted.

22 changes: 0 additions & 22 deletions config/database.yml.sqlite.example

This file was deleted.

5 changes: 0 additions & 5 deletions config/database.yml.travis

This file was deleted.

32 changes: 32 additions & 0 deletions config/seeds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# This file is used to seed the database after it is created
# (by `rake db:reset` or `rake db:seed`).
#

# The first admin you will use to login and setup the application.
admin:
username: "admin"
email: "[email protected]"
password: "admin"

# The first, only and default Site model with general configurations for the website.
# You can add here any attribute available in the model Site.
site:
name: "Mconf Dev"
description: "Mconf Development Website"
domain: "localhost:3000"
smtp_login: ""
smtp_password: ""
smtp_server: ""
smtp_domain: "localhost"
smtp_sender: "[email protected]"
smtp_use_tls: false
smtp_auto_tls: false
smtp_auth_type: ""
smtp_port: 1025

# The first and default webconference server.
webconf_server:
name: "Default Server"
url: "http://test-install.blindsidenetworks.com/bigbluebutton/api"
secret: "8cd8ef52e8e101574e400365b55e11a6"
63 changes: 0 additions & 63 deletions config/setup_conf.yml.example

This file was deleted.

54 changes: 29 additions & 25 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
# database with its default values. The data can then be loaded with
# the rake db:seed (or created alongside the db with db:setup).

config_file = File.join(::Rails.root, "config", "seeds.yml")
config = YAML.load_file(config_file)

puts "* Create the default site"
puts " attributes read from the configuration file:"
puts " #{configatron.site.to_hash.inspect}"
puts " #{config.inspect}"
puts " smtp configurations defaults to Gmail if not set"

params = { # smtp configs for gmail
:smtp_auto_tls => true,
:smtp_server => "smtp.gmail.com",
:smtp_port => 587,
:smtp_use_tls => true,
:smtp_domain => "gmail.com",
:smtp_auth_type => :plain,
:domain => 'mconf-example.com'
"smtp_auto_tls" => true,
"smtp_server" => "smtp.gmail.com",
"smtp_port" => 587,
"smtp_use_tls" => true,
"smtp_domain" => "gmail.com",
"smtp_auth_type" => :plain,
"domain" => 'mconf-example.com'
}
params.merge!(configatron.site.to_hash)
params[:smtp_sender] ||= params[:smtp_login]
params.merge!(config["site"])
params["smtp_sender"] ||= params["smtp_login"]

if Site.count > 0
Site.current.update_attributes params
Expand All @@ -26,11 +29,11 @@
end


params = config["webconf_server"]
puts "* Create the default webconference server"
puts " attributes read from the configuration file:"
puts " #{configatron.webconf_server.to_hash.inspect}"
puts " #{params.inspect}"

params = configatron.webconf_server.to_hash
if BigbluebuttonServer.count > 0
BigbluebuttonServer.first.update_attributes params
else
Expand All @@ -39,26 +42,27 @@


puts "* Create default roles"
Role.create! name: 'User', stage_type: Space.name
Role.create! name: 'Admin', stage_type: Space.name
Role.create! name: 'Organizer', stage_type: Event.name
Role.create! name: 'Global Admin', stage_type: Site.name
Role.create! name: 'Normal User', stage_type: Site.name
Role.where(name: 'User', stage_type: Space.name).first_or_create!
Role.where(name: 'Admin', stage_type: Space.name).first_or_create!
Role.where(name: 'Organizer', stage_type: Event.name).first_or_create!
Role.where(name: 'Global Admin', stage_type: Site.name).first_or_create!
Role.where(name: 'Normal User', stage_type: Site.name).first_or_create!

params = config["admin"]
puts "* Create the administrator account"
puts " attributes read from the configuration file:"
puts " #{configatron.admin.to_hash.inspect}"
puts " #{params.inspect}"

params = configatron.admin.to_hash
params[:password_confirmation] ||= params[:password]
params[:_full_name] ||= params[:username]
profile = params.delete(:profile_attributes)
params["password_confirmation"] ||= params["password"]
params["_full_name"] ||= params["username"]
profile = params.delete("profile_attributes")

u = User.new params
u = User.where(username: params["username"]).first_or_initialize
u.assign_attributes(params)
u.skip_confirmation!
u.approved = true
if u.save(:validate => false)
u.profile.update_attributes(profile.to_hash) unless profile.nil?
if u.save(validate: false)
u.profile.update_attributes(profile) unless profile.nil?
u.set_superuser!
else
puts "ERROR!"
Expand Down

0 comments on commit b4211af

Please sign in to comment.