Deploy SilverBullet to fly.io

Fly.io is a nice and simple to use (and probably) cheap option of hosting SilverBullet “in the cloud” yourself, exposing it to the Internet (with username and password). You don’t have to manage a full server and the process of setting it up is pretty straight forward.

Requirements

A fly.io account. I think you have to sign up with a credit card. Since we’ll configure your fly.io app to automatically stop when not in use (after a few minutes), cost of running SilverBullet should be low or possibly even free (I’ve seen claims that fly.io won’t charge you if your monthly bill is < $5). No promises, though. Please report your experiences when you deploy SilverBullet this way.

Setup

On your local machine, create an empty folder with a single file in it: fly.toml:

# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
swap_size_mb = 512

[build]
# Replace edge with a specific release, e.g. 0.9.0
# To upgrade, update the version number and run 'fly deploy' again
image = 'zefhemel/silverbullet:edge'

[deploy]
strategy = 'immediate'

[[mounts]]
# Volume to store your space
source = 'space_data'
destination = '/space'
initial_size = '1gb'

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0

[[vm]]
# 512mb is the recommended minimum
memory = '512mb'
cpu_kind = 'shared'
cpus = 1

Install the fly CLI, then launch the app. The first time you’ll have to authenticate your account.

fly launch

This will ask if you would like to “copy its configuration to the new app?” Say yes.

Tweak the suggested (random) app name if you like, this will become part of your deployed URL.

This will give you a running SilverBullet with no authentication. So let’s set a username and password immediately (replace user with your prefered username and letmein with something more secure).

fly secrets set SB_USER=user:letmein

After a while, you’ll be asked for your username and password.

That’s all.

Upgrading

You will have to manually upgrade your SilverBullet instance as follows:

In your fly.toml change the tag of your docker image to a specific version number, e.g. zefhemel/silverbullet:0.9.0, and then when it’s released update to zefhemel/silverbullet:0.9.1. Save your changes and run:

fly deploy

After a little while (watch server logs as described below to see progress), your upgraded SilverBullet will come back up.

Monitor server logs

fly logs

SSH into your machine

fly ssh console

Enjoy!

3 Likes

It is highly recommended that you do something like this right after: Backup your space to Github

I tried to build my own Docker image for SB but it always failed to start in fly.io.

First, I built the image

deno task bundle
docker build -t pvadocker/silverbullet .
docker push pvadocker/silverbullet:latest

then in fly.toml, I replace ‘zefhemel’ with my account ‘pvadocker’

image = 'pvadocker/silverbullet:latest'

then fly deploy again and got this error in fly log

2024-09-14T02:36:24.779 app[1857166f459478] sin [info] INFO Mounting /dev/vdd at /space w/ uid: 0, gid: 0 and chmod 0755

2024-09-14T02:36:24.781 app[1857166f459478] sin [info] INFO Resized /space to 1056964608 bytes

2024-09-14T02:36:24.787 app[1857166f459478] sin [info] INFO Preparing to run: `/tini -s -- /docker-entrypoint.sh` as root

2024-09-14T02:36:24.793 app[1857166f459478] sin [info] INFO [fly api proxy] listening at /.fly/api

2024-09-14T02:36:24.800 app[1857166f459478] sin [info] 2024/09/14 02:36:24 INFO SSH listening listen_address=[fdaa:0:b69e:a7b:188:bdc0:c69:2]:22 dns_server=[fdaa::3]:53

2024-09-14T02:36:24.808 app[1857166f459478] sin [info] /bin/bash: - : invalid option

2024-09-14T02:36:24.872 runner[1857166f459478] sin [info] Machine started in 1.027s

2024-09-14T02:36:24.873 proxy[1857166f459478] sin [info] machine started in 1.032660448s

2024-09-14T02:36:25.795 app[1857166f459478] sin [info] INFO Main child exited normally with code: 1

2024-09-14T02:36:25.809 app[1857166f459478] sin [info] INFO Starting clean up.

2024-09-14T02:36:25.829 app[1857166f459478] sin [info] INFO Umounting /dev/vdd from /space

2024-09-14T02:36:25.830 app[1857166f459478] sin [info] WARN could not unmount /rootfs: EINVAL: Invalid argument

2024-09-14T02:36:25.831 app[1857166f459478] sin [info] [ 1.804776] reboot: Restarting system

2024-09-14T02:36:29.300 runner[1857166f459478] sin [info] machine has reached its max restart count of 10

2024-09-14T02:36:32.219 proxy[1857166f459478] sin [info] waiting for machine to be reachable on 0.0.0.0:3000 (waited 7.346476819s so far)

2024-09-14T02:36:38.171 proxy[1857166f459478] sin [info] waiting for machine to be reachable on 0.0.0.0:3000 (waited 13.298530488s so far)

2024-09-14T02:36:44.147 proxy[1857166f459478] sin [info] waiting for machine to be reachable on 0.0.0.0:3000 (waited 19.274472632s so far)

2024-09-14T02:36:49.151 proxy[1857166f459478] sin [error] [PM05] failed to connect to machine: gave up after 15 attempts (in 24.278223914s)

do you have any idea on where I went wrong?

What platform are you building on? I think fly runs on amd64. Perhaps you’re building on an arm machine?

I was building it on Debian in WSL2.

I tried running the image locally, it throw the below error though the /docker-entrypoint.sh is still there in the / directory

[FATAL tini (7)] exec /docker-entrypoint.sh failed: No such file or directory

I guessed the issue might be related to line endings that caused Bash failed to read the file. I tried fixing it with dos2unix

dos2unix /docker-entrypoint.sh

After that I rebuilt the image then the problem was fixed. Now I can run the image on both local and fly.io.

1 Like