ruby-on-railswkhtmltopdfubuntu-18.04dokku

How to fix 'Error while loading shared libraries: libpng12.so.0' (on dokku)


I'm having some trouble while trying to generate an pdf through the pdf_from_url method on production. The error is the following:

Error: PDF could not be generated!
 Command Error: /app/vendor/bundle/ruby/2.5.0/gems/wkhtmltopdf-binary-edge-0.12.5.0/libexec/wkhtmltopdf-linux-amd64: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

The line bellow throws the error above:

   pdf = WickedPdf.new.pdf_from_url("https://google.com", {:temp_path => Rails.root.join('public')})

The error only occurs on production. Everything works normaly on development.

Running wkhtmltopdf https://google.com test.pdf via command line on the server works normally.

One thing to notice is that my application server runs on a dokku container, which i'm inexperienced in. So, probably the error occurs due to the way of how dokku's file architeture works.

What i have already tried:

  1. Changed wkhtmltopdf's gem from wkhtmltopdf-binary to wkhtmltopdf-binary-edge
  2. Installed libpng12 manualy on the server (not on dokku container)

What i'm using currently:

wicked_pdf gem version: 1.1.0

whtmltopdf [provider gem]: wkhtmltopdf-binary-edge ~> 0.12.5

platform/distribution and version: Dokku container running on Ubuntu 18.04


Solution

  • I managed to solve that problem by using dokku-apt plugin to install the libpng12.

    First, install the dokku-apt plugin on your dokku container:

    sudo dokku plugin:install https://github.com/F4-Group/dokku-apt
    

    Then, create a file named apt-packages on your root project directory and insert the name of the lib like:

    libpng12-0
    

    After that, create another file named apt-repositories on your root project directory and insert the following line to update your repositories: (remember to leave an empty line on the end of the file)

    deb http://security.ubuntu.com/ubuntu xenial-security main
    
    

    At last, commit and deploy those files to your dokku container and it should work.