# 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.

%[https://hashnode.com/post/cm3i8c9mp001609ku3rhieuku] 

## The database

Wakapi provide several choices of database.

> ### Supported databases
> 
> Wakapi uses [GORM](https://gorm.io/) as an ORM. As a consequence, a set of different relational databases is supported.
> 
> * [SQLite](https://sqlite.org/) (*default, easy setup*)
>     
> * [MySQL](https://hub.docker.com/_/mysql) (*recommended, because most extensively tested*)
>     
> * [MariaDB](https://hub.docker.com/_/mariadb) (*open-source MySQL alternative*)
>     
> * [Postgres](https://hub.docker.com/_/postgres) (*open-source as well*)
>     
> * [CockroachDB](https://www.cockroachlabs.com/docs/stable/install-cockroachdb-linux.html) (*cloud-native, distributed, Postgres-compatible API*)
>     
> * [Microsoft SQL Server](https://hub.docker.com/_/microsoft-mssql-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:

1. Visit [https://supabase.com/pricing](https://supabase.com/pricing) and register for an account.
    
2. Create a project on the platform.
    
3. 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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1731653948300/ef0925c2-d2fd-4215-acd4-3e2096423964.png align="center")

## The Wakapi app on Google Cloud

This is the hard part. You need a credit card to continue 😆

![Picture memes g7G8wky07 — iFunny](https://i.pinimg.com/736x/ca/42/4c/ca424c76464672e6a9f63bd1039379aa.jpg align="left")

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1731654880154/267c6681-73e0-404f-a0fa-f549e02aa18d.png align="center")

## How to set up your app

**Steps:**

1. Pull the original Docker image.
    
2. Push it to your Google Cloud Artifact Registry.
    
3. Create a Cloud Run instance that uses the most recent image you just pushed.
    
4. Set up the necessary configurations.
    

**Pull the docker image**

```bash
 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

```bash
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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1731655974389/41e09915-4217-4cdd-b33e-d1749e74528a.png align="center")

Give the required setting

* Select the image you just pushed
    
* App entry point
    
* 2GiB RAM and 2 CPU is more than enough
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1731655922809/a174b6e6-5ca1-4fd7-b2c8-230cee0ea9f2.png align="center")

**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](https://github.com/muety/wakapi?tab=readme-ov-file#-configuration-options)

You can set it however you want. Here is mine.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1731659235449/5e3db3cd-9356-4fa4-8760-00970011179c.png align="center")

Example:

```bash
# 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`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1731656753259/ec6b7107-bfbe-4326-98e0-6f0a97db14f0.png align="center")

That pretty much, if you run into any issue, let me know in the comment.

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Thanks <a target="_self" rel="noopener noreferrer nofollow" href="https://wakatime.com/" style="pointer-events: none">Wakatime</a> for open source your plugin and thanks <a target="_self" rel="noopener noreferrer nofollow" href="https://github.com/muety" style="pointer-events: none">Ferdinand Mütsch</a> for making this project.</div>
</div>
