jpegrecompress worker: `jpeg-recompress` not found; - ruby-on-rails

I recently installed the paperclip-optimizer gem in my Rails 4 app on Heroku. Whenever I attempt to save an uploaded image attachment, I get the following error: jpegrecompress worker: 'jpeg-recompress' not found; in my logs from Heroku, but not on localhost.
I'm not sure what I'm missing. I can't seem to find a single StackOverflow post, blog post, or other resource on this problem.
Here is my config/initializers/paperclip_optimizer.rb:
Paperclip::PaperclipOptimizer.default_options = {
skip_missing_workers: true,
advpng: false,
gifsicle: false,
jhead: false,
jpegoptim: false,
jpegrecompress: true,
jpegtran: false,
optipng: false,
pngcrush: false,
pngout: false,
pngquant: true,
svgo: false,
nice: 10, # Nice level (defaults to 10)
threads: 1, # Number of threads or disable (defaults to number of processors)
verbose: false, # Verbose output (defaults to false)
pack: nil, # Require image_optim_pack or disable it, by default image_optim_pack will be used if available,
allow_lossy: true, # Allow lossy workers and optimizations (defaults to false)
jpegrecompress: {
quality: 2 # JPEG quality preset: 0 - low, 1 - medium, 2 - high, 3 - veryhigh (defaults to 3)
},
pngquant: {
quality: 100..100, # min..max - don't save below min, use less colors below max (both in range 0..100; in yaml - !ruby/range 0..100) (defaults to 100..100)
speed: 3 # speed/quality trade-off: 1 - slow, 3 - default, 11 - fast & rough (defaults to 3)
}
}
In my photo.rb model I have:
has_attached_file :image, styles: { large: "600x600>", medium: "300x300>", thumb: "100x100>" }, default_url: "", processors: [:thumbnail, :paperclip_optimizer]
In my .buildpacks file for Heroku I have:
https://github.com/ddollar/heroku-buildpack-multi.git
https://github.com/heroku/heroku-buildpack-ruby.git
https://github.com/bobbus/image-optim-buildpack.git
I added the Ruby buildpack to solve this problem I was having earlier, but now it seems as though the multi and the image-optim buildpacks aren't loading.
Thanks!

After much head banging and keyboard bashing, I figured out how to solve the problem. In my case, I'm running a Rails 4.0 app on the Cedar-14 stack running on the Puma webserver, so these instructions may or may not be of use to you if you're configuration is different.
I followed the steps on this Heroku Dev Center article on adding multiple buildpacks to an app, which is now supported by Heroku.
In my case, I have the following buildpacks added for my app:
=== staging-app Buildpack URLs
1. https://github.com/bobbus/image-optim-buildpack.git
2. https://github.com/heroku/heroku-buildpack-ruby.git
The order is critical. The last buildpack on the list is the first one to be loaded. In my case, I need the Ruby buildpack so that the bundle command in my Procfile is recognized. See this question for more on that issue.
Do NOT use the Heroku-Buildpack-Multi. From what I understand, this is the old way to support multiple buildpacks. Adding this will cause your pushes to be rejected.
In my Gemfile, I needed to include the image_optim and image_optim_pack gems. These gems make the appropriate binaries available on OS X and Linux environments, from what I understand. It is very important to place these gems before paperclip-optimizer in the Gemfile, like so
gem 'paperclip', '~> 4.1'
group :production do
# Needs to be placed before paperclip-optimizer
gem 'image_optim'
gem 'image_optim_pack'
end
gem 'paperclip-optimizer'
Configure your paperclip-optimizer settings as you see fit and push to production.
Hopefully this helps someone in my situation.

Related

How can I get dependabot to ignore a docker minor version

I'm trying to stay one minor version behind the latest python version, and I was hoping to use dependabot to help with that.
I'm using the python slim docker image as my base image, and based on that plus the dependabot docs I've added the following to my dependabot.yml:
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
ignore:
- dependency-name: "python"
versions: [ "3.10.x" ]
This is not working. When I tell the 3.10 PR to "ignore this minor version", however, it does so successfully and states that it won't bother me about 3.10.x versions anymore, so clearly the logic is in there somewhere
It is using Gem::Requirement here: https://github.com/dependabot/dependabot-core/blob/c0945b376ef12f3551e22f185dc6f20c56049296/docker/lib/dependabot/docker/requirement.rb#L8
I haven't tested this specific scenario, but I am using something similar with success. I think this will work:
ignore:
- dependency-name: "python"
versions: ["~> 3.10", "< 3.11"]
It appears to anyway, when testing against Gem::Requirement:
>> r = Gem::Requirement.new("~> 3.10", "< 3.11")
=> Gem::Requirement.new(["~> 3.10", "< 3.11"])
>> r.satisfied_by?(Gem::Version.new('3.11'))
=> false
>> r.satisfied_by?(Gem::Version.new('3.10'))
=> true
>> r.satisfied_by?(Gem::Version.new('3.10.1'))
=> true

Rails Puma: --no-dev-caching does not work

