Skip to main content

Deno on CloudFlow

Learn how to run a "Hello World" Deno app at the edge for low latency and high availability. You can use our repo as a template, or perform the steps yourself using the Kubernetes dashboard or kubectl commands.

Step by Step

Following are step-by-step instructions to deploy a Deno "Hello World" application to the edge on CloudFlow. We'll Dockerize it, push it to GitHub Packages, and deploy it on CloudFlow.

Prerequisites

  • You need Docker and Deno installed so that you can build a docker image.

Create the Deno App

Create a new directory for your app.

mkdir my-deno-app
cd my-deno-app

Create main.ts with the following code.

main.ts
import { serve } from "https://deno.land/std@0.167.0/http/server.ts";
serve((_req) => new Response("Hello World from Deno on CloudFlow!"), { port: 1993 });

Test it using run --allow-net main.ts and visit it using curl http://localhost:1993. You'll get the "Hello World from Deno on CloudFlow!" response.

Dockerize It

Let's build the container image that we'll deploy to CloudFlow. First make a Dockerfile in your directory with the following content.

Dockerfile
FROM denoland/deno:latest

# The port that your application listens to.
EXPOSE 1993

WORKDIR /my-deno-app

# Prefer not to run as root.
USER deno

# These steps will be re-run upon each file change in your working directory:
ADD . .
# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno cache main.ts

CMD ["run", "--allow-net", "main.ts"]

Build and tag it.

docker build . -t ghcr.io/YOUR_GITHUB_USERNAME/my-deno-app:prod

Launch it locally to test it.

docker run -p 1993:1993 ghcr.io/YOUR_GITHUB_USERNAME/my-deno-app:prod
curl http://localhost:1993

Push It

Push it to GitHub Packages. This makes it available to CloudFlow.

docker push ghcr.io/YOUR_GITHUB_USERNAME/my-deno-app:prod

Be sure to make it public. To see your packages and make this change, visit https://github.com/YOUR_GITHUB_USERNAME?tab=packages

Deploy It

Next, use the Create Project command in the CloudFlow Console in order to deploy your new container. Use the image name ghcr.io/YOUR_GITHUB_USERNAME/my-deno-app:prod with port 8080.

See the pods running on CloudFlow's network with either the Kubernetes dashboard or kubectl get pods -o wide. The -o wide switch shows where your app is running according to the default AEE location optimization strategy. Your app will be optimally deployed according to traffic. In lieu of significant traffic, your deployment will be made to default locations.

Try kubectl logs POD to see the log message reporting that the server is listening on port 1993 (Listening on http://localhost:1993/)

Finally, follow the instructions that configure DNS and TLS.

See What You've Built

See the "Hello World" app you've built by visiting the https://YOUR.DOMAIN.COM, substituting YOUR.DOMAIN.COM according to your DNS and HTTPS configuration.