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

Heroku example for the Deployment Guide #235

Merged
merged 4 commits into from
Apr 16, 2024
Merged
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
49 changes: 47 additions & 2 deletions guides/deployment/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ hostname = File.basename(__dir__)
service hostname do
include Falcon::Environment::Rack
include Falcon::Environment::LetsEncryptTLS

# Insert an in-memory cache in front of the application (using async-http-cache).
cache true
end
Expand All @@ -50,7 +50,7 @@ hostname = File.basename(__dir__)
service hostname do
include Falcon::Environment::Rack
include Falcon::Environment::LetsEncryptTLS

endpoint do
Async::HTTP::Endpoint.parse('http://localhost:3000').with(protocol: Async::HTTP::Protocol::HTTP2)
end
Expand All @@ -63,6 +63,51 @@ end

You can verify this is working using `nghttp -v http://localhost:3000`.

#### Application Configuration Example for Heroku

Building on the examples above, the following is a full configuration example for Heroku:

~~~ bash
# Procfile

web: bundle exec falcon host
~~~

~~~ ruby
# falcon.rb

#!/usr/bin/env -S falcon host

load :rack

hostname = File.basename(__dir__)
port = ENV["PORT"] || 3000

service hostname do
include Falcon::Environment::Rack

# By default, Falcon uses Etc.nprocessors to set the count, which is likely incorrect on shared hosts like Heroku.
# Review the following for guidance about how to find the right value for your app:
# https://help.heroku.com/88G3XLA6/what-is-an-acceptable-amount-of-dyno-load
# https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#workers
count ENV.fetch("WEB_CONCURRENCY", 1).to_i

# If using count > 1 you may want to preload your app to reduce memory usage and increase performance:
preload "preload.rb"

# Heroku only supports HTTP/1.1 at the time of this writing. Review the following for possible updates in the future:
# https://devcenter.heroku.com/articles/http-routing#http-versions-supported
# https://github.com/heroku/roadmap/issues/34
endpoint Async::HTTP::Endpoint.parse("http://0.0.0.0:#{port}").with(protocol: Async::HTTP::Protocol::HTTP11)
end
~~~

~~~ ruby
# preload.rb

require_relative "config/environment"
~~~

## Falcon Virtual

Falcon can replace Nginx as a virtual server for Ruby applications.
Expand Down
Loading