Deno on Cloud Run
š¦ Deno (deno.land) is a secure TypeScript runtime built on V8 and Rust, created by Ryan Dahl, the creator of Node.js.
š Cloud Run (cloud.run) is a fully managed compute platform that automatically scales your stateless containers.
In this blogpost, weāll show you how to containerize and deploy a simple Deno application on Cloud Run, running a serverless, HTTPS, TypeScript service.
Create a Deno App
Letās create a web application in TypeScript for Deno:
Install Deno
Install Deno on your system using the instructions on the official site:
curl -fsSL https://deno.land/x/install/install.sh | sh
Create a main.ts file
Create a simple HTTP server using Denoās standard library:
Youāll notice non-Node features like import
and top-level for await
. Neat!
You might notice some code editors like VS Code issue warnings for Deno features like top-level await or TS imports (GitHub issue). They can be ignored.
Run Locally
Before proceeding, letās ensure our server works by running locally:
deno run --allow-env --allow-net main.ts
Hit localhost:8080
to see Hello, Deno!
Create a Dockerfile
Letās containerize this application.
Give Docker instructions for creating our image via a simple Dockerfile
:
To test this Dockerfile
, we can run our service locally with this command:
docker build -t app . && docker run -it --init -p 8080:8080 app
Deploy to Cloud Run
Now that weāve created our main.ts
and Dockerfile
files, weāre ready to deploy to Cloud Run.
Build the container (hellodeno
) and deploy to Cloud Run (fully managed):
GCP_PROJECT=$(gcloud config list --format 'value(core.project)' 2>/dev/null)
gcloud builds submit --tag gcr.io/$GCP_PROJECT/hellodeno
gcloud run deploy hellodeno --image gcr.io/$GCP_PROJECT/hellodeno --platform managed --allow-unauthenticated
Youāll get a URL from the deployed service:
https://deno-ff-q7vieseilq-ue.a.run.app
Voila! ę£ę£ēļ¼
This sample app is also a Github sample in the Knative Docs.
Next Steps
Thanks for reading! Check out these related posts: