Run Trilium server in google cloud run

Published

May 4, 2024

Purpose

Trilium can be used as a personal knowledge base. It can be run locally or synchronized across multiple devices as a server. By using google cloud run as the server, we can have a reliable and scalable solution with the following advantages.

  1. Cost-effective: Cloud Run is serverless. So no hassles of maintaining a server or VM. We pay only for the resources used. We can scale the number of nodes to zero when not in use.
  2. Storage: A recent feature of Cloud Run is the ability to mount a google cloud storage bucket as a volume.

Steps

# set the project name and region. Change these values as per your requirement
export PROJECT_ID=project_xyz
export REGION=asia-southeast1
export BUCKET_NAME=bucket_name

# switch to the project
gcloud config set project $PROJECT_ID

# create a cloud storage bucket
gsutil mb -l $REGION gs://$BUCKET_NAME

# deploy trilium to cloud run
gcloud beta run deploy trilium --image zadam/trilium:0.63-latest \
--execution-environment gen2 \
--add-volume=name=trilium_data,type=cloud-storage,bucket=$BUCKET_NAME \
--add-volume-mount=volume=trilium_data,mount-path=/home/node/trilium-data \
--allow-unauthenticated --max-instances 1 \
--memory 512Mi \
--region $REGION --project $PROJECT_ID

Once deployment is successful, we get a url in shell, something like https://trilium-xyz1234-as.a.run.app

Access

  1. Open the url in a browser. Now you can set a strong password and start using trilium.