rposborne/wkhtmltopdf-heroku

Support Heroku-22 stack

Closed this issue ยท 26 comments

Heroku-22 Stack has been released and it breaks the wkhtmltopdf-heroku gem with the following error message:

Failed to execute:
["/app/vendor/bundle/ruby/3.1.0/gems/wkhtmltopdf-heroku-2.12.6.0/bin/wkhtmltopdf-linux-amd64", "--page-size", "Letter", "file:////tmp/wicked_pdf20220622-6-3pxuf2.html", "/tmp/wicked_pdf_generated_file20220622-6-ko5r5s.pdf"]
Error: PDF could not be generated! Command Error: /app/vendor/bundle/ruby/3.1.0/gems/wkhtmltopdf-heroku-2.12.6.0/bin/wkhtmltopdf-linux-amd64: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

Heroku explains this with:

OpenSSL 3
Ubuntu 22.04 ships with OpenSSL 3.0. OpenSSL 1.1 is not available as a runtime library.

If you see OpenSSL/libssl related errors (for example libssl.so.1.1: cannot open shared object file, but there will be many other variations), you will need to update your dependencies and/or third-party buildpacks to a version that is compatible with OpenSSL 3, and ensure that dependencies or binaries you use are compiled against OpenSSL 3.

In addition, OpenSSL 3 drops default support for a number of legacy/insecure cryptographic algorithms. If you see TLS/SSL related failures connecting from your application to external services, it is likely that those servers are running outdated/insecure software or configurations, that will need to be fixed by the maintainers of those services.

@pallymore tell me if I can help by suggesting a PR ๐Ÿ™

hmm this is tricky. I don't think that's something we can resolve in this repository - this gem simply ships the binary from https://github.com/wkhtmltopdf/wkhtmltopdf , unfortunately that repo is in a semi-abandoned state.

We could try to compile a binary from source with openssl 3 but it still might not work due to the breaking changes mentioned in the article ๐Ÿค”

Looks like someone has already compiled a binary for Ubuntu 22: wkhtmltopdf/packaging#114

testing that shortly.

Hi - I think it actually works - here's a test page:

https://wkhtmltopdf-demo.herokuapp.com/greetings/hello.pdf

could you test this on your end also? here's my test "app":
https://github.com/pallymore/wkhtmltopdf-test

could you try it with: https://github.com/pallymore/wkhtmltopdf-test/blob/main/Gemfile#L29

gem 'wkhtmltopdf-heroku',  git: 'https://github.com/rposborne/wkhtmltopdf-heroku.git', branch: '2.12.6.0-jammy'

@pallymore there's an official release for 22.04 published just now.

thanks - checking if those binaries work ๐Ÿค”

Hi @ashkulz - the latest release does not work on Heroku-22.
I'm getting the same libssl 1.1 error - for now i've reverted the binary back: https://github.com/rposborne/wkhtmltopdf-heroku/commits/2.12.6.0-jammy

@guillaumewrobel please let me know if that branch works for you:

gem 'wkhtmltopdf-heroku',  git: 'https://github.com/rposborne/wkhtmltopdf-heroku.git', branch: '2.12.6.0-jammy'

@pallymore yeah, there were some issues and I've deleted the release.

@pallymore the 2.12.6.0-jammy branch works well ๐Ÿ‘

awesome, for now i've published the branch as version 2.12.6.0.pre.jammy until an official binary is available.

https://rubygems.org/gems/wkhtmltopdf-heroku/versions/2.12.6.0.pre.jammy

@pallymore please check again with the latest build.

Hi @ashkulz the latest release works! thank you!

Released: https://rubygems.org/gems/wkhtmltopdf-heroku/versions/2.12.6.1.pre.jammy

Thanks!

Is there going to be a Ubuntu 20 (Focal) AMD64 build?

@pallymore there is already a Ubuntu 20.04 build which was part of the original 0.12.6 release ... not sure what you mean? ๐Ÿค”

nvm, I thought this release is for 0.12.6.1 and the original release was 0.12.6.0 ๐Ÿ˜… we are good here if they are built from the same source.

