Deno on Cloud Run

Grant Timmerman
May 13, 2020 · 2 min read
Image for post
Image for post
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

Install Deno

curl -fsSL https://deno.land/x/install/install.sh | sh

Create a main.ts file

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

deno run --allow-env --allow-net main.ts

Hit localhost:8080 to see Hello, Deno!

Create a Dockerfile

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

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://hellodeno-q7vieseilq-uc.a.run.app/

Voila! 棒棒的!

This sample app is also a Github sample in the Knative Docs.

Next Steps

Google Cloud - Community

Google Cloud community articles and blogs

Grant Timmerman

Written by

Google • Explorer

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

Written by

Google • Explorer

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.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store