Astro
Deploy your Astro Site with Deno
Deploy your Astro Site with Deno
import deno from '@deno/astro-adapter';
export default defineConfig({
output: 'server',
adapter: deno(),
});
```
Update your
previewscript inpackage.jsonwith the change below.// package.json { "scripts": { "dev": "astro dev", "start": "astro dev", "build": "astro build", "preview": "astro preview" "preview": "deno run --allow-net --allow-read --allow-env ./dist/server/entry.mjs" } }You can now use this command to preview your production Astro site locally with Deno.
```shell npm run preview ``` ```shell pnpm run preview ``` ```shell yarn run preview ```
How to deploy
You can run your Astro site on your own server, or deploy to Deno Deploy through GitHub Actions or using Deno Deploy’s CLI (command line interface).
On your own server
Install the project dependencies using your preferred package manager:
```shell npm install ``` ```shell pnpm install ``` ```shell yarn install ``` Build your Astro site with your preferred package manager:
```shell npm run build ``` ```shell pnpm run build ``` ```shell yarn run build ``` Start your application with the following command:
```bash deno run -A jsr:@std/http/file-server dist ``` ```bash deno run -A ./dist/server/entry.mjs ```
GitHub Actions Deployment
If your project is stored on GitHub, the Deno Deploy website will guide you through setting up GitHub Actions to deploy your Astro site.
Sign in on Deno Deploy with your GitHub account, and click on New Project.
Select your repository, the branch you want to deploy from, and select GitHub Action mode. (Your Astro site requires a build step, and cannot use Automatic mode.)
In your Astro project, create a new file at
.github/workflows/deploy.ymland paste in the YAML below. This is similar to the YAML given by Deno Deploy, with the additional steps needed for your Astro site.```yaml --- // .github/workflows/deploy.yml --- name: Deploy on: [push] 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@v6 # Not using npm? Change `npm ci` to `pnpm i` or `yarn install` - name: Install dependencies run: npm ci # Not using npm? Change `npm run build` to `pnpm run build` or `yarn run build` - name: Build Astro run: npm run build - name: Upload to Deno Deploy uses: denoland/deployctl@v1 with: project: my-deno-project # TODO: replace with Deno Deploy project name entrypoint: jsr:@std/http/file-server root: dist ``````yaml --- // .github/workflows/deploy.yml --- name: Deploy on: [push] 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@v6 # Not using npm? Change `npm ci` to `pnpm i` or `yarn install` - name: Install dependencies run: npm ci # Not using npm? Change `npm run build` to `pnpm run build` or `yarn run build` - name: Build Astro run: npm run build - name: Upload to Deno Deploy uses: denoland/deployctl@v1 with: project: my-deno-project # TODO: replace with Deno Deploy project name entrypoint: dist/server/entry.mjs ```After committing this YAML file, and pushing to GitHub on your configured deploy branch, the deploy should begin automatically!
You can track the progress using the "Actions" tab on your GitHub repository page, or on Deno Deploy.
CLI Deployment
```bash
deno install -gArf jsr:@deno/deployctl
```
Build your Astro site with your preferred package manager:
```shell npm run build ``` ```shell pnpm run build ``` ```shell yarn run build ``` Run
deployctlto deploy!```bash cd dist && deployctl deploy jsr:@std/http/file-server ``` ```bash deployctl deploy ./dist/server/entry.mjs ``` You can track all your deploys on Deno Deploy.
(Optional) To simplify the build and deploy into one command, add a
deploy-denoscript inpackage.json, adapting it for your preferred package manager.```json ins={8} // package.json { "scripts": { "dev": "astro dev", "start": "astro dev", "build": "astro build", "preview": "astro preview", "deno-deploy": "npm run build && cd dist && deployctl deploy jsr:@std/http/file-server" } } ``` ```json ins={8} // package.json { "scripts": { "dev": "astro dev", "start": "astro dev", "build": "astro build", "preview": "deno run --allow-net --allow-read --allow-env ./dist/server/entry.mjs", "deno-deploy": "npm run build && deployctl deploy ./dist/server/entry.mjs" } } ``` Then you can use this command to build and deploy your Astro site in one step.
```shell npm run deno-deploy ``` ```shell pnpm run deno-deploy ``` ```shell yarn run deno-deploy ```