View Source Hosting guide

A short guide to running Bonfire in a production environment and setting up a digital space connected to the fediverse.

Warning

Bonfire is currently beta software. While it's fun to play with it, we would not recommend running any production instances yet (meaning not using it for your primary fediverse identity) because it's not quite ready for that today.

These instructions are for setting up Bonfire in production. If you want to run the backend in development, please refer to our Installation guide instead.

Security Warning

We recommend only granting an account to people you trust to minimise the attack surface. Accordingly, Bonfire ships with public registration disabled. The admin panel has an invite facility.


Step 1 - Decide how you want to deploy and manage the app

Install using Co-op Cloud (recommended) which is an alternative to corporate cloud services built by tech co-ops, and provides handy tools for setting up and managing many self-hosted free software tools using ready-to-use "recipes". Very useful if you'd like to host Bonfire alongside other open and/or federated projects.

  1. Install Abra on your machine
  2. Set up a server with co-op cloud
  3. Use the Bonfire recipe and follow the instructions there, including editing the config in the env file at ~/.abra/servers/your_server/your_app.env (see prepare the config for details about what to edit)
  4. Run the abra deploy command and done!

Preparing the config (in .env)

Config keys you should pay special attention to:

The app needs these environment variables to be configured in order to work.

  • FLAVOUR should reflect your chosen flavour
  • HOSTNAME (your domain name, eg: bonfire.example.com)
  • PUBLIC_PORT (usually 443)
  • MAIL_DOMAIN and MAIL_KEY and related keys to configure transactional email, for example set MAIL_BACKEND=mailgun and sign up at Mailgun and then configure the domain name and key (you may also need to set MAIL_BASE_URI if your domain is not setup in EU, as the default MAIL_BASE_URI is set as https://api.eu.mailgun.net/v3).
  • SMTP is supported as well, through the following env vars
    MAIL_SERVER (smtp domain of the mail server)
    MAIL_DOMAIN (the bit after the @ in your email)
    MAIL_USER
    MAIL_PASSWORD
    MAIL_FROM
    MAIL_PORT (optional)
    MAIL_SSL (optional)
  • UPLOADS_S3_BUCKET and the related API key and secret for uploads. WARNING: If you want to store uploads in an object storage rather than directly on your server (which you probably want, to not run out of space), you need to configure that up front, otherwise URLs will break if you change it later. See config/runtime.exs for extra variables to set if you're not using the default service and region (which is Scaleway Paris).

Secret keys for which you should put random secrets.

You can run just secrets to generate some for you.

  • SECRET_KEY_BASE
  • SIGNING_SALT
  • ENCRYPTION_SALT
  • POSTGRES_PASSWORD
  • MEILI_MASTER_KEY

Further information on config

In the ./config/ (which is a symbolic link to the config of the flavour you choose to run) directory of the codebase, there are following config files:

  • config.exs: default base configuration, which itself loads many other config files, such as one for each installed Bonfire extension.
  • prod.exs: default extra configuration for MIX_ENV=prod
  • runtime.exs: extra configuration which is loaded at runtime (vs the others which are only loaded once at compile time, i.e. when you build a release)
  • bonfire_*.exs: configs specific to different extensions, which are automatically imported by config.exs

You should not have to modify the files above. Instead, overload any settings from the above files using env variables or in ./.env. If any settings in the .exs config files are not available in env or in the instance settings UI, please open an issue or PR.

Notes on running the app

NOTE: If you are running in a restricted environment such as Amazon RDS, you will need to execute some sql against the database before migrations can run: CREATE EXTENSION IF NOT EXISTS citext;

By default, the backend listens on port 4000 (TCP), so you can access it on http://localhost:4000/ (if you are on the same machine). In case of an error it will restart automatically.

Once you've signed up, you will automatically be an instance admin if you were the first to register.

You can also sign up via CLI (accessed via just rel-shell) by entering something like this in your app's Elixir console: Bonfire.Me.make_account_only("my@email.net", "my pw")

Handy commands

  • just update to update to the latest release of Bonfire
  • just rel-run Run the app in Docker, in the foreground
  • just rel-run-bg Run the app in Docker, and keep running in the background
  • just rel-stop Stop the running release
  • just rel-shell Runs a simple shell inside of the container, useful to explore the image

Once in the shell, you can run bin/bonfire with the following commands: Usage: bonfire COMMAND [ARGS]

The known commands are:

  • start Starts the system
  • start_iex Starts the system with IEx attached
  • daemon Starts the system as a daemon
  • daemon_iex Starts the system as a daemon with IEx attached
  • eval "EXPR" Executes the given expression on a new, non-booted system
  • rpc "EXPR" Executes the given expression remotely on the running system
  • remote Connects to the running system via a IEx remote shell
  • restart Restarts the running system via a remote command
  • stop Stops the running system via a remote command
  • pid Prints the operating system PID of the running system via a remote command
  • version Prints the release name and version to be booted

There are some useful database-related release tasks under EctoSparkles.Migrator. that can be run in an iex console (which you get to with just rel.shell followed by bin/bonfire remote, assuming the app is already running):

  • migrate runs all up migrations
  • rollback(step) roll back to step X
  • rollback_to(version) roll back to a specific version
  • rollback_all rolls back all migrations back to zero (caution: this means losing all data)

You can also directly call some functions in the code from the command line, for example:

  • to migrate: docker exec bonfire_web bin/bonfire rpc 'Bonfire.Common.Repo.migrate'
  • to just yourself an admin: docker exec bonfire_web bin/bonfire rpc 'Bonfire.Me.Users.make_admin("my_username")'

Admin tools

  • LiveDashboard for viewing real-time metrics and logs at /admin/system/
  • Oban logs for viewing queued jobs (e.g. for processing federated activities) /admin/system/oban_queues
  • LiveAdmin for browsing data in the database at /admin/system/data
  • Orion for dynamic distributed performance profiling at /admin/system/orion
  • Web Observer as an alternative way to view metrics at /admin/system/wobserver

Troubleshooting

Some common issues that may arise during deployment and our suggestions for resolving them.

WebSocket connections not establishing behind a reverse proxy

If you are running Bonfire behind your own reverse proxy (e.g. nginx), you might experience issues with WebSocket connections not establishing. WebSocket connections require specific configuration to work, in nginx the following configuration is necessary for websockets to work:

location /live/websocket {
    proxy_pass http://127.0.0.1:4000;
    
    # these configurations are necessary to proxy WebSocket requests
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}