aisensiy / memos-on-fly

✍ Run memos on fly.io. Backup the memos DB to cloud storage with litestream.

Home Page:https://memos.fly.dev/explore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

memos on fly

Run the self-hosted memo service memos on fly.io. Automatically backup the database to B2 with litestream.

🙏 Thanks for linkding-on-fly, the project is inspired by it.

Prerequisites

Install flyctl

  1. Follow the instructions to install fly's command-line interface flyctl.
  2. log into flyctl.
flyctl auth login

Launch a fly application

do not setup Postgres and do not deploy yet!

flyctl launch

This command creates a fly.toml file.

Edit your fly.toml

You can take fly.example.toml in this repository as a reference and modify according to the comments.

Details of manual modifications

1. Add an env section.

[env]
  DB_PATH = "/var/opt/memos/memos_prod.db"  # do not change
  LITESTREAM_REPLICA_BUCKET = "<filled_later>"  # change to your litestream bucket name
  LITESTREAM_REPLICA_ENDPOINT = "<filled_later>"  # change to your litestream endpoint url
  LITESTREAM_REPLICA_PATH = "memos_prod.db"  # keep the default or change to whatever path you want

2. Configure litestream backups

ℹ️ If you want to use another storage provider, check litestream's "Replica Guides" section and adjust the config as needed.

  1. Log into B2 and create a bucket. Instead of adjusting the litestream config directly, we will add storage configuration to fly.toml.
  2. Now you can set the values of LITESTREAM_REPLICA_ENDPOINT and LITESTREAM_REPLICA_BUCKET to your [env] section.
  3. Then, create an access key for this bucket. Add the key to fly's secret store (Don't add < and >).
    flyctl secrets set LITESTREAM_ACCESS_KEY_ID="<keyId>" LITESTREAM_SECRET_ACCESS_KEY="<applicationKey>"

3. Add a persistent volume

  1. Create a persistent volume. Fly's free tier includes 3GB of storage across your VMs. Since memos is very light on storage, a 1GB volume will be more than enough for most use cases. It's possible to change volume size later. A how-to can be found in the "scale persistent volume" section below.

    flyctl volumes create memos_data --region <your_region> --size <size_in_gb>

    For example:

    flyctl volumes create memos_data --region hkg --size 1
  2. Attach the persistent volume to the container by adding a mounts section to fly.toml.

    [mounts]
      source="memos_data"
      destination="/var/opt/memos"

4. Change internal_port in [[services]]

[[services]]
  internal_port = 5230

5. Deploy to fly.io

flyctl deploy

If all is well, you can now access memos by running flyctl open. You should see its login page.

All done!

🎊 Just enjoy using memos!

Other

How to update to the latest memos release

You can check the status of memos's docker image built by GitHub Actions.

If the latest docker image has been released to Docker Hub, you can upgrade memos easily by flyctl deploy in your project's folder.

Custom Domains

If you wish, you can configure a custom domain for your install.

Verify the installation

  • you should be able to log into your memos instance.
  • there should be an initial replica of your database in your B2 bucket.
  • your user data should survive a restart of the VM.

Verify backups / scale persistent volume

Litestream continuously backs up your database by persisting its WAL to B2, once per second.

There are two ways to verify these backups:

  1. run the docker image locally or on a second VM. Verify the DB restores correctly.
  2. swap the fly volume for a new one and verify the DB restores correctly.

We will focus on 2 as it simulates an actual data loss scenario. This procedure can also be used to scale your volume to a different size.

Start by making a manual backup of your data:

  1. ssh into the VM and copy the DB to a remote. If only you are using your instance, you can also export bookmarks as HTML.
  2. make a snapshot of the B2 bucket in the B2 admin panel.

Now list all fly volumes and note the id of the memos_data volume. Then, delete the volume.

flyctl volumes list
flyctl volumes delete <id>

This will result in a dead VM after a few seconds. Create a new memos_data volume. Your application should automatically attempt to restart. If not, restart it manually.

When the application starts, you should see the successful restore in the logs.

[info] No database found, attempt to restore from a replica.
[info] Finished restoring the database.
[info] Starting litestream & memos service.

Pricing

Assuming one 256MB VM and a 3GB volume, this setup fits within Fly's free tier. 1 Backups with B2 are free as well. 2

Troubleshooting

litestream is logging 403 errors

Check that your B2 secrets and environment variables are correct.

fly ssh does not connect

Check the output of flyctl doctor, every line should be marked as PASSED. If Pinging WireGuard fails, try flyctl wireguard reset and flyctl agent restart.

fly does not pull in the latest version of memos

Just run flyctl deploy --no-cache

Footnotes

  1. otherwise the VM is ~$2 per month. $0.15/GB per month for the persistent volume.'

  2. the first 10GB are free, then $0.005 per GB.

About

✍ Run memos on fly.io. Backup the memos DB to cloud storage with litestream.

https://memos.fly.dev/explore

License:MIT License


Languages

Language:Dockerfile 64.5%Language:Shell 35.5%