Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/deployments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,49 @@ jobs:
CF_ACCOUNT_ID: ${{ secrets.TEST_CF_ACCOUNT_ID }}
CF_API_TOKEN: ${{ secrets.TEST_CF_API_TOKEN }}

# "deploy deploy" is not a typo, we are deploying to Deno Deploy
deno_deploy_deploy:
name: "Deno Deploy Deploy"
if: github.repository == 'remix-run/remix'
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"

# some deployment targets require the latest version of npm
# TODO: remove this eventually when the default version we get
# is "latest" enough.
- name: 📦 Install latest version of npm
run: npm install -g npm@latest
working-directory: ./scripts/deployment-test

- name: 📥 Install deployment-test deps
uses: bahmutov/npm-install@v1
with:
working-directory: ./scripts/deployment-test
useLockFile: false

- name: 🦕 Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: vx.x.x
- name: 🦕 Deno Deploy CLI
run: deno install --allow-read --allow-write --allow-env --allow-net --allow-run --no-check -r -f https://deno.land/x/deploy/deployctl.ts

- name: 🚀 Deploy to Deno Deploy
run: node ./deno-deploy.mjs
working-directory: ./scripts/deployment-test
env:
DENO_DEPLOY_TOKEN: ${{ secrets.TEST_DENO_DEPLOY_TOKEN }}

fly_deploy:
name: "Fly Deploy"
if: github.repository == 'remix-run/remix'
Expand Down
51 changes: 51 additions & 0 deletions scripts/deployment-test/deno-deploy.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { sync as spawnSync } from "cross-spawn";
import { createApp } from "@remix-run/dev";

import {
getAppDirectory,
getAppName,
getSpawnOpts,
validatePackageVersions,
} from "./_shared.mjs";

let DENO_DEPLOY_PROJECT_NAME= "remix-deno-deploy-test"
let APP_NAME = getAppName(DENO_DEPLOY_PROJECT_NAME);
let PROJECT_DIR = getAppDirectory(APP_NAME);

async function createNewApp() {
await createApp({
appTemplate: "deno",
installDeps: false,
useTypeScript: true,
projectDir: PROJECT_DIR,
});
}

try {
// create a new remix app
await createNewApp();

// validate dependencies are available
await validatePackageVersions(PROJECT_DIR);

let spawnOpts = getSpawnOpts(PROJECT_DIR);

// install deps
spawnSync("npm", ["install"], spawnOpts);
spawnSync("npm", ["run", "build"], spawnOpts);

// deploy to deno deploy
let deployCommand = spawnSync(
"deployctl",
["deploy", "--prod", "--include=public,build", `--project=${DENO_DEPLOY_PROJECT_NAME}`, "./build/index.js"],
spawnOpts
);
if (deployCommand.status !== 0) {
throw new Error("Deploying to Deno Deploy failed");
}

console.log(`Deployed to ${DENO_DEPLOY_PROJECT_NAME}.deno.dev`);
} catch (error) {
console.error(error);
process.exit(1);
}
5 changes: 5 additions & 0 deletions templates/deno/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"denoland.vscode-deno"
]
}
55 changes: 54 additions & 1 deletion templates/deno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ npm run dev

This starts your app in development mode, rebuilding assets on file changes.

### Type hints

This template provides type hinting to VS Code via a [dedicated import map](./.vscode/resolve_npm_imports.json).

To get types in another editor, use an extension for Deno that supports import maps and point your editor to `./.vscode/resolve_npm_imports.json`.

For more, see [our decision doc for interop between Deno and NPM](https://github.com/remix-run/remix/blob/main/decisions/0001-use-npm-to-manage-npm-dependencies-for-deno-projects.md#vs-code-type-hints).

## Production

First, build your app for production:
Expand All @@ -58,4 +66,49 @@ Building the Deno app (`npm run build`) results in two outputs:
- `build/` (server bundle)
- `public/build/` (browser bundle)

You can deploy these bundles to a host of your choice, just make sure it runs Deno!
You can deploy these bundles to any host that runs Deno, but here we'll focus on deploying to [Deno Deploy](https://deno.com/deploy).

## Setting up Deno Deploy

1. [Sign up](https://dash.deno.com/signin) for Deno Deploy.

2. [Create a new Deno Deploy project](https://dash.deno.com/new) for this app.

3. Replace `<your deno deploy project>` in the `deploy` script in `package.json` with your Deno Deploy project name:

```json
{
"scripts": {
"deploy": "deployctl deploy --project=<your deno deploy project> --include=.cache,build,public ./build/index.js"
}
}
```

4. [Create a personal access token](https://dash.deno.com/account) for the Deno Deploy API and export it as `DENO_DEPLOY_TOKEN`:

```sh
export DENO_DEPLOY_TOKEN=<your Deno Deploy API token>
```

You may want to add this to your `rc` file (e.g. `.bashrc` or `.zshrc`) to make it available for new terminal sessions, but make sure you don't commit this token into `git`.
If you want to use this token in GitHub Actions, set it as a GitHub secret.

5. Install the Deno Deploy CLI, [`deployctl`](https://github.com/denoland/deployctl):

```sh
deno install --allow-read --allow-write --allow-env --allow-net --allow-run --no-check -r -f https://deno.land/x/deploy/deployctl.ts
```

6. If you have previously installed the Deno Deploy CLI, you should update it to the latest version:

```sh
deployctl upgrade
```

### Deploying to Deno Deploy

After you've set up Deno Deploy, run:

```sh
npm run deploy
```
1 change: 1 addition & 0 deletions templates/deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"sideEffects": false,
"scripts": {
"build": "remix build",
"deploy": "deployctl deploy --prod --include=build,public --project=<your deno deploy project> ./build/index.js",
"dev": "remix build && run-p dev:*",
"dev:deno": "cross-env NODE_ENV=development deno run --unstable --watch --allow-net --allow-read --allow-env ./build/index.js",
"dev:remix": "remix watch",
Expand Down