Deno on Cloud Run

Grant Timmerman
Google Cloud - Community
2 min readMay 13, 2020
Deno + 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:

main.ts

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:

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:

--

--

Google Cloud - Community
Google Cloud - Community

Published in Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Grant Timmerman
Grant Timmerman

Written by Grant Timmerman

Explorer ā€¢ Adventurer ā€¢ Builder

Responses (4)