🤫 You're sleeping on Deno Deploy - Part 1: Static Astro Deployments

I recently searched for a simple way to deploy a static site, compiled from an astro codebase. My first thoughts went to

But, they all have problems I don’t like:

After some more searching, I found this nice trick to host simple static sites on deno deploy:

# Entrypoint 
jsr:@std/http/file-server

How to deploy a static site on Deno Deploy

Prepare the repo

  1. Make a repo which has static files or can output static files, like astro.

  2. Build the site (I use bun for that): bun run build => this will create a dist folder with the static files (only for testing or deploying with deployctl).

  3. Add a .github/workflows/deploy.yaml file with the following content:

    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: Install Node.js
               uses: actions/setup-node@v4
               with:
                  node-version: lts/*
    
             - name: Install bun
               uses: oven-sh/setup-bun@v2
    
             - name: Install step
               run: "bun install"
    
             - name: Build step
               run: "bun run build"
    
             - name: Upload to Deno Deploy
               uses: denoland/deployctl@v1
                 with:
                   project: "blog-deno-astro-static"
                   entrypoint: "jsr:@std/http/file-server"
                   root: "dist"
  4. Some notes to this github actions file:

    • Since I use bun to manage dependencies and build the site, I have to add the bun install step.
    • In the last step, you can replace the projectname with your own project name you want to have on deno deploy.

    You can also see the most important part of this blogpost here – the entrypoint field!

    Deno Deploy expects your repo to contain a kind of server.ts or server.mjs file which starts a server itself. However, we only want to host static files, so we don’t have a js/ts module with server code in it.

    The trick is now: we can simply use ANY jsr Module as an entrypoint, which runs a server! Kindly the deno team offers us the package jsr:@std/http/file-server which we can use as our entrypoint! Since we set the root directory to dist, it will simply serve up the whole folder and we’re good to go! *1

  5. Make sure to commit the github actions file to the repo!

Create the project in Deno Deploy

Create the project in Deno Deploy

  1. Go to deno deploy, register if needed and create a new project with the black button (or with the assistant, if this is your first project).

    A screenshot showing the black 'New Project' button on the deno deploy dashboard
  2. Select a repo from your connected github account as the source. If you want to use the deployctl as described there, you can do so with the local build you did earlier. But for this blogpost, we’ll use the github integration.

    A screenshot of the deno deploy dashboard showing the dropdown to connect to a github repo or use the commandline
  3. With the right repo selected, you’ll see that deno deploy automatically detects, that this is an astro project.

    A screenshot of the deno deploy dashboard showing the astro detection of our repo
  4. In the project config below, make sure to select Just link the repo, I'll setup github actions myself !

    A screenshot of the deno deploy dashboard showing the project config - part 1
  5. Now we can click on Deploy and wait for the build to finish.

    A screenshot of the deno deploy dashboard showing the build in progress

And so it runs!

You can view the example deployment at: https://blog-deno-astro-static.deno.dev/

Please write me on Bluesky or X/Twitter if you have any questions or feedback!


*1 Serving the whole dist folder might not be enough when hosting static single page apps. The deno team is working on a new deno deploy version which will fully support serving single page apps. It is in Early Access right now, so it’s called Deno Deploy EA