Introduction
Deno Deploy is a distributed system that allows you to run JavaScript, TypeScript, and WebAssembly close to users, at the edge, worldwide. Deeply integrated with the V8 runtime, Deno deploy servers provide minimal latency and eliminate unnecessary abstractions. You can develop your script locally using the Deno CLI, and then deploy it to our managed infrastructure in less than a second, without the need to configure anything.
Hint
Learn more on the official Deno Deploy website
Easy way
Grab an access token from your Deploy account page, then run
danet deploy --project my-api --token $DENO_DEPLOY_TOKENThe project is created for you if it does not exist yet.
Here are the options:
Usage: danet deploy --project <project> --token <token>
Description:
Deploy your project to Deno Deploy
Options:
-h, --help - Show this help.
-p, --project <project> - Deno deploy project name. (required)
-e, --entrypoint <entrypoint> - Bundle entrypoint file (Default: "run.ts")
-b, --bundle <bundle> - Bundle output file name, also used as deployctl entrypoint (Default: "bundle.js")
-t, --token <token> - Deno Deploy API token. (required)WARNING
The first deployment of a project is pushed to production. Every deployment after that one is a preview deployment with its own URL. To promote a later build, bundle it and call deployctl yourself with --prod:
danet bundle app.js
deployctl deploy --prod --project my-api bundle/app.jsAdvanced way
First step
Create an account
Before diving into the (few) commands required to deploy your Danet project from your local environment or from a Github action, you need to create an account on Deno Deploy.
There is a free tier, generous enough for a side project, and paid plans when you outgrow it. Prices and quotas change, so read them at the source: deno.com/deploy/pricing.
The signing up process is pretty simple, login with github and voilà.
Hint
The Github integration allows you to deploy from Github actions without the need of any secret/environment variable
Create a project
Now that you have an account, you need to create a Deploy project to deploy to.
Thanks to Github integration, you have access to your repository list, and can easily select which repo you want to deploy on this project.
Then, you must select the branch which will be deployed, and how will be your Continuous Deployment:
- Automatic, so your project is deployed on pushes as is
- Github Action, if you want to add a build step before deploying.
For Danet project, we need to select "Github Action".
Last input is to name your project, this will also be your project subdomain.
Deploy from your local environment
If you want a fast way to test deploy, you can easily do so in 1 commands.
TLDR:
$ danet deploy --project my-api --token $DENO_DEPLOY_TOKENBundle your application
Bundling is the action of creating one JS file which contains all your project source code. We recommend that you use danet bundle command to bundle, but feel free to use any bundler you want as long as it handles "emitDecoratorMetadata" option.
The argument is the output file name, the input is --entrypoint (default run.ts). The result is written to the ./bundle folder, which is deleted and recreated on every run.
$ danet bundle my-app.jsManually Deploy to DD
Now that you have your whole app bundled, you can send this .js file to deploy. In order to do so, you need to get your access token from Deploy
$ cd bundle && deployctl deploy --project=YOUR_PROJECT_NAME my-app.jsGithub Action
If you created your project with our CLI, you already have a workflow ready in .github/workflows/run-tests.yml to be used, you simply need to put your project name in the last step :
- name: Deploy to Deno Deploy
uses: denoland/deployctl@v1
with:
project: YOUR PROJECT NAME HERE
entrypoint: run.js
root: bundleIf you don't have it (because you used an older version of the starter project), we got your back.
Create a yaml file in .github/workflows folder, something like deploy.yml Follow these steps :
Setup the workflow:
name: Deploy to Deno Deploy
on:
push:
branches: [main]
permissions:
contents: read
id-token: write # Needed for auth with Deno DeploySetup jobs
Then, we need a job to run, which is what will be done on push.
- Pull the repository.
- Setup Deno (install it on the worker).
- Install Danet CLI.
- Bundle our app with
danet bundlecommand - Send the bundle on Deploy
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v4
- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Install Danet CLI
run: deno install -A -g -n danet jsr:@danet/cli
- name: Bundle app with danet CLI
run: danet bundle run.js
- name: Deploy to Deno Deploy
uses: denoland/deployctl@v1
with:
project: YOUR-PROJECT-NAME
entrypoint: run.js
root: bundleFull working example
Check our own workflow on the Starter project here
Danet