0

I'm using the wicked_pdf gem to render a pdf from an html template in Rails. While on localhost it works on the production environment (a docker image running in AWS ECS via Fargate) the export endpoint returns an error. The error is caused by the wkhtmltopdf binary:

["/usr/local/bundle/bin/wkhtmltopdf", "--enable-local-file-access", "--dpi", "80", "--margin-bottom", "1", "--header-html", "file:////tmp/wicked_header_pdf20230901-1-log5m3.html", "file:////tmp/wicked_pdf20230901-1-pxi12g.html", "/tmp/wicked_pdf_generated_file20230901-1-wa7ysm.pdf"]
Error: PDF could not be generated!
 Command Error: Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
Error: Failed to load file:////tmp/wicked_header_pdf20230901-1-log5m3.html, with network status code 203 and http status code 0 - Error opening //tmp/wicked_header_pdf20230901-1-log5m3.html: No such file or directory
Error: Failed loading page file:////tmp/wicked_header_pdf20230901-1-log5m3.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: ContentNotFoundError

How can I solve this? The only difference is that locally it runs natively, in docker using wkhtmltopdf-binary gem.

Fabrizio Mele
  • 229
  • 2
  • 15

1 Answers1

0

I fixed the problem by setting ENV TMPDIR=/tmp inside the Dockerfile. For some reason it is not set in the ruby:x.x.x-slim Docker image, and I believe Rails is not able to resolve temp paths correctly without it.

After setting it everything works correctly.

Fabrizio Mele
  • 229
  • 2
  • 15