Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions FLY_HOSTING_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,47 @@ to make sure Chrome is installed via Docker and running with the --no-sandbox fl
First, add these dependencies to the Dockerfile used when deploying to Fly.io.

```
ENV DOCKER_BUILD=1
RUN apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
chromium chromium-sandbox fonts-liberation libappindicator3-1 xdg-utils && \
rm -rf /var/lib/apt/lists/* /var/cache/apt
```

I've also set `DOCKER_BUILD`, so the initializer is skipped when building the
image (FerrumPdf will timeout since Chrome is not yet installed).

## Initialize with options

Fly.io does not allow Chrome to run in sandbox mode, so we need to disable it.

Additionally, in my testing, setting browser options via FerrumPdf did not work
as expected once deployed. In production, we need to initialize Ferrum::Browser directly and
set it directly in FerrumPdf.

```ruby
# config/initializers/ferrum.rb

return if ENV['DOCKER_BUILD']

options = {
process_timeout: 30,
browser_options: {
'no-sandbox' => nil
}
}

options = options.merge(browser_path: '/usr/bin/chromium') if Rails.env.production?

FerrumPdf.browser(options)
if Rails.env.production?
require 'ferrum'

FERRUM_BROWSER = Ferrum::Browser.new(
browser_options: {
"no-sandbox" => true,
"headless" => "new"
},
process_timeout: 30,
browser_path: '/usr/bin/chromium'
)

# Configure FerrumPdf to use our browser instance
module FerrumPdf
class << self
def browser
FERRUM_BROWSER
end
end
end
end
```

Additionally, increasing the process timeout avoids code reloading issues in
Increasing the process timeout avoids code reloading issues in
development as detailed here: [Possibility to set Ferrum timeout to overcome code reloading issues in Development](https://github.com/excid3/ferrum_pdf/issues/5).

`fly deploy` these changes, confirm the build step succeeds and FerrumPdf generates pdfs as expected.
Loading