Skip to main content
Version: 1.x

Deploy on Fly.io

This document is based on a guide by one of our community members. You can find it here.

Requirements

Get started

We will create a working directory for our deployment. In it, we will store a Dockerfile and a fly.toml config file.

mkdir surrealdb-deployment && cd surrealdb-deployment
## Uncomment the below line for macOS or Linux
# nano Dockerfile
## Uncomment the below line for Windows
# notepad Dockerfile

In the Dockerfile we specify which base image we want to use, and to which address/port we will bind the instance. You can edit the Dockerfile file and paste the following snippet into the file without any indents or spaces. The rest of the SurrealDB configuration will be done later with secrets.

Docker file
FROM surrealdb/surrealdb:latest
EXPOSE 8080
CMD ["start", "--bind", "0.0.0.0:8080", "file://data/srdb.db"]

Generate fly.toml

We will generate most of the content for the fly.toml configuration file using the fly launch utility. Please answer the questions with the guidelines given below.

Generate Boilerplate fly.toml file
fly launch --no-deploy
  • Choose an app name: Choose what you like. It will end up as name.fly.dev, so it must be a unique name.
  • Choose a region: Choose what you like, usually a region close to your users.
  • Setup postgres database?: No, we will persist storage through a volume.
  • Setup upstash redis database?: No, we will persist storage through a volume.
  • Would you like to deploy now?: No, we need to finalize our configuration first.

Create volume for persistent storage

For this demo, we'll create a single volume with a size of 1 GB. Make sure to set it to the same region that you chose earlier! In this case data is the name of the volume.

Create the volume
fly volumes create data --region <region> --size 1

To assign this volume to the instance that we'll deploy, we have to edit the fly.toml file. Paste the following snippet down the bottom of the file without any indents or spaces. If you changed the name of the volume in the previous step, please also adjust the source property here.

Assign the volume to instance
[mounts]
source="data"
destination="/data"

Configure root authentication details

We will store the username and password for the root user in secrets. Feel free to pass on any other options here. You can use surreal start -h to see which environment variables can be passed to surreal.

Configure username & password
fly secrets set SURREAL_USER="..."
fly secrets set SURREAL_PASS="..."

Deploy the instance

Everything has been configured now, and we can deploy our instance securely with a single command:

Deploy the instance
fly deploy

After this, your instance will be available via https://name.fly.dev, followed by the respective path for methods like HTTP REST and Websocket.