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:

--

--