GithubHelp home page GithubHelp logo

memos-on-fly's Introduction

Memos Deployment Guide

English | 中文

Deploy the self-hosted memo service, memos, on fly.io. Automate database backups to B2 using litestream.

Acknowledgments to linkding-on-fly for inspiring this project.

IMPORTANT NOTICE

To deploy memos without litestream on fly.io (Memos Official images), refer to README_no_litestream for instructions. Skip the remainder of this README document.

Prerequisites

⚠️ WARNING

hu3rror/memos-on-fly-build is deprecated. Maintenance has moved to hu3rror/memos-litestream.

If you previously used this image, change the build image section in your fly.toml to the new image:

[build]
-  image = "hu3rror/memos-fly:latest"
+  image = "ghcr.io/hu3rror/memos-litestream:stable"

The new image is universal for both fly.io and local runs.

Installation

  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 set up Postgres and do not deploy yet!

flyctl launch

This command creates a fly.toml file.

Edit your fly.toml

Use fly.with.litestream.example.toml in this repository as a reference and modify according to the comments.

Details of manual modifications

1. Add a build section.

[build]
  image = "ghcr.io/hu3rror/memos-litestream:stable"

2. Add an env section.

[env]
  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

3. 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, add storage configuration to fly.toml.
  2. Set the values of LITESTREAM_REPLICA_ENDPOINT and LITESTREAM_REPLICA_BUCKET to your [env] section.
  3. 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>"

4. 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. Change the volume size later if needed. Find instructions 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
  1. Attach the persistent volume to the container by adding a mounts section to fly.toml.
[[mounts]]
  source = "memos_data"
  destination = "/var/opt/memos"

5. Add internal_port to [[services]]

[http_service]
  internal_port = 5230   # change to 5230

6. Deploy to fly.io

flyctl deploy

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

All done!

🎊 Enjoy using memos!

Other

How to update to the latest memos release

Check the status of memos's docker image built by GitHub Actions.

If the latest docker image is on Docker Hub, upgrade memos with flyctl deploy in your project's folder.

Custom Domains

If desired, configure a custom domain for your install.

Verify the installation

  • Log into your memos instance.
  • Find an initial replica of your database in your B2 bucket.
  • Confirm your user data survives a VM restart.

Verify backups / scale persistent volume

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

Two ways to verify 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.

Focus on 2 as it simulates an actual data loss scenario. This procedure can also 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 use your instance, export bookmarks as HTML.
  2. Make a snapshot of the B2 bucket in the B2 admin panel.

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 console 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

Run flyctl deploy --no-cache.

Memos Telegram bot does not respond

Due to the fly.toml v2 update, modify your fly.toml like:

[http_service]
  auto_stop_machines = false   # change to `false` if you use the Telegram bot

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.

memos-on-fly's People

Contributors

hu3rror avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

memos-on-fly's Issues

How to migrate from the no litestream version to the version with litestream?

Since I am unfamiliar with Memos, I chose the version without litestream for deployment. After using it for some time, I've come to realize the significance of having a backup. Therefore, I would like to switch from the non-litestream version to the litestream version. How can I accomplish this?

Can I use flyctl ssh console to connect to the container, back up its database files and asset folder, and then upload them to the new deployment?

Thank you.

部署之后网站访问不通

会提示:

2023-08-21T12:44:48.950 app[5683d6e7b0458e] hkg [info] INFO [fly api proxy] listening at /.fly/api

2023-08-21T12:44:48.951 app[5683d6e7b0458e] hkg [info] 2023/08/21 12:44:48 listening on [fdaa:2:d560:a7b:1a5:f96e:f29f:2]:22 (DNS: [fdaa::3]:53)

2023-08-21T12:44:48.952 app[5683d6e7b0458e] hkg [info] No database found, attempt to restore from a replica.

2023-08-21T12:44:53.966 proxy[5683d6e7b0458e] hkg [error] instance refused connection. is your app listening on 0.0.0.0:5230? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers often print the address they are listening on)

2023-08-21T12:45:03.010 proxy[5683d6e7b0458e] hkg [error] instance refused connection. is your app listening on 0.0.0.0:5230? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers often print the address they are listening on)

2023-08-21T12:45:13.129 proxy[5683d6e7b0458e] hkg [error] instance refused connection. is your app listening on 0.0.0.0:5230? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers often print the address they are listening on)

关于该镜像的一些咨询和建议

感谢大佬给出这样的免费部署方案,但是在使用过程中因为不熟悉该工具及相关的工具,因此想咨询您一些关于memos-on-fly库的问题:
1.这里面使用的B2存储库只是单纯备份fly.io上的数据,还是将fly.io上部署的memos用户产生的数据存到B2里,然后在用户前端访问memos时从B2中取出数据呢?
2.B2的备份是自动的吗?
3.能否支持设置图床的功能?毕竟免费资源的容量有限,而且是写到数据库里的,加载和渲染的代价比直接存储图床要高。
谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.