|
1 | 1 | LiteFS Example Application
|
2 | 2 | ==========================
|
3 | 3 |
|
4 |
| -This repository is an example of a toy application running on LiteFS on Fly.io. |
| 4 | +This repository is an example of a toy application running on LiteFS. You can |
| 5 | +test it out by deploying to Fly.io, or locally with a docker-compose setup. |
5 | 6 |
|
6 |
| -## Prerequisites |
| 7 | +* [Fly.io instructions](./fly-io-config) |
| 8 | +* [Docker-compose instructions](./docker-config) |
7 | 9 |
|
8 |
| -First, you'll need to install [`flyctl`][] and then [sign up for a free account][signup]. |
9 |
| - |
10 |
| -[`flyctl`]: https://fly.io/docs/hands-on/install-flyctl/ |
11 |
| -[signup]: https://fly.io/docs/hands-on/sign-up/ |
12 |
| - |
13 |
| - |
14 |
| -## Usage |
15 |
| - |
16 |
| -### Creating the application |
17 |
| - |
18 |
| -First, we'll need to create our application on [Fly.io](https://fly.io). This |
19 |
| -will prompt you for a name or you can autogenerate one for this example. |
20 |
| -Remember this name as we'll need it later. |
21 |
| - |
22 |
| -```sh |
23 |
| -fly launch --region ord --no-deploy |
24 |
| -``` |
25 |
| - |
26 |
| -The launch command will create a `fly.toml` file and set the primary region to |
27 |
| -Chicago (`ord`) but will not launch the app. |
28 |
| - |
29 |
| - |
30 |
| -### Creating a volume |
31 |
| - |
32 |
| -Next, we need to set up a persistent volume in our primary region so that our |
33 |
| -data is not lost between restarts. |
34 |
| - |
35 |
| -```sh |
36 |
| -fly volumes create -r ord --size 1 litefs |
37 |
| -``` |
38 |
| - |
39 |
| -And add a mount to this volume in your `fly.toml` file: |
40 |
| - |
41 |
| -```toml |
42 |
| -[mounts] |
43 |
| - source = "litefs" |
44 |
| - destination = "/var/lib/litefs" |
45 |
| -``` |
46 |
| - |
47 |
| -### Setting up Consul |
48 |
| - |
49 |
| -LiteFS uses [Consul](https://consul.io) for its distributed lease. You can find |
50 |
| -instructions for using Fly.io's free multi-tenant Consul in the |
51 |
| -[Lease Management][] section of the Getting Started guide. |
52 |
| - |
53 |
| -[Lease Management]: https://fly.io/docs/litefs/getting-started/#lease-configuration |
54 |
| - |
55 |
| - |
56 |
| -### Launching your app |
57 |
| - |
58 |
| -The next step is to launch & deploy your app with the following command: |
59 |
| - |
60 |
| -```sh |
61 |
| -fly deploy |
62 |
| -``` |
63 |
| - |
64 |
| -The application should build and deploy and you should see it up in running |
65 |
| -after a minute or so. You can go to `https://$APPNAME.fly.dev/` and see your |
66 |
| -application running live. |
67 |
| - |
68 |
| -The application is a simple interface for generating fake records. It's just |
69 |
| -for illustrating how LiteFS can easily replicate your data between nodes. |
70 |
| - |
71 |
| -When you click the _"Generate Record"_ button, it will create that row in a |
72 |
| -local SQLite database that is running on a LiteFS file system. Any other node |
73 |
| -running LiteFS will automatically get those updates and apply them to their |
74 |
| -local copy of the database. That lets every node keep an exact copy of the same |
75 |
| -database. |
76 |
| - |
77 |
| - |
78 |
| -### Launching more regions |
79 |
| - |
80 |
| -This example application is configured to run as a primary only in the |
81 |
| -`PRIMARY_REGION` (which is Chicago). It's best practice to run two or more |
82 |
| -instances in the primary region and then you can add instances in additional |
83 |
| -regions to reduce latency for your users. |
84 |
| - |
85 |
| -You can clone the configuration of the machine to other regions by using the |
86 |
| -`fly m clone` command. The `--select` flag lets you choose from a list of |
87 |
| -existing machines to clone. |
88 |
| - |
89 |
| -```sh |
90 |
| -# Make a second instance in your primary region. |
91 |
| -fly m clone --select --region ord |
92 |
| - |
93 |
| -# Make additional instances in regions around the world (London, Sydney, etc). |
94 |
| -fly m clone --select --region lhr |
95 |
| -fly m clone --select --region syd |
96 |
| -``` |
| 10 | +**Note: commands should be run from the top-level directory for both Fly.io and |
| 11 | +local docker-compose (not from the location of the README files above).** |
0 commit comments