[Git][noosfero/noosfero][master] 3 commits: Optionally use dotenv

Bráulio Bhavamitra gitlab at mg.gitlab.com
Fri Mar 17 14:32:38 BRT 2017


Bráulio Bhavamitra pushed to branch master at Noosfero / noosfero


Commits:
9886db34 by Braulio Bhavamitra at 2017-03-17T14:30:22-03:00
Optionally use dotenv

- - - - -
5a853d6f by Braulio Bhavamitra at 2017-03-17T14:30:22-03:00
puma: use environment variables

- - - - -
86acdf46 by Braulio Bhavamitra at 2017-03-17T14:30:22-03:00
Configure mailgun and rollbar if tokens are provided

- - - - -


9 changed files:

- + .env
- + .env.production
- + .env.test
- config/database.yml.pgsql
- + config/dotenv.rb
- config/environment.rb
- + config/initializers/mailgun.rb
- + config/initializers/rollbar.rb
- config/puma.rb


Changes:

=====================================
.env
=====================================
--- /dev/null
+++ b/.env
@@ -0,0 +1,28 @@
+# number of workers
+WORKERS=2
+
+# number of threads
+THREADS=16
+
+# Max memory in mb that the worker shouldn't exceed
+WORKER_MAX_MEM=512
+
+# Daemons (delayed_job/feed_updater) threads priority inside Puma
+# The lower the priority the less it will run compared to HTTP requests
+DAEMON_PRIORITY=-5
+
+# TCP port to bind to in webservers
+BIND_PORT=3000
+
+# Max connections on db, need to be higher than the number of threads
+DB_POOL=20
+
+# RollBar token
+#ROLLBAR_TOKEN='xxxxxxx'
+
+# Mailgun token if using it
+#MAILGUN_TOKEN='key-xxxxxxx'
+
+# Mailgun domain
+#MAILGUN_DOMAIN='example.com'
+


=====================================
.env.production
=====================================
--- /dev/null
+++ b/.env.production
@@ -0,0 +1,4 @@
+
+# TCP port to bind to in webservers
+BIND_PORT=50000
+


=====================================
.env.test
=====================================
--- /dev/null
+++ b/.env.test


=====================================
config/database.yml.pgsql
=====================================
--- a/config/database.yml.pgsql
+++ b/config/database.yml.pgsql
@@ -15,7 +15,7 @@ development:
   template: template0
   username: noosfero
   password:
-  pool: 20
+  pool: <%= (ENV['DB_POOL'] || '20').to_i %>
 
   # Connect on a TCP socket. Omitted by default since the client uses a
   # domain socket that doesn't need configuration. Windows does not have
@@ -50,7 +50,7 @@ production:
   template: template0
   username: noosfero
   password:
-  pool: 20
+  pool: <%= (ENV['DB_POOL'] || '20').to_i %>
 
 cucumber:
   <<: *TEST


=====================================
config/dotenv.rb
=====================================
--- /dev/null
+++ b/config/dotenv.rb
@@ -0,0 +1,15 @@
+begin
+  require 'dotenv'
+
+  # Load custom variables for the deploy
+  Dotenv.load '.env.custom'
+
+  # Load environment specific .env files
+  Dotenv.load ".env.#{ENV['RAILS_ENV']}"
+
+  # The regular .env is required and overwrites everything that is not already set
+  Dotenv.load! '.env'
+
+rescue LoadError
+  # put dotenv on config/Gemfile to use it
+end


=====================================
config/environment.rb
=====================================
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -1,3 +1,4 @@
+require_relative 'dotenv'
 require_relative 'application'
 
 Noosfero::Application.initialize!


=====================================
config/initializers/mailgun.rb
=====================================
--- /dev/null
+++ b/config/initializers/mailgun.rb
@@ -0,0 +1,9 @@
+if ENV['MAILGUN_TOKEN'].present?
+  # Use with mailgun-ruby or mailgun_rails gem
+
+  ActionMailer::Base.delivery_method  = :mailgun
+  ActionMailer::Base.mailgun_settings = {
+    api_key: ENV['MAILGUN_TOKEN'],
+    domain:  ENV['MAILGUN_DOMAIN'],
+  }
+end


=====================================
config/initializers/rollbar.rb
=====================================
--- /dev/null
+++ b/config/initializers/rollbar.rb
@@ -0,0 +1,8 @@
+if ENV['ROLLBAR_TOKEN'].present?
+  Rollbar.configure do |config|
+    config.access_token = ENV['ROLLBAR_TOKEN']
+    config.exception_level_filters.merge!(
+      'ActionController::InvalidCrossOriginRequest' => 'ignore',
+    )
+  end
+end


=====================================
config/puma.rb
=====================================
--- a/config/puma.rb
+++ b/config/puma.rb
@@ -1,14 +1,14 @@
+require_relative 'dotenv'
+
 RailsRoot      = Dir.pwd
-BindPort       = 3000
+BindPort       = (ENV['BIND_PORT'] || '3000').to_i
 Production     = if ENV['RAILS_ENV'] == 'production' then true else false end
 
-Workers        = 2
-Threads        = 16 # db pool must be higher than this
-
-WorkerKiller   = true
-WorkerMaxMem   = 256*2
+Workers        = (ENV['WORKERS'] || '2').to_i
+Threads        = (ENV['THREADS'] || '5').to_i
+WorkerMaxMem   = (ENV['WORKER_MAX_MEM'] || '512').to_i
 
-DaemonPriority = -5
+DaemonPriority = (ENV['DAEMON_PRIORITY'] || '-5').to_i
 WorkerDaemons  = {
   delayed_job: {
     worker_nr: 0,
@@ -39,19 +39,17 @@ workers Workers
 threads 0,Threads
 
 before_fork do
-  if WorkerKiller
-    begin
-      require 'puma_worker_killer'
-      PumaWorkerKiller.config do |config|
-        config.ram           = Workers * WorkerMaxMem # mb
-        config.frequency     = 15                     # seconds
-        config.percent_usage = 0.90
-        config.rolling_restart_frequency = 12 * 3600  # 12 hours in seconds
-      end
-      PumaWorkerKiller.start
-    rescue LoadError
-      puts 'Add `puma_worker_killer` to `config/Gemfile` to use worker killer'
+  begin
+    require 'puma_worker_killer'
+    PumaWorkerKiller.config do |config|
+      config.ram           = Workers * WorkerMaxMem # mb
+      config.frequency     = 15                     # seconds
+      config.percent_usage = 0.90
+      config.rolling_restart_frequency = 12 * 3600  # 12 hours in seconds
     end
+    PumaWorkerKiller.start
+  rescue LoadError
+    puts 'Add `puma_worker_killer` to `config/Gemfile` to use worker killer'
   end
 end
 



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/92625eca95eda26cf68b4c48f3b6e59b53f247f9...86acdf46cfc9d44d0d7daa512717cd70d42bd2ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170317/5d0b6451/attachment-0001.html>


More information about the Noosfero-dev mailing list