I am using the ruby-zbar gem in a rails app to scan barcodes from jpgs. I installed the zbar library using homebrew on my local machine and everything works fine. However, when deploying to Heroku I consistently get errors such as the following:
remote: LoadError: Didn't find libzbar on your system
remote: Please install zbar (http://zbar.sourceforge.net/) or set ZBAR_LIB if it's in a weird place
remote: FFI::Library::ffi_lib() failed with error: library names list must not be empty
I've tried following the advice from this Stack Overflow post (Heroku Zbar Didn't find libzbar on your system (LoadError)), namely to set the ZBAR_LIB ENV variable to /app/vendor/lib/libzbar.so, or failing that to run heroku bash and try to find a file named libzbar.so and point ZBAR_LIB to its path.
However, I can't seem to find the heroku buildpack referenced in the original Stack Overflow post (the link to https://github.com/ballantyne/heroku-buildpack-zbar goes to a 404 page), so I can't replicate the solution outlined there.
I have tried all of the following buildpacks:
https://github.com/generalui/heroku-buildpack-zbar
https://github.com/robert-wallis/heroku-buildpack-zbar
https://github.com/robert-wallis/heroku-buildpack-zbar/tree/patch-1
During the build process I can see hopeful messages like this:
remote: -----> Multipack app detected
remote: -----> Fetching custom git buildpack... done
remote: -----> ZBAR app detected
remote: -----> Downloading and installing ZBAR
remote: -----> Configuring ZBAR
remote: -----> Make!
remote: -----> Make install !!!
remote: -----> Writing profile script
remote: -----> Fetching custom git buildpack... done
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.1
But setting ZBAR_LIB to /app/vendor/lib/libzbar.so gives me some version of this error:
remote: LoadError: Didn't find libzbar on your system
remote: Please install zbar (http://zbar.sourceforge.net/) or set ZBAR_LIB if it's in a weird place
remote: FFI::Library::ffi_lib() failed with error: Could not open library '/app/vendor/lib/libzbar.so': /app/vendor/lib/libzbar.so: cannot open shared object file: No such file or directory
And trying to find libzbar.so on heroku run bash has not been successful for me -- I can see many files that are similar in name (even a libzbar.rc) but none that fits the bill.
~ $ find / -name '*libzbar*'
find: `/var/lib/polkit-1': Permission denied
/app/vendor/zbar/plugin/.deps/plugin_libzbarplugin_la-plugin.Plo
/app/vendor/zbar/qt/.deps/qt_libzbarqt_la-QZBar.Plo
/app/vendor/zbar/qt/.deps/qt_libzbarqt_la-QZBarThread.Plo
/app/vendor/zbar/qt/.deps/qt_libzbarqt_la-moc_QZBarThread.Plo
/app/vendor/zbar/qt/.deps/qt_libzbarqt_la-moc_QZBar.Plo
/app/vendor/zbar/gtk/.deps/gtk_libzbargtk_la-zbargtk.Plo
/app/vendor/zbar/gtk/.deps/gtk_libzbargtk_la-zbarmarshal.Plo
/app/vendor/zbar/zbar/zbar_libzbar_la-symbol.lo
/app/vendor/zbar/zbar/zbar_libzbar_la-video.o
/app/vendor/zbar/zbar/zbar_libzbar_la-error.lo
/app/vendor/zbar/zbar/processor/zbar_libzbar_la-lock.lo
/app/vendor/zbar/zbar/processor/.libs/zbar_libzbar_la-lock.o
/app/vendor/zbar/zbar/processor/zbar_libzbar_la-lock.o
/app/vendor/zbar/zbar/processor/.deps/zbar_libzbar_la-null.Plo
/app/vendor/zbar/zbar/processor/.deps/zbar_libzbar_la-x.Plo
/app/vendor/zbar/zbar/processor/.deps/zbar_libzbar_la-posix.Plo
/app/vendor/zbar/zbar/processor/.deps/zbar_libzbar_la-lock.Plo
/app/vendor/zbar/zbar/processor/.deps/zbar_libzbar_la-win.Plo
/app/vendor/zbar/zbar/zbar_libzbar_la-config.o
/app/vendor/zbar/zbar/zbar_libzbar_la-processor.o
/app/vendor/zbar/zbar/zbar_libzbar_la-refcnt.lo
/app/vendor/zbar/zbar/zbar_libzbar_la-convert.o
/app/vendor/zbar/zbar/zbar_libzbar_la-video.lo
/app/vendor/zbar/zbar/zbar_libzbar_la-window.o
/app/vendor/zbar/zbar/video/.deps/zbar_libzbar_la-null.Plo
/app/vendor/zbar/zbar/video/.deps/zbar_libzbar_la-v4l1.Plo
/app/vendor/zbar/zbar/video/.deps/zbar_libzbar_la-v4l2.Plo
/app/vendor/zbar/zbar/video/.deps/zbar_libzbar_la-vfw.Plo
/app/vendor/zbar/zbar/zbar_libzbar_la-processor.lo
/app/vendor/zbar/zbar/zbar_libzbar_la-image.lo
/app/vendor/zbar/zbar/zbar_libzbar_la-refcnt.o
/app/vendor/zbar/zbar/zbar_libzbar_la-error.o
/app/vendor/zbar/zbar/qrcode/.deps/zbar_libzbar_la-qrdectxt.Plo
/app/vendor/zbar/zbar/qrcode/.deps/zbar_libzbar_la-binarize.Plo
/app/vendor/zbar/zbar/qrcode/.deps/zbar_libzbar_la-isaac.Plo
/app/vendor/zbar/zbar/qrcode/.deps/zbar_libzbar_la-rs.Plo
/app/vendor/zbar/zbar/qrcode/.deps/zbar_libzbar_la-qrdec.Plo
/app/vendor/zbar/zbar/qrcode/.deps/zbar_libzbar_la-bch15_5.Plo
/app/vendor/zbar/zbar/qrcode/.deps/zbar_libzbar_la-util.Plo
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-video.o
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-config.o
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-processor.o
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-convert.o
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-window.o
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-refcnt.o
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-error.o
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-img_scanner.o
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-image.o
/app/vendor/zbar/zbar/.libs/zbar_libzbar_la-symbol.o
/app/vendor/zbar/zbar/zbar_libzbar_la-img_scanner.o
/app/vendor/zbar/zbar/zbar_libzbar_la-image.o
/app/vendor/zbar/zbar/window/.deps/zbar_libzbar_la-null.Plo
/app/vendor/zbar/zbar/window/.deps/zbar_libzbar_la-dib.Plo
/app/vendor/zbar/zbar/window/.deps/zbar_libzbar_la-xv.Plo
/app/vendor/zbar/zbar/window/.deps/zbar_libzbar_la-x.Plo
/app/vendor/zbar/zbar/window/.deps/zbar_libzbar_la-ximage.Plo
/app/vendor/zbar/zbar/window/.deps/zbar_libzbar_la-win.Plo
/app/vendor/zbar/zbar/zbar_libzbar_la-img_scanner.lo
/app/vendor/zbar/zbar/libzbar.rc
/app/vendor/zbar/zbar/zbar_libzbar_la-symbol.o
/app/vendor/zbar/zbar/zbar_libzbar_la-config.lo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-decoder.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-config.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-convert.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-processor.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-symbol.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-scanner.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-error.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-jpeg.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-video.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-window.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-refcnt.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-svg.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-img_scanner.Plo
/app/vendor/zbar/zbar/.deps/zbar_libzbar_la-image.Plo
/app/vendor/zbar/zbar/zbar_libzbar_la-window.lo
/app/vendor/zbar/zbar/decoder/.deps/zbar_libzbar_la-code39.Plo
/app/vendor/zbar/zbar/decoder/.deps/zbar_libzbar_la-pdf417.Plo
/app/vendor/zbar/zbar/decoder/.deps/zbar_libzbar_la-qr_finder.Plo
/app/vendor/zbar/zbar/decoder/.deps/zbar_libzbar_la-i25.Plo
/app/vendor/zbar/zbar/decoder/.deps/zbar_libzbar_la-ean.Plo
/app/vendor/zbar/zbar/decoder/.deps/zbar_libzbar_la-code128.Plo
/app/vendor/zbar/zbar/zbar_libzbar_la-convert.lo
Has anyone had success getting zbar to run on heroku? If so, what buildpack did you use? I would be thrilled to learn how to make this work.
This is what ultimately worked for me:
1) I needed to use the apt-buildpack and the ruby buildpack in tandem.
Command line:
heroku buildpacks
https://github.com/ddollar/heroku-buildpack-apt
https://github.com/heroku/heroku-buildpack-ruby
2) Then I created a file called Aptfile (no extension), placed it at the root of my project folder, and the only line in it is:
Aptfile:
libzbar-dev
Finally, I had to not require zbar in my gemfile, and require it separately in the code where I was processing the barcode:
Gemfile:
gem 'zbar', :require => false
Controller:
class HomeController < ApplicationController
require 'zbar'
def index
path = "#{Rails.public_path}/barcode.jpg"
jpeg = File.binread(path)
z = ZBar::Image.from_jpeg(jpeg)
r = z.process
#barcode = r.first.data
end
end
I was having a really tough time getting not just Heroku to use the right Zbar, but Circle CI as well. I tried using Apt on the CI server to get the dev version, but could not get it working because of weird dependency issues. I ended up creating a heroku buildpack to take care of patching and building the right version, and I wrote a script to get the CI server to do the same.
Heroku:
https://github.com/sheck/heroku-buildpack-zbar
Circle CI:
https://gist.github.com/sheck/475e0c8f2d9f618f1eca
andy they have a success stories coming out of here check it out
https://github.com/willglynn/ruby-zbar/issues/8
Related
Ruby 2.7.4
Rails 6.1.4.1
note: in package.json the engines key is missing in my app
Heroku fails during build with this error
this commit is an empty commit on top of exactly a SHA that I was successful at pushing yesterday (I've checked twice now) so I suspect this is a platform problem or somehow the node-sass got deprecated or yanked yesterday?
how can I fix this?
remote:
remote: ERROR in ./app/javascript/require_bootstrap.scss
remote: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
remote: ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
**remote: Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (93)**
remote: For more information on which environments are supported please see:
remote: https://github.com/sass/node-sass/releases/tag/v4.14.1
remote: at module.exports (/tmp/build_1c436dcf/node_modules/node-sass/lib/binding.js:13:13)
remote: at Object.<anonymous> (/tmp/build_1c436dcf/node_modules/node-sass/lib/index.js:14:35)
remote: at Module._compile (/tmp/build_1c436dcf/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
remote: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
Heroku switched the default Node from 14 to 16 in Dec 2021 for the Ruby buildpack .
Heroku updated the heroku/ruby buildpack Node version from Node 14 to Node 16 (see https://devcenter.heroku.com/changelog-items/2306) which is not compatible with the version of Node Sass locked in at the Webpack version you're likely using.
To fix it do these two things:
Specify the 14.x Node version in package.json.
# In package.json
{
# ...
"engines": {
"node": "14.x"
},
# ...
}
Add the heroku/nodejs buildpack before the heroku/ruby buildpack. You can do this in the web interface or with the command line. Here is the command for the CLI:
$ heroku buildpacks:add heroku/nodejs -i 1 -a YOUR-APP-NAME
With the NodeJS buildpack running first, it will look at the package.json file and respect that when choosing which version of Node to install. Then the Ruby buildpack will run and since a version of Node already exists it will just use that and everything should work as before.
The solution to this problem was quite different in my situation. Updating the webpacker gem from 3.5.5 to 5.4.3 made the error disappear.
Our deploys started failing to heroku yesterday and I can't figure out why, nothing in our codebase changed related to the build/dependencies. I've been trying to debug it and use different combinations of buildpacks for a day now and cant seem to figure it out. Heroku support hasn't been able to help me either.
Essentially it errors out when it goes to install node. Ive tried every version of node and various buildpacks. Prior to the builds failing we werent specifying our versions in the package.json, but I tried doing this with all the different combinations and still no luck. The deploy breaks at this point:
remote: Resolving node version 12.x...
remote: Error: Unknown error installing "12.x" of node
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
Let me know any information I could provide or debugging ideas anyone might have, thanks in advance!
The problem was the QuotaGuard Static IP's Add-On which was prompting us to upgrade, we upgraded and then our deploys started breaking likely because of a cached environment variable on the heroku side for HTTPS_PROXY. I removed this variable and the build worked.
On Heroku, I would like to use Rails 6.0 with Active Storage and VIPS for fast and low memory image transformation.
I tried following the instructions here https://github.com/janko/image_processing/issues/32, but the build fails:
-----> vips app detected
-----> Vendoring binaries
Fetching wget https://kespry-packages.s3.amazonaws.com/vips/heroku-18/libvips-8.6.2.tgz
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
! Push rejected, failed to compile vips app.
! Push failed
I had these buildpacks in place:
heroku-community/apt
https://github.com/zoras/heroku-buildpack-libvips
What buildpacks am I recommended to use?
If none exists, how would I go about adding VIPS support for a Heroku buildpack?
This one works well:
https://github.com/brandoncc/heroku-buildpack-vips
Though note that you should bump the libvips version it uses -- it's still on 8.7.1 as I write.
I tried deploying it multiple times but got the same error. I'm new to ruby on rails and have no idea how to solve it. I tried cloning it locally and changing the file to read "config.assets.compile = false" instead of true. That didn't work either. Any ideas? Here's the link to the git repository I'm trying to download. Let me know if I need to be more specific about anything. Thanks for all the help!
There was an issue building your app. This can mean your app.json's project is not a valid Heroku application. Please ensure your app is deployable to Heroku and try again.
-----> Installing node-v8.10.0-linux-x64
Detected manifest file, assuming assets were compiled locally
-----> Detecting rails configuration
sh: 2: config.assets.compile: not found
!
! A security vulnerability has been detected in your application.
! To protect your application you must take action.
Your application
! is currently exposing its credentials via an easy to exploit
directory
! traversal.
!
! To protect your application you must either upgrade to
Sprockets version "3.7.2"
! or disable dynamic compilation at runtime by setting:
!
! ! config.assets.compile = false # Disables security
vulnerability !
!
! Push rejected, failed to compile Ruby app.
! Push failed
This should work:
bundle update sprockets
Alternatively to updating sprockets with bundle update sprockets, you can disable config.assets.compile in config/environments/production.rb.
For more information, Heroku published a very detailed blog post on this subject: https://blog.heroku.com/rails-asset-pipeline-vulnerability
I'm trying to get the image_optim gem to work with a Rails 4 app on Heroku's Cedar stack to optimize png/gif/jpeg images.
I threw the required binaries (advpng, gifsicle, jpegoptim, jpegtran, optipng, pngcrush, pngout) into /bin and set ENV['PATH'] = "#{Rails.root}/bin:#{ENV['PATH']}" in an initializer. This works for gifs and pngs, but I'm running into problems with jpegs.
In the rails console I get:
irb(main):001:0> `jpegoptim`
jpegoptim: error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory
How should I go about installing libjpeg on Heroku?
The correct way to deploy binaries to Heroku is to use buildpacks:
https://devcenter.heroku.com/articles/buildpacks
Use this one if you want to package up multiple binaries:
https://github.com/ddollar/heroku-buildpack-multi
There are a number of buildpacks already created for various binaries, but none for the ones you have listed.
I have created a gem that allows you to run image_optim on heroku:
https://github.com/mooktakim/image_optim_bin
You're probably looking for this: Heroku Image-Optim Buildpack
Or this: https://github.com/bobbus/image-optim-buildpack