#community-help

Deploying Typesense in GCP Cloud Run

TLDR Christian had difficulties obtaining an API key for deploying Typesense in GCP Cloud Run. Kishore Nallan guided on API key creation when setting up Typesense server and suggested checking the Typesense self-hosting guide. Christian decided to run the Typesense in Kubernetes instead of Cloud Run. Nasim thanked Christian for sharing findings.

Powered by Struct AI

1

Feb 24, 2022 (20 months ago)
Christian
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Christian
08:19 AM
Hi! I'm trying to deploy Typesense in GCP Cloud Run, but is not fully clear on how to obtain the API key. Do I need to set up a cluster on Typesense Cloud even though the intention was to keep things in GCP/Firebase?

Thankful for guidance 🙂
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:44 AM
👋 Are you self hosting Typesense on GCP? Christian
08:49
Kishore Nallan
08:49 AM
When you start the Typesense server, you set a master API key via --api-key CLI argument (or equivalent config file or environment variable). You can then use this master key to create additional keys with narrower permissions for searching or exposing to the front-end.
Christian
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Christian
08:54 AM
Hi, yes, the intention is to self-host in GCP using the Docker image. I used the Firebase plugin, which asks for a API key during setup.

So if I understand correctly, I would start the instance in Cloud Run and set the key there, and thereafter run the Firebase plugin?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:55 AM
Correct, check this self hosting guide:

https://typesense.org/docs/guide/install-typesense.html#option-2-local-machine-self-hosting

It contains snippets that show how the server is started with a master API key.
Christian
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Christian
08:59 AM
Great, thank you for the support! 😀
09:03
Christian
09:03 AM
Even though I'm clearly in over my head here... no idea how to run those commands on GCP 🙂
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:03 AM
Are you using Docker?
09:04
Kishore Nallan
09:04 AM
You can set environment variables like this for Docker deployment.
09:05
Kishore Nallan
09:05 AM
export TYPESENSE_API_KEY=xyz

mkdir /tmp/typesense-data

docker run -p 8108:8108 -v/tmp/typesense-data:/data typesense/typesense:0.22.2 \
  --data-dir /data --api-key=$TYPESENSE_API_KEY --enable-cors
Christian
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Christian
09:07 AM
Yes, but the Docker image has already been pushed to the artefact registry in GCP for deployment, and this looks like commands on a local machine, which makes me somewhat confused.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:08 AM
I'm sure GCP will allow you to pass environment variables to the Docker container for configuration.
Christian
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Christian
09:09 AM
Ok, will investigate. Thanks again! 🙂
Christian
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Christian
01:05 PM
Could you maybe hint on how to enter these variables into CR? For example, how does one handle the directory creation in this context? And is the API key entered as a secret?

Thanks in advance, and sorry for basic questions. I'm somewhat of a newbie.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:07 PM
I'm afraid I'm not familiar with the GCP ecosystem apart from the basics. This is not anything specific to Typesense so I think posting on Stackoverflow should get you quick help. I would love to help here but my own knowledge is limited on GCP.
Christian
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Christian
01:29 PM
Ok, thanks anyway 🙂
Feb 25, 2022 (20 months ago)
Christian
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Christian
12:28 PM
Just to follow up and conclude this thread; I assume that the Typesense Docker container is stateful, so it will have to be run in Kubernetes instead of Cloud Run, which only handles stateless services.

It's a continuous learning process 🙂

1

Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:10 PM
👍
Jun 07, 2022 (17 months ago)
Nasim
Photo of md5-46b59943e82de807cdb3cc937f78183a
Nasim
08:13 AM
Thanks Christian for sharing your findings. Been on the same rabbit hole.