DEV Community

aKuad
aKuad

Posted on • Edited on

3 (+1) ways of Deploy to Deno Deploy

What is Deno Deploy?

Deno Deploy is a hosting service for Deno by Deno Land Inc..

It requires only GitHub account. For free plan, no additional registers, credit-cards and payments are required.

Deploy methods

0. Playground

You can try it on a browser.

After login to Deno Deploy, then on Deploy dashboard, click 'New Playgroung'.

Deploy Dashboard - New Playground

Now code editor is here.

Deploy Playground

Write code here and save, then deployed soon. It live at the deno.dev URL what you can see upper right of the code editor.

It supports not only TS and JS, also TSX and JSX are.

Note
Project named with random words. On this screen-shot, it was fresh-crown-29.

1. deployctl CLI

This method deploys local files via deployctl CLI.

At first, install deployctl.

deno install -gArf jsr:@deno/deployctl

deployctl -h

# Other way to execute
~/.deno/bin/deployctl -h
Enter fullscreen mode Exit fullscreen mode

Next, make any working directory.

mkdir work
cd work
Enter fullscreen mode Exit fullscreen mode

Then write any HTTP server.

// main.ts
Deno.serve((req: Request) => new Response("Hello World"));
Enter fullscreen mode Exit fullscreen mode

At last, deploy it by deployctl. Nothing to do for dashboard.

ls
# main.ts

deployctl deploy --project=akuad-helloworld --entrypoint=main.ts
Enter fullscreen mode Exit fullscreen mode

Note
If specified project name is already in use, it be an error error: APIError: This project name is already in use. Set other project name.

At first time of deploy or few days elapsed deploy (session expired?), authentication page open on a browser. Authorize it.

Deploy Authentication

All done! On dashboard, you can see a created project.

Deploy Dashboard - Projects

Let's access the URL.

curl https://akuad-helloworld.deno.dev/
# Hello World
Enter fullscreen mode Exit fullscreen mode

To re-deploy with same project name, instance will be added to the project.

# After source editing, type same command
deployctl deploy --project=akuad-helloworld --entrypoint=main.ts
Enter fullscreen mode Exit fullscreen mode

Deploy Project detail

Note
prod badge means Production instance. The instance can be access with <project-name>.deno.dev.

To set production, click 'Promote to Production' in '︙' menu.

Deploy Project sub menu

Or set production on CLI, add --prod option when deploy.

deployctl deploy --project=akuad-helloworld --> entrypoint=main.ts --prod

2. GitHub repository + dashboard control

This method deploys GitHub repository files on browser control.

Click 'New Project' on dashboard.

Deploy Dashboard - New Project

Select a GitHub account and a repository.

Note
At first time, no repositories will be shown. Because Deno Deploy has no access permissions for all repositories. Click 'Modify GitHub Permissions' to grant permission.

Deploy New Project - Repo select

After selected a repository, project configuration will be shown.

Deploy New Project - Initial setting

Fill them, then click 'Deploy Project'. All done!

On pushed or merged to specified 'Production Branch', re-deploy automatically.

3. GitHub Actions

This method deploys GitHub repository files via GitHub Actions (CD).

Click 'New Project' on dashboard.

Deploy Dashboard - New Project

Select a GitHub account, a repository and a production branch. Check 'Just link the repo...', then click 'Create Project'. On this case, project configuration will not be shown.

Deploy New Project - Link setting

For next, let's setup GitHub Actions workflow on selected repository.

Sample workflow is on official docs.

name: Deploy
on:
  push:
    branches: main
  pull_request:
    branches: main

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest

    permissions:
      id-token: write # Needed for auth with Deno Deploy
      contents: read # Needed to clone the repository

    steps:
      - name: Clone repository
        uses: actions/checkout@v4

      - name: Install Deno
        uses: denoland/setup-deno@v2
        with:
          deno-version: v2.x

      - name: Build step
        run: "deno task build"

      - name: Upload to Deno Deploy
        uses: denoland/deployctl@v1
        with:
          project: "<your-project-name>"
          entrypoint: "main.ts"
          root: "."
Enter fullscreen mode Exit fullscreen mode

Note
entrypoint: is related path from root: directory.

Finally, when specified on: event triggered, it will be deployed.

All done! You don't have to manage any access tokens or environment variables.

Conclusion

You can start free deployment for Deno with Deno Deploy. Every ways are easy to start.

Top comments (0)