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

Generate PDFs with chromium, remove wicked_pdf #453

Merged
merged 19 commits into from
Apr 20, 2018
Merged

Conversation

wioux
Copy link
Member

@wioux wioux commented Apr 10, 2018

wkhtmltopdf has more limitations and bugs (links in our PDFs are not clickable!), and we also have issues with having to keep an xvfb display running in our container.

As mentioned in #447 ideally we would have chrome running in a separate container. Right now the chrome-headless-render-pdf package I'm using doesn't support connecting to a remote instance but it looks like an easy-ish patch we could make. I intend to follow up on it but meanwhile I think we are somewhat better off running chrome headless rather than xvfb + wicked_pdf.

Depends on #450

@wioux wioux changed the title Generate PDFs with chrome headless, removes wicked_pdf Generate PDFs with chromium, remove wicked_pdf Apr 10, 2018
Copy link
Contributor

@k-stewart k-stewart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🌮

@@ -4,7 +4,6 @@ namespace :pdfs do
task recreate: :environment do
Lesson.published.find_each do |lesson|
UpdateLessonPdf.perform_now(lesson.id)
sleep 0.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

at_least(:once)

html = %(<a href="/relative">anchor</a>")
expect(pdf_template.send(:rebase_urls, html)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it necessary to send :rebase_urls?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a private method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, maybe consider finding some other way to test? One of the only purposes of making a method private is to tell coders that it's not a reliable feature of the object's public interface. The internet is divided over this, but that's how I was taught.

@wioux
Copy link
Member Author

wioux commented Apr 11, 2018

@vbrown608 For now I'd like to take the --no-sandbox approach and add a seccomp profile later on if/when we move the chromium process to a separate container.

def print_pdf(input)
output = Tempfile.new(["pdf", ".pdf"])
chrome_wrapper = Rails.root.join("bin/chrome-stub").to_s
command = ["timeout", "-t", "5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls use Ruby's timeout instead, for cross-platform compatibility!

@@ -28,6 +29,7 @@ RUN echo "@edge http://nl.alpinelinux.org/alpine/edge/main" >>/etc/apk/repositor

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove xvfb and wkhtmltopdf@edgetesting from the Dockerfile?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Good idea.


#main-content {
margin-top: 65px;
}
Copy link
Collaborator

@vbrown608 vbrown608 Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some styles aren't getting picked up when I test this locally and the image doesn't seem to be coming through. The font size (or maybe weight?) also seems a bit heavy. I'm not sure if this is unique to my setup, maybe we can check in about it on Monday.

pdf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a change to inline the stylesheet and use a data URI for the header image, which should be more reliable.

@wioux
Copy link
Member Author

wioux commented Apr 19, 2018

This is ready for review again. I switched to a different node library, which doesn't have the problem with stalling jobs (though I'm keeping it wrapped in a timeout block just in case). It also has better support for printing from an existing/remote chrome process (instead of spawning a new one each time) so we should be able to follow up soon with moving the browser to its own container.

@vbrown608 vbrown608 merged commit d5400b5 into master Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants