Deno on Cloud Run

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:

--

--

--

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.

Recommended from Medium

Understanding PM2 (Process Manager 2) Commands — Deploy and Monitor Node.js Application

Liverpool Locks NewVideo https://t.co/VS2LAfdjET

Trafalgar (Figma Project)

Laravel 6 — VueJS — AdminLTE 3

Presentation Mode In vsCode is A God Gift For YouTuber and Teacher?

Presentation Mode In vsCode is A God Gift For YouTuber and Teacher?

Video Live Streaming with React Native

Tech: Create a reactive Master-Detail template with Angular Router + Material

Double Equals vs. Triple Equals

The Equality and the Strict Equality operators in JavaScript

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
Grant Timmerman

Grant Timmerman

Google • Explorer

More from Medium

2nd gen Cloud Functions Local Testing & Development

Lessons learned integrating AppSignal APM with NestJS

Integrating Bitbucket Cloud Pipelines with Google Firebase using OpenID Connect

Firebase and Bitbucket Cloud

[Part 1] NextJS + Golang Service in Kubernetes — Setup