Problem
If you’re porting an app from Deno Deploy to Fly.io, you may hit a bit of a snag: if it was built with Deno KV, a traditionally FoundationDB backed K/V store made for Deno Deploy, there’s no obvious way to easily run Deno KV at scale on Fly.io. You could use denoland/denokv on Fly.io, but due to an alignment of the stars there happens to be an easier way. Deno KV can actually be backed by an SQLite DB stored on disk in a cache folder, and you can specify the path of this DB with the parameter toDeno.openKv( <here> ).
This means you can do something like this to get Deno KV to use an arbitrary SQLite DB:
Setting up LiteFS
Firstly, you need to add alitefs.yml file to your project, and make sure it gets included in the Dockerfile.
Here’s an example:
It’s not immediately clear based on the example config, but your app needs to listen on “target” (:8081) and your service/http_service in fly.toml needs to listen on “addr” (:8080). This is because part of LiteFS acts as a proxy, so you need the fly-proxy to send requests to LiteFS which then forwards them on to your app.If you’re not able to change your application’s port, make sure
target is set up correctly then change addr and fly.toml to something other than :8080.DB_LOCATION is set to /litefs/my.db in fly.toml under [env].
Now, if you’re deploying to Fly.io, you’re almost ready to go. Here’s where to look if you’re not running on Fly.io.
Creating a LiteFS Cloud cluster
For a more in-depth article, check out Getting Started with LiteFS on Fly.io. Head over to the LiteFS section of the dashboard and create a cluster, make a note of the auth token (you’ll need it later).Dockerfile
You need to add the dependencies for LiteFS to your Dockerfile:ENTRYPOINT/CMD:
fly.toml to mount the LiteFS volume: