Skip to content

Instantly share code, notes, and snippets.

@marcelmorgan
Forked from pcreux/Gemfile
Created November 27, 2013 20:18
Show Gist options
  • Save marcelmorgan/7682502 to your computer and use it in GitHub Desktop.
Save marcelmorgan/7682502 to your computer and use it in GitHub Desktop.

Revisions

  1. @pcreux pcreux revised this gist Nov 27, 2013. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions addons.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    Free addons!

    ```
    heroku addons:add memcachier
    heroku addons:add sendgrid
    heroku addons:add newrelic
    heroku addons:add pgbackups
    heroku addons:add papertrail
    ```
  2. @pcreux pcreux revised this gist Nov 27, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@ end

    gem 'memcachier'
    gem 'dalli'
    # Fast IO for memcache
    gem 'kgio'

    # Serve static assets through Rack + Memcache
  3. @pcreux pcreux revised this gist Nov 27, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions production.rb
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@

    # Enable Rails's static asset server for Heroku
    config.serve_static_assets = true

    # Set static assets cache header. rack-cache will cache those.
    config.static_cache_control = "public, max-age=31536000"

    config.cache_store = :dalli_store
    @@ -12,11 +14,13 @@
    :value_max_bytes => 10485760,
    :expires_in => 1.day)

    # Configure rack-cache for using memcachier
    config.action_dispatch.rack_cache = {
    :metastore => client,
    :entitystore => client
    }

    # Send emails via sendgrid
    config.action_mailer.smtp_settings = {
    :address => 'smtp.sendgrid.net',
    :port => '587',
  4. @pcreux pcreux revised this gist Nov 27, 2013. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,17 @@
    group :production do
    gem 'unicorn'

    # Enable gzip compression on heroku, but don't compress images.
    gem 'heroku-deflater'

    # Heroku injects it if it's not in there already
    gem 'rails_12factor'
    end

    gem 'memcachier'
    gem 'dalli'
    gem 'kgio'

    # Serve static assets through Rack + Memcache
    # https://devcenter.heroku.com/articles/rack-cache-memcached-rails31
    gem 'rack-cache'
  5. @pcreux pcreux renamed this gist Nov 27, 2013. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions config/environments/production.rb → production.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    Refuge::Application.configure do
    # config/environments/production.rb

    # ...

    # Enable Rails's static asset server for Heroku
    config.serve_static_assets = true
    config.static_cache_control = "public, max-age=31536000"
    @@ -23,4 +26,6 @@
    :domain => 'heroku.com',
    :enable_starttls_auto => true
    }
    end

    # ...

  6. @pcreux pcreux renamed this gist Nov 27, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions config/unicorn.rb → unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # config/unicorn.rb

    worker_processes 3
    timeout 30
    preload_app true
  7. @pcreux pcreux revised this gist Nov 27, 2013. 2 changed files with 34 additions and 0 deletions.
    1 change: 1 addition & 0 deletions Procfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
    33 changes: 33 additions & 0 deletions config/unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    worker_processes 3
    timeout 30
    preload_app true

    before_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    Rails.logger.info('Disconnected from ActiveRecord')
    end

    # If you are using Redis but not Resque, change this
    if defined?(Resque)
    Resque.redis.quit
    Rails.logger.info('Disconnected from Redis')
    end

    sleep 1
    end

    after_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
    Rails.logger.info('Connected to ActiveRecord')
    end

    # If you are using Redis but not Resque, change this
    if defined?(Resque)
    Resque.redis = ENV['REDIS_URI']
    Rails.logger.info('Connected to Redis')
    end
    end
  8. @pcreux pcreux revised this gist Nov 27, 2013. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions config/environments/production.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    Refuge::Application.configure do
    # Enable Rails's static asset server for Heroku
    config.serve_static_assets = true
    config.static_cache_control = "public, max-age=31536000"

    config.cache_store = :dalli_store

    client = Dalli::Client.new(ENV["MEMCACHIER_SERVERS"],
    :value_max_bytes => 10485760,
    :expires_in => 1.day)

    config.action_dispatch.rack_cache = {
    :metastore => client,
    :entitystore => client
    }

    config.action_mailer.smtp_settings = {
    :address => 'smtp.sendgrid.net',
    :port => '587',
    :authentication => :plain,
    :user_name => ENV['SENDGRID_USERNAME'],
    :password => ENV['SENDGRID_PASSWORD'],
    :domain => 'heroku.com',
    :enable_starttls_auto => true
    }
    end
  9. @pcreux pcreux created this gist Nov 27, 2013.
    11 changes: 11 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    group :production do
    gem 'unicorn'
    gem 'heroku-deflater'
    gem 'rails_12factor'
    end

    gem 'memcachier'
    gem 'dalli'
    gem 'kgio'

    gem 'rack-cache'