Self-host your Wakatime stats for (almost) free with Supabase Postgres + Google Cloud Run
In my previous post, I introduce the project Wakapi - an alternative to Wakatime but it totally free, it mean you have to self hosted it somewhere.
The database
Wakapi provide several choices of database.
Supported databases
Wakapi uses GORM as an ORM. As a consequence, a set of different relational databases is supported.
SQLite (default, easy setup)
MySQL (recommended, because most extensively tested)
MariaDB (open-source MySQL alternative)
Postgres (open-source as well)
CockroachDB (cloud-native, distributed, Postgres-compatible API)
Microsoft SQL Server (Microsoft SQL Server)
I was looking for a free service to host my database and discovered that the Supabase free tier is sufficient for this small application. They offer a managed Postgres service, which I really appreciate as I love using Postgres.
Get started with:
Unlimited API requests
50,000 monthly active users
500 MB database space
Shared CPU • 500 MB RAM
5 GB bandwidth
1 GB file storage
Community support
Supabase is a company, and their need for profit is important. I don't encourage spamming their free tier; we only use it here as an experiment. Also, remember to back up your data because we don’t know when it might be stop offering the free package.
To get started with the free package, follow these steps:
Visit https://supabase.com/pricing and register for an account.
Create a project on the platform.
On the home page, click the "Connect" button to obtain the connection string.
Make sure to copy the connection string for the Session mode, as it supports concurrency and is suitable for your app. The Transaction mode is only appropriate for one-time commands.
The Wakapi app on Google Cloud
This is the hard part. You need a credit card to continue 😆
However, if you can afford it, it's really cheap.
Cloud Run is incredibly affordable for low workloads. I created a new Google Cloud account to experiment with Kubernetes, but in October I only used a single Cloud Run instance to host my Wakapi. The total cost for that was 2,733 VND, which is approximately $0.11. That's why I say it feels almost free. Please ignore the free trial credit in the image below, as it expires in three months. However, the monthly fee for Cloud Run remains minimal.
How to set up your app
Steps:
Pull the original Docker image.
Push it to your Google Cloud Artifact Registry.
Create a Cloud Run instance that uses the most recent image you just pushed.
Set up the necessary configurations.
Pull the docker image
docker pull --platform linux/amd64 ghcr.io/muety/wakapi:latest
Remember to pull this arch --platform linux/amd64
If you are on MacOS Apple silicon chip, it will pull the arm64 image and you can’t push it to Artifact register
Push it to your Google Cloud Artifact Registry
After you pull it, your image will be wakapi:latest
Now push it to you google project
docker push gcr.io/YOUR_GOOGLE_PROJECT_ID/wakapi:latest
Create a Cloud Run instance that uses the most recent image you just pushed.
Create a new Cloud Run Service deploy from container
Give the required setting
Select the image you just pushed
App entry point
2GiB RAM and 2 CPU is more than enough
Set up the necessary configurations.
Don’t click Deploy yet, remember your database secret? Wakapi provide all kind of configuration here https://github.com/muety/wakapi?tab=readme-ov-file#-configuration-options
You can set it however you want. Here is mine.
Example:
# Database Configuration
export WAKAPI_DB_AUTOMIGRATE_FAIL_SILENTLY=true
export WAKAPI_DB_TYPE=postgres
export WAKAPI_DB_HOST=aws-0-ap-southeast-1.redacted.supabase.co
export WAKAPI_DB_PORT=5432
export WAKAPI_DB_USER=postgres.redacted
export WAKAPI_DB_NAME=postgres
export WAKAPI_DB_PASSWORD=******** # Replace with your actual database password
# Application Settings
export WAKAPI_LISTEN_IPV4=0.0.0.0
export WAKAPI_ALLOW_SIGNUP=false
export WAKAPI_INSECURE_COOKIES=true
# Security Settings
export WAKAPI_PASSWORD_SALT=******** # Replace with your secure random salt
export WAKAPI_SENTRY_DSN=******** # Replace with your Sentry DSN if using error tracking
# Environment Type
export ENVIRONMENT=production
The most crucial configuration is the database secret. Once you're satisfied with your settings, click "Deploy" and wait a few minutes for your Cloud Run service to boot up. At the top of the page, you will see a URL; this is your public URL to access your Wakapi. You also have the option to purchase a domain and point it to your Cloud Run service. Googling Cloud Run domain mapping
for the further instruction.
Setting Up the Client
Wakapi uses the same client as Wakatime, which means that all Wakatime plugins can send data to Wakapi. You have the option to disable data sending to Wakatime and send data exclusively to Wakapi, and that is completely acceptable.
To get started, navigate to your deployed Cloud Run URL and register your first account. Make sure to retrieve the API key and update it in the appropriate location in your system, located at ~/.wakatime.cfg
That pretty much, if you run into any issue, let me know in the comment.