Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does it work with Alpine? #841

Closed
olegsobchuk opened this issue Jun 13, 2019 · 15 comments
Closed

Does it work with Alpine? #841

olegsobchuk opened this issue Jun 13, 2019 · 15 comments

Comments

@olegsobchuk
Copy link

I want to build Docker on Alpine image with Rails 5.2 + Ruby 2.6.
But seems like wkhtmltopdf-binary isn't compatible with linux Alpine, I installed wkhtmltopdf from Alpine sources, and it builds PDF, but without styles.

Is there any approach to use wicked_pdf on linux Alpine?

@unixmonkey
Copy link
Collaborator

In another issue, someone reported this wkhtmltopdf Alpine Docker container

And there are several posts on StackOverflow about it

Please come back and let us know what works for you!

@unixmonkey unixmonkey changed the title Does it work with Alpine Does it work with Alpine? Jun 13, 2019
@olegsobchuk
Copy link
Author

@unixmonkey I've tried almost all suggestions and it doesn't work for me... Unfortunately... I'm going to spend some time to find fix for my issue but seems like I'll migrate to Ubuntu

@tareksamni
Copy link

tareksamni commented Jul 2, 2019

I'm running it on Alpine3.8 and I guess it will work for any Alpine as follows:

FROM madnight/docker-alpine-wkhtmltopdf as wkhtmltopdf_image

FROM ruby:2.3.8-alpine3.8 # my parent docker image
# I do some staff here and then
COPY --from=wkhtmltopdf_image /bin/wkhtmltopdf /bin/

@kam1kaze
Copy link

If you do not see some fonts in generated PDF, you just need to install them. apk --update add ttf-ubuntu-font-family should be enough in most cases. More fonts here https://wiki.alpinelinux.org/wiki/Fonts

@mileszs
Copy link
Owner

mileszs commented Jul 22, 2019

It works on Alpine for us, as well. We've been running this in a production app for a few months. The top of our Dockerfile looks like this:

# stage 1
FROM madnight/docker-alpine-wkhtmltopdf:alpine-3.8 as base

# stage 2
FROM our-private-thing/ruby:2.6.2-alpine3.8.4

# copy over wkhtmltopdf apline binary
COPY --from=base /bin/wkhtmltopdf /usr/bin/wkhtmltopdf

# ... a bunch of other stuff, none of it wkhtmltopdf related I promise :-)

@kam1kaze
Copy link

We've migrated to new ruby docker version and started to use wkhtmltopdf from Alpine upstream. So our Dockefile looks like that:

FROM ruby:2.6.3-alpine

RUN apk --update add ttf-ubuntu-font-family wkhtmltopdf

...

and it works fine :)

@tareksamni
Copy link

It's irrelevant to ruby version. ruby:2.6.3-alpine is basically an alias to ruby:2.6.3-alpine3.10 which means you are running alpine3.10.

As per https://pkgs.alpinelinux.org/packages you can see that starting from 3.9 a new package is available and called wkhtmltopdf. while it was not available from 3.8 downwards.

@unixmonkey
Copy link
Collaborator

Closing this, as it appears to have been answered. Yes, it works with Alpine.
Thank you all who responded 🙇

@bo-oz
Copy link

bo-oz commented Feb 21, 2020

I followed instructions here to incorporate WickedPDF in a docker image, but I keep getting this strange error from time to time. Sometimes the PDF is generated, other times it exits with:

Command Error: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

Any ideas how to overcome?

@unixmonkey
Copy link
Collaborator

@bo-oz wkhtmltopdf uses QT to render sometimes, and that appears to sometimes need to write to a temporary directory. Is /tmp not writable by the user your app runs as in your image?

I think you might fix this by either granting write permission to /tmp, or setting the $XDG_RUNTIME_DIR environment variable to somewhere it can write.

I'm not sure this is the reason the command errors though. This sounds like just a warning, unless it can't write to /tmp. Is there more to those messages than you pasted here?

@bo-oz
Copy link

bo-oz commented Feb 21, 2020

I think this error had to do with the font pack that wasn’t installed. But the issue still persists, it seems that the call that lets WickedPDF write a string to a HTML file to the tmp folder seems to fail from time to time. The error is coming from wkhtmltopdf that isn’t able to access the file or it is missing entirely. Trying to do some more debugging tomorrow.

@bo-oz
Copy link

bo-oz commented Feb 24, 2020

After debugging some more, I found that the command that addresses wkhtmltopdf, seems to fail from time to time with signal 11. Any ideas what that could mean? Could it be a rights issue accessing the file in the temp dir?

This is the line that sometimes raises the error: Open3.popen3(*command) on line 68 in lib/wicked_pdf.rb

@bo-oz
Copy link

bo-oz commented Feb 24, 2020

Ok, finally found the issue. When calling pdf_from_string before the actual pdf is rendered, there's an intermittent call to pdf_from_html_file to add file:/// before the temporary filename. When using this gem inside my Alpine, this results in an error: Failed to load file:///tmp/wicked_pdf20200224-11365-1k7clri.html, with network status code 203 and http status code 0

When I "monkeypatch" the method to the following, it does work like a charm:

  def pdf_from_html_file(filepath, options = {})
    pdf_from_url(filepath, options)
  end

Is there a reason that you are adding this file:/// to the path? Would you consider a PR in which I add an option to skip this call?

Edit: Same problems exist when attaching header/footer htlml, since the file:/// is hardcoded in the method prerender_header_and_footer in /lib/wicked_pdf/pdf_helper.rb. Also the options param is not passed into the WickedPdfTempFile. Trying to create a PR for this. Any suggestions for the name of the option?

@bo-oz
Copy link

bo-oz commented Feb 24, 2020

Created PR #889 to have a way to solve the issue above.

@thisismydesign
Copy link

Simply installing wkhtmltopdf and pointing the gem to the binary didn't work for me.

Command Error: The switch --footer-left, is not support using unpatched qt, and will be ignored.The switch --footer-right, is not support using unpatched qt, and will be ignored.The switch --footer-font-size, is not support using unpatched qt, and will be ignored.The switch --footer-spacing, is not support using unpatched qt, and will be ignored.QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

Instead, I needed to copy from madnight/docker-alpine-wkhtmltopdf as also proposed before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants