I am using WickedPDF, and I have basically two gems that include the binaries:
gem "wkhtmltopdf-heroku", "1.0.0"
gem "wkhtmltopdf-binary", "0.9.5.3"
The first one is supposed to be just for production, and the second one for development. The deployment to Heroku doesn't work if I have my Gemfile like:
group :development do
gem "wkhtmltopdf-binary", "0.9.5.3"
end
group :production do
gem "wkhtmltopdf-heroku", "1.0.0"
end
And it doesn't work either if I have it like:
group :production do
gem "wkhtmltopdf-heroku", "1.0.0"
end
It just works if I have it without groups. Just like:
gem "wkhtmltopdf-heroku", "1.0.0"
The error that I get is:
RuntimeError: Location of wkhtmltopdf unknown
Why would this happen? Why Heroku is not using the production group?
WickedPdf tries to figure out where the wkhtmltopdf binary lives, but can have a hard time on some systems (particularly shared servers).
You probably have to set it manually in an initializer something like this:
bin_location = case Rails.env
when 'production' then "/wherever/your/binary/is/bin/wkhtmltopdf"
when 'development' then "/local/path/to/wkthmltopdf"
else `which wkhtmltopdf`
end
WickedPdf.config = { :exe_path => bin_location }
Related
I've read Richard Schneeman's article, and a bunch of other ones. ;-)
I'm still struggling with this.
Here's few gems I've added in my Gemfile to benchmark my app:
gem 'airbrake'
gem 'newrelic_rpm'
gem 'stackprof'
gem 'derailed', group: :development
gem 'rack-mini-profiler'
gem 'flamegraph'
gem 'memory_profiler'
gem "skylight"
After a lots of benchmarks in development and in staging env, I know where my app is not fast enough but there's not memory leak (some small mem bloats sometimes maybe).
newapp-staging app is the new version (aka: new frontend, upgraded gems, optimized queries, ...) of oldapp-production app.
Please have a look at the screenshots (oldapp-production use webrick, newapp-staging use puma)
So here comes 2 simple questions:
question #1
newapp-staging app is using ruby '2.2.0' & rails '3.2.22.2' and I can't ensure that it is threadsafe because of my code and the associated gems, so... I must use 1 thread at a time. Is puma an advantage here? Metrics are telling me not.
OR... my configuration is not good. (missing preload_app! maybe, or other things?) Here's my Procfile:
web: bundle exec puma -t 1:1 -p ${PORT:-3000} -e ${RACK_ENV:-development}
worker: bundle exec rake jobs:work
question #2
Unicorn could be used as a replacement?
Thank you for your time and your advices.
Cheers
Using unicorn is the best move here. Here's my configuration if that could help anyone.
Gemfile:
gem 'unicorn'
gem 'unicorn-rails'
group :production, :staging do
gem 'unicorn-worker-killer'
end
Procfile:
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 2)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
config.ru
if ENV['RAILS_ENV'] == 'production' || ENV['RAILS_ENV'] == 'staging'
require 'unicorn/worker_killer'
use Unicorn::WorkerKiller::MaxRequests, 768, 1024, true
use Unicorn::WorkerKiller::Oom, (450*(1024**2)), (490*(1024**2)), 16, true
end
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Deflater
run MyApp::Application
On Heroku:
2 x `Standard 2X dynos` for web
1 x `Standard 1X dyno` for worker
Heroku config vars:
SENSIBLE_DEFAULTS: enabled (just in case) & WEB_CONCURRENCY: 2
Cheers
I want to use guard to run my bacon tests, my Gemfile looks like:
source 'https://rubygems.org'
gem 'sinatra'
gem 'sidekiq'
gem 'slim'
gem 'puma'
gem 'nokogiri'
gem 'httparty'
group :test, :development do
gem 'guard'
gem 'bacon'
gem 'guard-bacon'
gem 'libnotify'
gem 'rb-inotify'
end
My Guardfile looks like
# parameters:
# output => the formatted to use
# backtrace => number of lines, nil = everything
guard 'bacon', :output => "BetterOutput", :backtrace => 4 do
watch(%r{^lib/(.+)\.rb$}) { |m| "specs/lib/#{m[1]}_spec.rb" }
watch(%r{specs/.+\.rb$})
end
When I run guard the following happens
$ guard
Bacon: Using output BetterOutput.
Bacon: Limiting backtrace to 4 lines.
09:02:05 - INFO - Guard uses Libnotify to send notifications.
09:02:05 - INFO - Guard uses TerminalTitle to send notifications.
09:02:05 - INFO - Guard is now watching at '/home/martin/code/jse-api'
Guard::Bacon started.
[1] guard(main)> %
$
It seems to load everything, get to the guard prompt and exit.
I have no idea why?
The issue seems to the version of guard required by guard-bacon 1.1.0
If you force it to the latest version of guard
gem 'guard', '>= 1.8.0'
It falls back to a older version of guard-bacon 1.0.5 and everything works.
I am using the following configurations in my deploy.rb file for capistrano:
require 'bundler/capistrano'
require 'rvm/capistrano'
set :bundle_cmd, "/home/deployment/.rvm/gems/ruby-1.9.3-p194#global/bin/bundle"
set :default_environment, {
'PATH' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194/bin:/home/deployment/.rvm/bin:$PATH",
'RUBY_VERSION' => 'ruby 1.9.3',
'GEM_HOME' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194",
'GEM_PATH' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194",
'BUNDLE_PATH' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194"
}
But when I run cap deploy:update I get this:
* executing "cd /var/www/currienet/marketplace/releases/20120928140140 && /home/deployment/.rvm/gems/ruby-1.9.3-p194#global/bin/bundle install --gemfile /var/www/currienet/marketplace/releases/20120928140140/Gemfile --path /var/www/currienet/marketplace/shared/bundle --deployment --quiet --without development test"
That is, it's not setting the bundle path (the --path argument) to what I want it to be.
I've tried a number of tutorials, including the rvm capistrano tutorial but nothing seems to work. It continues to use the capistrano default.
Capistrano also creates an application with the following .bundler/config
BUNDLE_FROZEN: '1'
BUNDLE_PATH: /var/www/currienet/marketplace/shared/bundle
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_WITHOUT: development:test
Development Machine: Windows 7, bundler (1.0.22), capistrano (2.12.0), rvm-capistrano (1.2.7), rails (3.2.8), (no rvm)
Production: Debian, bundler (1.2.1) (no capistrano), (no rvm-capistrano), rails (3.2.8), rvm 1.16.5
Thanks to Joseph Holsten's blog I was able to ascertain my problem was I was not defining the bundler variables in my deploy.rb before I required 'bundler/capistrano'. I also needed to define the bundle_dir variable, to create code that looks like the following:
set :bundle_cmd, "/home/deployment/.rvm/gems/ruby-1.9.3-p194#global/bin/bundle"
set :bundle_dir, "/home/deployment/.rvm/gems/ruby-1.9.3-p194"
require 'bundler/capistrano'
config/application.rb
...
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.assets.digest = true
config.assets.paths << "#{Rails.root}/vendor/assets/images"
...
config/environment.rb
...
ENV['RAILS_ENV'] ||= 'production'
...
My gemfile
...
gem 'uglifier'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
#gem 'uglifier'
end
...
environment/production.rb
....
config.active_support.deprecation = :notify
config.assets.enabled = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :scss
config.assets.compress = false
...
I have my javascript files in app/assets/javascripts. My javascript files are not getting compressed. Followed this url http://dev.mensfeld.pl/category/rails3/ to workout compression.
Thanks for any directions.
In environment/production.rb:
...
config.assets.compress = true
...
I had the same problem, & after much tearing of hair, discovered that you must change an asset file in order to trigger compression.
Seems that compression relies on asset file mtime, which makes sense, since one of the problems the asset pipeline intends to overcome is (from the Rails guide):
... when static assets are deployed with each new release of code, the mtime of all these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed.
use this command:
rake RAILS_ENV=production RAILS_GROUP=assets assets:precompile
When i run my features i get this error:
undefined method `visit' for #<Cucumber::Rails::World:0x81b17ac0> (NoMethodError)
This is the relevant part of my Gemfile.
group :development, :test do
gem "rspec-rails", ">= 2.0.0.beta.19"
gem "cucumber"
gem "cucumber-rails", ">= 0.3.2"
gem 'webrat', ">= 0.7.2.beta.1"
end
The relating step_definition (though i don't think it's important)
When /^I create a movie Caddyshack in the Comendy genre$/ do
visit movies_path
click_link "Add Movie"
fill_in "Title", :with => "Caddyshack"
check "Comedy"
click_button "Save"
end
In the env.rb i have the following Webrat configuration:
# […]
require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
# […]
Anything i am missing here?
I had to set config.mode to :rack instead of :rails:
# […]
require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rack
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
# […]
now works as expected.
Paul Nelligan try adding this to env.rb to fix the error : "no such file to load -- action_controller/integration"
World(Webrat::Methods)
World(Webrat::Matchers)
I also encountered this error on two separate occasions: the first instance the adjustment to confg.mode solved the problem; the second time, however, after a lot of frustration I found a link that suggested a buggy version of bundler could be the culprit. Updating it solved the problem.