How to deploy a Deno application

Rejoice! The long-awaited Deno 1.0 release is among us. What is Deno you ask?

Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.

More Rust code is often something that makes us happy at Clever Cloud. So purely based on this, and because we like new, shiny toys, here’s how to deploy a Deno application on Clever Cloud.

Clever Cloud being a PaaS, there are a bunch of things that can happen automatically, some that can be configured through environment variables. But Deno is not fully integrated to all our tooling yet, so instead we are going to use a NodeJS application with a twist.

I am going to assume you already have our CLI Clever-tools installed, npm and git as well.

First thing first, create a git repo and a node package:

git init
npm init

Then we install Deno. And if there is something I do not like, it’s executing arbitrary shell script from the internet. So I am not going to use their installer. Deno is available as a downloadable binary from their Github Repo. It will do just fine in our case. Create a new folder for your application. From now on every file should be created in that folder.

Here’s a shell script that will manage the download and extraction of a specific Deno version:

wget https://github.com/denoland/deno/releases/download/$DENO_VERSION/deno-x86_64-unknown-linux-gnu.zip
unzip deno-x86_64-unknown-linux-gnu.zip

Notice the use of $DENO_VERSION that will define which one will be downloaded. Let’s call this file installdeno.sh and make it executable:

chmod +x installdeno.sh

And now we can create the Clever Cloud application:

clever create --type node myDenoApplication

As I wrote earlier, we can specify custom behavior with environment variable. So let’s add one that will automate the installation of Deno with our script and one to specify the version we want:

clever env set CC_PRE_BUILD_HOOK ./installdeno.sh
clever env set DENO_VERSION v1.0.0 

You can execute arbitrary scripts during the deployment of the application; here we want to execute installdeno.sh before the build phase. You’ll find the list of hooks in our dedicated documentation.

For the application itself, I took a look at the available Deno module and because I am super lazy I chose the first web framework of the list, abc. There is an Hello World example in the Readme, that’s perfect for this test. So go ahead and create abc.js with the following content:

import { Application } from "https://deno.land/x/abc/mod.ts";

const app = new Application();

app
  .get("/", (c) => {
    return "Hello, Abc!";
  })
  .start({ port: 8080 });

The remaining question is, how do we launch this application? Remember that on Clever Cloud, the run process looks at your package.json the main file or start script to know what to execute. Let’s use this to our advantage and simply add a start script that uses the Deno binary downloaded by the script.

{
  "name": "abc-test",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start":"./deno run --allow-net abc.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

The only thing left to do is to commit your code and deploy it:

git add abc.js installdeno.sh package.json
clever deploy

From there you should see logs of your deployment showing up. The final message should be Deployment successful. Now type clever open and it will automatically open the website in your default browser.

Granted, this is a little raw and it could feel like cheating but it works and your app benefits from all the Clever Cloud good stuffs, just like any another application:

  • environment variables injection
  • monitoring & alerting (auto restart)
  • zero downtime deployments
  • metrics (data & charts)
  • live logs
  • automatic scalability

If we see a growing interest in Deno in our community we will make sure it’s available with a proper, dedicated and simpler support. Let us know what you think about it and if you intend to use it!

Blog

À lire également

MateriaDB KV, Functions: discover the future of Clever Cloud at Devoxx Paris 2024

Clever Cloud is proud to present its new range of serverless products: Materia!
Company

Our new logs interface is available in public beta

You can now discover our new log stack interface and its new features!
Company

Deploy from GitLab or GitHub

Over the past few months, some customers have raised questions about CI/CD building to deploy…

Engineering