This repository contains a template for setting up and running goatcounter on fly.io, including Litestream backing up our SQLite database to a S3 (compatible) bucket. This setup runs great on the fly.io free tier (1 shared CPU, 256 MB of memory, 1 GB of disk), at least for a small website. You can also make use of Backblaze B2's free tier1 to store your backups.
One important thing to note is that this is a single node setup using local volumes, so in case the host running our container dies we might not be automagically migrated to a new host. However, our data is reasonably safe due to Litestream backups, so we should not lose more than a few minutes of data (at most).
PRs are always welcome!
- A fly.io account
- An account with a S3 (compatible) storage provider, with a bucket already setup & credentials at hand (see this tutorial for Backblaze specific instructions)
- flyctl CLI installed
-
Clone or fork this repository.
git clone https://github.com/oscarcarlsson/goatcounter-on-fly.git && cd goatcounter-on-fly
-
Run the command below and answer the questions - you don't need Redis nor Postgres! This will generate a
fly.toml
but won't try to launch anything yet. Make sure you change the name for the application as well.flyctl launch --no-deploy --memory 256 --name CHANGEME
If you want, you can always specify the region to launch the VM in. You can list all regions by running:
flyctl platform regions
-
Create a volume for the database, change to your preferred region:
flyctl volumes create goatcounter_data --region CHANGEME --size 1
-
Open
fly.toml
and add the following to the env section:[env] # Change these! GOATCOUNTER_DOMAIN = 'goatcounter.example.com' GOATCOUNTER_EMAIL = '[email protected]' # Change these for your S3 provider! LITESTREAM_REPLICA_ENDPOINT = '' LITESTREAM_REPLICA_BUCKET = '' # These can be blank GOATCOUNTER_SMTP = '' GOATCOUNTER_DEBUG = '' # Don't change these GOATCOUNTER_LISTEN = '0.0.0.0:8080' GOATCOUNTER_DB = '/data/goatcounter.sqlite3' LITESTREAM_REPLICA_PATH = 'goatcounter_replica.sqlite3'
Also make sure that the mount section looks something like this:
[[mounts]] source = 'goatcounter_data' destination = '/data' processes = ['app']
-
Nearly done! Now, create secrets for your secrets:
flyctl secrets set GOATCOUNTER_PASSWORD="changeme" LITESTREAM_ACCESS_KEY_ID="changeme" LITESTREAM_SECRET_ACCESS_KEY="changeme"
The secret called
GOATCOUNTER_PASSWORD
will be the initial password for theadmin
account. -
Now, try to deploy the application!
This is heavily inspired by fspoettel/linkding-on-fly.
Footnotes
-
Their free tier is 10GB free, then $0.005 per GB, which is plenty โฉ