thank you again.

Yeah, the only changes in the 0.12.6.x branch is some fixes to get it working with newer compiler versions.

Hi there, not sure if anyone will see this but I just upgraded my heroku to 22 stack and tried to add the experimental gem to my gemfile and redeploy but I am still getting the same error. I might be missing something can anyone help?

gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
gem 'wkhtmltopdf-heroku', '2.12.6.1.pre.jammy' # experimental support for heroku stack 22

@toddsutt I see you are using both wkhtmltopdf-binary and wkhtmltopdf-heroku
I'd check which one is being picked up by wicked_pdf

I'd recommend keeping wkhtmltopdf-binary in the :development and :test gem group, and only use wkhtmltopdf-heroku in production.

@pallymore thank you for the response! As you can see, I don't understand what these gems are doing, so I will give that a try!

@pallymore after your suggestion I get this error on heroku:

Command Error: /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.10/lib/bundler/rubygems_integration.rb:319:in `block in replace_bin_path': can't find executable wkhtmltopdf for gem wkhtmltopdf-binary. wkhtmltopdf-binary is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)

yea looks like it's still trying to find wkhtmltopdf-binary - I'd check where it is still referenced in the code.
what's in your wicked_pdf config file?

@pallymore again, thank you so much for helping me I really appreciate it.

Here is the relevant part of my gemfile:

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'wkhtmltopdf-binary'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise'
gem 'jquery-rails'
gem 'haml-rails'
gem 'font-awesome-rails', '~> 4.7.0'
gem 'will_paginate'
gem 'wicked_pdf'
gem 'wkhtmltopdf-heroku', '2.12.6.1.pre.jammy' # experimental support for heroku stack 22

wicked_pdf.rb is completely default:

# WickedPDF Global Configuration
#
# Use this to set up shared configuration options for your entire application.
# Any of the configuration options shown here can also be applied to single
# models by passing arguments to the `render :pdf` call.
#
# To learn more, check out the README:
#
# https://github.com/mileszs/wicked_pdf/blob/master/README.md

WickedPdf.config = {
  # Path to the wkhtmltopdf executable: This usually isn't needed if using
  # one of the wkhtmltopdf-binary family of gems.
  # exe_path: '/usr/local/bin/wkhtmltopdf',
  #   or
  # exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')

  # Layout file to be used for all PDFs
  # (but can be overridden in `render :pdf` calls)
  # layout: 'pdf.html',

  # Using wkhtmltopdf without an X server can be achieved by enabling the
  # 'use_xvfb' flag. This will wrap all wkhtmltopdf commands around the
  # 'xvfb-run' command, in order to simulate an X server.
  #
  # use_xvfb: true,
}

Do I need to do something to uninstall the binary gem from heroku after moving it to development? Like delete my Gemfile.lock?

Sorry for the late response - in regards to the lock file, yea you will need to run bundle install after making the gemfile changes, and commit the new lock file.

I'd search wkhtmltopdf-binary in the codebase to see if it's still being referenced somewhere - assuming you've set the environment to production on Heroku, only wkhtmltopdf-heroku gem should be loaded.

also could you DM me on twitter we can continue there if you are still having issues: https://twitter.com/Yuruiology ๐Ÿ‘‹๐Ÿป

@pallymore I finally figured it out! Btw I couldn't message you on twitter it said I was unable to send messages even after following.

I tried a whole lot of things but it ended up just being that I needed to add exe_path: Gem.bin_path('wkhtmltopdf-heroku', 'wkhtmltopdf-linux-amd64') to my WickedPdf.config for production environment.

great - I don't think exe_path is needed as this gem configures that for you automatically.

however I think I know the problem now - in your config you had:

WickedPdf.config = {
}

which overrides the whole config object - in the README file, it's recommended to extend the config instead
(see https://github.com/rposborne/wkhtmltopdf-heroku#when-using-with-wicked_pdf )

WickedPdf.config ||= {}
WickedPdf.config.merge!({
  # your extra configurations here
})

this should eliminate the needs of having to set an exe_path manually.