Whenever I change an included .scss file I cannot see the changes, even if I restart the server. I found that if I manually delete tmp/cache/* then restart the server, I can see the changes one time. Further changes are not shown (and the cache is back). I have tried rails server --no-dev-caching but it doesn't help. I have
config.assets.digest = false
config.assets.debug = false
config.assets.quiet = false
config.assets.raise_runtime_errors = true
config.action_controller.perform_caching = false
config.cache_store = :null_store
How can I see changes to my SCSS files when I reload the page in development? I test with curl http://localhost:3000/assets/application.css | less and search for the class that I changed and saved.
=> Booting Puma
=> Rails 5.0.7.2 application starting in development on http://localhost:3000
* Version 3.12.2 (ruby 2.4.3-p205), codename: Llamas in Pajamas
* Environment: development
Docs: https://guides.rubyonrails.org/v5.0/configuring.html#configuring-assets
I commented out Puma, used WebBrick with rails server --no-dev-caching, set config.assets.debug = true, loaded $ curl http://localhost:3000/assets/theme/theme.self.css | less, and the change was still not there.
I found the answer here! https://stackoverflow.com/a/59895954/148844
I had to change #import "theme-overrides.scss"; => #import "theme-overrides";, rename theme-overrides.scss => _theme-overrides.scss, change #import "theme_components/helpers.scss"; => #import "theme_components/helpers";, rename helpers.scss => _helpers.scss, and it all worked!
Now I have to rename 100 different files!

AWS Elastic Beanstalk Error - Passenger

I've tried various solutions that are intuitive and then have tried the solutions that have apparently helped others. I've spun up and terminated my Rails 4 app about 10 times. So...I thought I'd turn here to see if anyone knew an answer.
Here is the log file:
[ 2015-03-06 06:12:27.0070 2619/7fa0f6d60740 agents/Watchdog/Main.cpp:538 ]:
Options: { 'analytics_log_user' => 'webapp', 'cleanup_pidfiles' =>
'L3RtcC9wYXNzZW5nZX*********************yL3RlbXBfZGlyX3RvdWNoZXIucGlk',
'default_group' => 'webapp', 'default_python' => 'python', 'default_ruby' =>
'/opt/rubies/ruby-2.1.5/bin/ruby', 'default_user' => 'webapp', 'log_level' =>
'0', 'max_pool_size' => '6', 'passenger_root' => '/tmp/passenger-
standalone.1fcb7jr/locations.ini', 'passenger_version' => '4.0.53',
'pool_idle_time' => '300', 'prestart_urls' => 'aHR0cDovLzAuMC4wLjA6ODAA',
'temp_dir' => '/tmp', 'union_station_gateway_address' =>
'gateway.unionstationapp.com', 'union_station_gateway_port' => '443',
'user_switching' => 'false', 'web_server_passenger_version' => '4.0.53',
'web_server_pid' => '2618', 'web_server_type' => 'nginx',
'web_server_worker_gid' => '496', 'web_server_worker_uid' => '497' }
[ 2015-03-06 06:12:27.3877 2622/7fac802f6740 agents/HelperAgent/Main.cpp:650]:
PassengerHelperAgent online, listening at
unix:/tmp/passenger.1.0.2618/generation-0/request
[ 2015-03-06 06:12:28.2222 2630/7fe1e0b67740 agents/LoggingAgent/Main.cpp:321
]: PassengerLoggingAgent online, listening at
unix:/tmp/passenger.1.0.2618/generation-0/logging
[ 2015-03-06 06:12:28.2223 2619/7fa0f6d60740 agents/Watchdog/Main.cpp:728 ]:
All Phusion Passenger agents started!
2015/03/06 06:12:29 [error] 2638#0: *3 "/var/app/current/public/index.html" is
not found (2: No such file or directory), client: 127.0.0.1, server: _,
request: "HEAD / HTTP/1.1", host: "0.0.0.0"
2015/03/06 06:13:35 [error] 2638#0: *7 "/var/app/current/public/index.html" is
not found (2: No such file or directory), client: 172.3*.**.***, server: _,
request: "GET / HTTP/1.1", host: "****************-env.elasticbeanstalk.com"
I have gem 'passenger' in my gem file...I have tried in both development (because I've seen a number of errors with production and passenger) and production and I swear I have never had this kind of trouble uploading to elastic beanstalk. In fact this is a very stripped down app with only a static page and both devise for a user and devise for active admin. No errors or problem in either environment on my local machine.
I've never even realized I needed the index.html file...I always assumed that was only in php and other languages and that Rails took care of that for you with root. And like I said I've never seen this problem before. So to test that I put in an index.html file in the public folder and I could see that ahead of my root route on my local machine, but still no dice in AWS. I'd prefer to be able to drop this in and one of the other configs like just Puma. And I see a Puma and Nginx config available, but not in the GUI which is what I was planning to just "drop" this in and be done with it for the time being. I'm using a t2.small instance.
Any help or direction would be greatly appreciated. Thanks.
UPDATE: I've now tried this pushing through Git using Puma...etc. Trouble everywhere. It makes no sense. I even moved it to a "Hello World" app and still nothing. I'm about done with AWS. This is ridiculous. Nearly worse than an iOS release that has massive problems every year.
Ok. After today I have gotten this taken care of and hosted properly. In case this helps someone out...here were the key takeaways:
1) There is a Puma option if you are using CLI that is obvious. There is ALSO an option in the GUI, however it reads like a sentence instead of a logical select box. It DOES exist on the front page underneath the selection of the language to be installed. If you are getting a Passenger Error and expect to be using Puma, this is something you need to change.
2) I had installed a User model that contained an ActiveAdmin role as well. ActiveAdmin was pulling the gem from GitHub and I am using a machine with GitHub installed already. This really was the problem...switching to production and onto ElasticBeanstalk I forgot that git wasn't already installed. After going back through the errors many times, the common error was
# :github => 'activeadmin/activeadmin'+ '[' -d /vendor/cache ']'
+ bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
You need to install git to be able to use gems from git repositories.
[CMD-Startup/StartupStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.
This is located in the eb-activity.log.
So, if this is similar to anything happening to you, you can do as follows:
1) start up your instance with the correct server.
2) if you get an error, look through that activity log mentioned above. (All the logs for that matter)
3) If the error fails similarly there is NO NEED to delete the instance. Leave it running.
4) SSH into the server instance that you just created. Run
sudo yum update
that is more than likely recommended. And then run
sudo yum install git
5) Upload the same exact file and name the version 0.1 and when it's through it should be green if this was your only error. Click the link and Voila.
For the git binary problem: It will fail again, if more instances are spinning up. You can avoid that by adding a config under $ROOT/.ebextensions which will be used for any new instance.
# Install git in order to be able to bundle gems from git
packages:
yum:
git: []

No expected output for my performance testing

I want to do a performance test for my rails 3 app and I did a try according to the rails online guide
rake test:profile
and it gave some output as:
Specify ruby-prof as application's dependency in Gemfile to run benchmarks.
Loaded suite /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/rake_test_loader
Started
.
Finished in 0.326233 seconds.
1 tests, 0 assertions, 0 failures, 0 errors, 0 skips
But according to the guide, there should be something like:
BrowsingTest#test_homepage (31 ms warmup)
wall_time: 6 ms
memory: 437.27 KB
objects: 5,514
gc_runs: 0
gc_time: 19 ms
and also some log files produced in app's tmp/performance dir, which doesn't exist in my case.
The performance test is the generated sample test, browsing_test.rb, in my app's test\performance dir:
require 'test_helper'
require 'rails/performance_test_help'
# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionDispatch::PerformanceTest
def test_homepage
get '/'
end
end
And my rails version is 3.0.10. Can anyone give me some tips or hints?
Had the exact same issue, and solved it by running
rvm install 1.9.2-p290 --patch gcdata # Make sure you have the same patch version
(note: not sure how much that step helped since I had an error, but since it's part of what I did...)
Adding to my gemfile
gem 'ruby-prof', :git => 'git://github.com/wycats/ruby-prof.git'
gem 'test-unit'
And of course running
bundle install
Some reading that helped me
http://rubylearning.com/blog/2011/08/14/performance-testing-rails-applications-how-to/
https://rails.lighthouseapp.com/projects/8994/tickets/4171-fresh-rails-3-app-cannot-run-performance-tests
http://guides.rubyonrails.org/performance_testing.html#installing-gc-patched-mri

Paperclip + ImageMagick on Windows 7: Image display fails when I add styles to attached_file in model

I'm working with Ruby on rails 2.3.8, NetBeans IDE.
I've installed paperclip and I could show/save images successfully. Now, I've installed ImageMagick-6.6.2-4-Q16(for windows 7, 64bits).
Until that moment, my model looked like this(and worked fine):
has_attached_file :photo
Now, after installing ImageMagick, when I add the :style line it fails:
has_attached_file :photo,
:styles => {:thumb => "100x100#", :small => "150x150>", :large => "400x400>" }
and it throws the following error message when I try to upload an image:
TypeError in ProfilesController#update
backtrace must be Array of String
The only thing I'm doing in the update action of that controller is the following:
#profile.update_attributes(params[:profile])
#profile.update_attribute(:photo, params[:profile][:photo])
I've also installed miniMagick gem(because I read somewhere I had to do it).
What am I missing?
I'll show you what it worked for us:
There is a name conflict with "convert" command. Paperclips tries to run "convert" as is, but this command is already included in the Windows installations as a filesystem converter (FAT to NTFS or something).
If you try to run "convert" from command line, probably will run the mentioned converter instead of imagemagick's "convert"
It depends on the PATH environment variable.
If we set imagemagick's path FIRST in the PATH variable it will resolve this path first, so the windows' command won't be executed.
In order to fix it on our rails application, we added
...
if Sys::Uname.sysname == "Linux"
...
else
....
ENV['PATH'] = Paperclip.options[:command_path] + ";" + ENV['PATH']
end
...
on production.rb
Try to download the paperclip version 2.3.1.1, higher versions failed to me.

Resources