diff --git a/.gitignore b/.gitignore index 0574eb0..60a71da 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ nbproject/* .bundle .sass-cache/ public/assets/ + +config/settings.yml +config/settings.local.yml diff --git a/Gemfile b/Gemfile index 05d06f0..e20a62c 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,7 @@ gem 'rqrcode-rails3' gem 'mini_magick' gem 'routing_concerns' gem 'deep_cloneable', '~> 1.5.5' +gem 'rails_config' # Gems used only for assets and not required # in production environments by default. diff --git a/Gemfile.lock b/Gemfile.lock index 4f02d2b..83f9775 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -189,6 +189,8 @@ GEM activesupport (= 3.2.13) bundler (~> 1.0) railties (= 3.2.13) + rails_config (0.3.2) + activesupport (>= 3.0) railties (3.2.13) actionpack (= 3.2.13) activesupport (= 3.2.13) @@ -315,6 +317,7 @@ DEPENDENCIES pg poltergeist rails (~> 3.2.0) + rails_config rake recordselect redcarpet diff --git a/config/backup.rb b/config/backup.rb new file mode 100644 index 0000000..a8eed9c --- /dev/null +++ b/config/backup.rb @@ -0,0 +1,51 @@ +Backup::Model.new(:taurus, 'Taurus backup configuration') do + + db_config = YAML.load_file("#{File.dirname(__FILE__)}/database.yml") + app_config = YAML.load_file("#{File.dirname(__FILE__)}/settings.yml") + + database PostgreSQL do |db| + db.name = db_config['production']['database'] + db.username = db_config['production']['username'] + db.password = db_config['production']['password'] + db.host = db_config['production']['host'] + db.port = db_config['production']['port'] + db.skip_tables = ['sessions', 'sessions_id_seq'] + db.additional_options = ['--clean'] + end + + compress_with Bzip2 + + store_with SCP do |server| + server.username = app_config['backup']['server']['username'] + server.password = app_config['backup']['server']['password'] + server.ip = app_config['backup']['server']['ip'] + server.port = app_config['backup']['server']['port'] + server.path = app_config['backup']['server']['path'] + server.keep = app_config['backup']['server']['keep'] + end + + store_with Dropbox do |db| + db.api_key = app_config['backup']['dropbox']['api_key'] + db.api_secret = app_config['backup']['dropbox']['api_secret'] + db.path = app_config['backup']['dropbox']['path'] + db.keep = 5 + end + + store_with Local do |local| + local.path = app_config['backup']['local']['path'] + local.keep = app_config['backup']['local']['keep'] + end + + notify_by Mail do |mail| + mail.on_success = true + mail.on_failure = true + + mail.from = "#{app_config['mailer']['user_name'] || 'andrey.novikov'}@#{app_config['mailer']['domain']|| 'amursu.ru'}" + mail.to = app_config['backup']['email']['to'] + mail.address = app_config['mailer']['address'] + mail.domain = app_config['mailer']['domain'] || 'amursu.ru' + mail.port = app_config['mailer']['port'] + mail.authentication = app_config['mailer']['authentication'] if app_config['mailer']['authentication'] + end + +end diff --git a/config/backup.rb.example b/config/backup.rb.example deleted file mode 100644 index 68a394c..0000000 --- a/config/backup.rb.example +++ /dev/null @@ -1,40 +0,0 @@ -Backup::Model.new(:taurus, 'Taurus backup configuration') do - - database PostgreSQL do |db| - db.name = 'taurus' - db.username = 'taurus_user' - db.password = 'taurus_password' - db.host = 'taurus.amursu.ru' - db.port = 5432 - db.skip_tables = ['sessions', 'sessions_id_seq'] - db.additional_options = ['--clean'] - end - - compress_with Bzip2 - - store_with SCP do |server| - server.username = 'backup_user' - server.password = 'backup_pass' - server.ip = 'backup_ip' - server.port = 22 - server.path = '/path/to/backups' - server.keep = 50 - end - - store_with Local do |local| - local.path = '~/backups' - local.keep = 50 - end - - notify_by Mail do |mail| - mail.on_success = true - mail.on_failure = true - - mail.from = 'taurus@amursu.ru' - mail.to = '' - mail.address = 'localhost' - mail.domain = 'amursu.ru' - mail.port = 25 - mail.authentication = 'plain' - end -end diff --git a/config/deploy.rb b/config/deploy.rb index a60adad..e16634a 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -37,7 +37,7 @@ after 'deploy:update_code', :roles => :app do run "test -d #{deploy_to}/shared/config || mkdir #{deploy_to}/shared/config" run "test -f #{deploy_to}/shared/config/database.yml || cp #{current_release}/config/database.yml.example #{deploy_to}/shared/config/database.yml" - run "test -f #{deploy_to}/shared/config/backup.rb || cp #{current_release}/config/backup.rb.example #{deploy_to}/shared/config/backup.rb" + run "test -f #{deploy_to}/shared/config/settings.yml || cp #{current_release}/config/settings.yml.example #{deploy_to}/shared/config/settings.yml" run "test -f #{deploy_to}/shared/config/newrelic.yml || cp #{current_release}/config/newrelic.yml.example #{deploy_to}/shared/config/newrelic.yml" end @@ -46,8 +46,8 @@ run "rm -f #{current_release}/config/database.yml" run "ln -s #{deploy_to}/shared/config/database.yml #{current_release}/config/database.yml" - run "rm -f #{current_release}/config/backup.rb" - run "ln -s #{deploy_to}/shared/config/backup.rb #{current_release}/config/backup.rb" + run "rm -f #{current_release}/config/settings.yml" + run "ln -s #{deploy_to}/shared/config/settings.yml #{current_release}/config/settings.yml" run "rm -f #{current_release}/config/newrelic.yml" run "ln -s #{deploy_to}/shared/config/newrelic.yml #{current_release}/config/newrelic.yml" diff --git a/config/environments/production.rb b/config/environments/production.rb index e3dae84..b485ac6 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -54,6 +54,6 @@ # Generate digests for assets URLs config.assets.digest = true - GA.tracker = 'UA-39782423-3' + GA.tracker = Settings.analytics.id end diff --git a/config/initializers/rails_config.rb b/config/initializers/rails_config.rb new file mode 100644 index 0000000..5378de9 --- /dev/null +++ b/config/initializers/rails_config.rb @@ -0,0 +1,3 @@ +RailsConfig.setup do |config| + config.const_name = "Settings" +end \ No newline at end of file diff --git a/config/settings.yml.example b/config/settings.yml.example new file mode 100644 index 0000000..4b6979c --- /dev/null +++ b/config/settings.yml.example @@ -0,0 +1,25 @@ +mailer: + address: mail.amursu.ru + port: 587 + +analytics: + id: UA-39782423-3 + +backup: + server: + username: user + password: password + ip: 1backup.server.ip.address + port: 22 + path: /data/backups + keep: 50 + dropbox: + api_key: my_key + api_secret: my_secret + path: / + keep: 5 + local: + path: ~/backups + keep: 100 + email: + to: my@email.address