|
| 1 | +# Deployment |
| 2 | + |
| 3 | +This guide explains how to use Falcon in production environments. |
| 4 | + |
| 5 | +Falcon can be deployed into production either as a standalone application server, or as a virtual host routing to multiple applications. Both configurations can run behind a load balancer, but `falcon virtual` is designed to be zero-configuration deployment option. |
| 6 | + |
| 7 | +## Falcon Serve |
| 8 | + |
| 9 | +`falcon serve` is not designed for deployment because the command line interface is not guaranteed to be stable nor does it expose every possible configuration option. |
| 10 | + |
| 11 | +## Falcon Hosts |
| 12 | + |
| 13 | +`falcon host` is designed for deployment, and is the recommended way to deploy Falcon in production. It exposes a well defined interface for configuring services (web applications, job servers, etc). |
| 14 | + |
| 15 | +### Configuration |
| 16 | + |
| 17 | +`falcon host` loads configuration from the `falcon.rb` file in your application directory. This file contains configuration blocks which define how to host the application and any related services. This file should be executable and it invokes `falcon-host` which starts all defined services. |
| 18 | + |
| 19 | +Here is a basic example which hosts a rack application using : |
| 20 | + |
| 21 | +~~~ ruby |
| 22 | +#!/usr/bin/env falcon-host |
| 23 | +# frozen_string_literal: true |
| 24 | + |
| 25 | +require "falcon/environment/rack" |
| 26 | +require "falcon/environment/lets_encrypt_tls" |
| 27 | +require "falcon/environment/supervisor" |
| 28 | + |
| 29 | +hostname = File.basename(__dir__) |
| 30 | +service hostname do |
| 31 | + include Falcon::Environment::Rack |
| 32 | + include Falcon::Environment::LetsEncryptTLS |
| 33 | + |
| 34 | + # Insert an in-memory cache in front of the application (using async-http-cache). |
| 35 | + cache true |
| 36 | +end |
| 37 | + |
| 38 | +service "supervisor" do |
| 39 | + include Falcon::Environment::Supervisor |
| 40 | +end |
| 41 | +~~~ |
| 42 | + |
| 43 | +These configuration blocks are evaluated using the [async-service](https://github.com/socketry/async-service) gem. The supervisor is an independent service which monitors the health of the application and can restart it if necessary. Other services like background job processors can be added to the configuration. |
| 44 | + |
| 45 | +### Environments |
| 46 | + |
| 47 | +The service blocks define configuration that is loaded by the serivce layer to control how the service is run. The `service ... do` block defines the service name and the environment in which it runs. Different modules can be included to provide different functionality, such as `Falcon::Environment::Rack` for Rack applications, or `Falcon::Environment::LetsEncryptTLS` for automatic TLS certificate management. |
| 48 | + |
| 49 | +## Falcon Virtual |
| 50 | + |
| 51 | +Falcon virtual provides a virtual host proxy and HTTP-to-HTTPS redirection for multiple applications. It is designed to be a zero-configuration deployment option, allowing you to run multiple applications on the same server. |
| 52 | + |
| 53 | +You need to create a `falcon.rb` configuration in the root of your applications, and start the virtual host: |
| 54 | + |
| 55 | +~~~ bash |
| 56 | +falcon virtual /srv/http/*/falcon.rb |
| 57 | +~~~ |
| 58 | + |
| 59 | +See the [docker example](https://github.com/socketry/falcon-virtual-docker-example) for a complete working example. |
0 commit comments