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
20 changes: 16 additions & 4 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Node.js CI

on:
push:
branches: [master, develop]
branches: [master]
pull_request:
branches: [master]

Expand All @@ -14,17 +14,29 @@ jobs:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [18.x]
# 18.x: oldest Node in CI (engines allows >=16.20.2).
# 22.x: matches .nvmrc; builds and serves vision.hyphy.org (DEPLOY.md).
# 24.x: current LTS; flags breakage before production moves to it.
node-version: [18.x, 22.x, 24.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn build
- name: Smoke-test server.js
run: |
test -s dist/index.html
test -s dist/hyphyvision.js
PORT=8000 node server.js &
for i in $(seq 1 20); do curl -fsS -o /dev/null http://localhost:8000/ && break; sleep 1; done
curl -fsS -o /dev/null http://localhost:8000/
curl -fsS -o /dev/null 'http://localhost:8000/fel?json=https://example.org/results.FEL.json'
- run: yarn test
env:
CI: true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
225 changes: 225 additions & 0 deletions DEPLOY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# Deploying vision.hyphy.org

This is the build-and-deploy procedure for the hosted HyPhy Vision site at
<https://vision.hyphy.org>. It exists because the live site once drifted 27
commits behind `master` without anyone noticing (#899). Merging to `master`
does **not** deploy anything; a maintainer has to run the steps below.

Items marked **TODO (maintainer)** could not be confirmed from the repository
or from the last deploy and should be filled in by someone with host access.

## Topology

| Piece | Where | Notes |
| --- | --- | --- |
| TLS + reverse proxy | nginx on `junglegym`, site config `/etc/nginx/conf.d/hyphy.conf` | Proxies `vision.hyphy.org` to `datamonkey-main:8000` and adds `Access-Control-Allow-Origin: *`. TLS certificate: `/etc/letsencrypt/live/hyphy.org/` (includes `vision.hyphy.org`; renewal config `/etc/letsencrypt/renewal/hyphy.org.conf`). |
| App server | datamonkey host (`datamonkey-main`) | `node server.js` (Express, serves the static `dist/` folder, falls back to `dist/index.html` for every other path). Listens on `PORT`, default `8000`. Production does not set `PORT`, so it uses the code default. |
| Process manager | pm2 app **`hyphy-vision`**, run as the **`node`** user | Fork mode, one instance, autorestart on, no watch. Logs: `~/.pm2/logs/hyphy-vision-{out,error}.log`. |
| Live checkout | `/home/node/hyphy-vision` | `dist/` is git-ignored, so it is a build artifact that lives only on the host. |
| Staging clone | `/home/node/hyphy-vision-next` | Separate clone used to build and smoke-test before swapping. |

The app was originally started with a bare `pm2 start server.js` from
`/home/node/hyphy-vision`: no arguments, no app-specific environment
variables, and no ecosystem file. `pm2 describe hyphy-vision` was the only
record of its definition. The repository now has `ecosystem.config.js`,
which reproduces that definition with the Node interpreter pinned (see
below).

## Node versions

| Purpose | Node | How it is selected |
| --- | --- | --- |
| Building (`webpack`) | 22 | `.nvmrc`; run `nvm use` in the checkout (v22.11.0 is installed under nvm). |
| Serving (`pm2` → `server.js`) | 22 (target); currently 17.9.1 | pm2 `interpreter`, see below. |

`package.json` `engines` allows `>=16.20.2`, and CI builds on 18, 22 and 24.
Use **Yarn 1 (classic)**; `yarn.lock` is a v1 lockfile and Yarn 2+ refuses
it.

### How pm2 picks the Node for `hyphy-vision`

The `hyphy-vision` pm2 app has `interpreter: node` (a bare name, not a path),
so it runs whatever Node the `node` user's **nvm default alias** points to:
v17.9.1 (EOL) as of 2026-10-06.

**Do not change the nvm default alias.** Several other pm2 apps under the
`node` user also use a bare `interpreter: node` (among them hivtrace-viz,
webhooks, phylotree, blog and mutation-dashboard). Changing the default would
silently move all of them to a new Node on their next restart. To move
`hyphy-vision` to Node 22, re-create that app only from `ecosystem.config.js`,
which sets an absolute interpreter path (`~/.nvm/versions/node/v22.11.0/bin/node`,
overridable with `HYPHY_VISION_NODE`):

```sh
cd /home/node/hyphy-vision
pm2 delete hyphy-vision
pm2 start ecosystem.config.js
pm2 save
pm2 describe hyphy-vision | grep -iE 'interpreter|node.js version|exec cwd'
```

The host runs pm2 3.5.2. That version loads a `.js` ecosystem file but not a
`.cjs` one; `package.json` has no `"type": "module"`, so the `.js` file is
CommonJS. These steps were tested with pm2 3.5.2 on Node 17.9.1 running the
app on Node 22. The site is down between `pm2 delete` and `pm2 start` (a few
seconds). To roll
back, run the same commands with `HYPHY_VISION_NODE=$HOME/.nvm/versions/node/v17.9.1/bin/node`
set. Once the app runs from the ecosystem file, the `pm2 restart hyphy-vision`
in the deploy procedure keeps the pinned interpreter. After the switch, update
the table above.

## Build command

```sh
yarn install --frozen-lockfile
yarn build
```

The build needs no `NODE_OPTIONS` flags on any supported Node (#896). Do not
edit the `build` script on the host; the live checkout once carried such an
uncommitted edit, and it broke the build.

On a successful build, webpack removes files in `dist/` that the build did
not emit, so stale hashed assets do not pile up (#898). A failed build leaves
`dist/` untouched. Files are still replaced in place while the build emits,
so never build inside the live checkout; build in the staging clone and swap
(below).

## Deploy procedure

Run everything as the `node` user in a login shell, so nvm is loaded. Set the
shell variables once:

```sh
LIVE=/home/node/hyphy-vision
NEXT=/home/node/hyphy-vision-next
BACKUP=/home/node/hyphy-vision-backups/$(date +%Y%m%d-%H%M%S)
```

The 2026-10-06 deploy predates this layout. Its backups are in the `node`
user's home: `~/hv-prev-sha` (previous HEAD `585f6a9`),
`~/hv-local-drift.patch` and `~/hv-dist-backup`.

### 1. Back up the live state

```sh
mkdir -p "$BACKUP"
git -C "$LIVE" rev-parse HEAD > "$BACKUP/HEAD.sha"
git -C "$LIVE" status --porcelain > "$BACKUP/status.txt"
git -C "$LIVE" diff HEAD > "$BACKUP/uncommitted.diff"
cp -a "$LIVE/dist" "$BACKUP/dist"
```

If `uncommitted.diff` is not empty, find out why before continuing. Local
edits on the host are how the build script drift in #896 went unnoticed.

### 2. Build in the staging clone

```sh
cd "$NEXT"
git fetch origin
git reset --hard origin/master
nvm use
yarn install --frozen-lockfile
yarn build
```

### 3. Check that the build produced output

Do not swap unless these pass; `rsync --delete` from an empty `dist/` would wipe the live site:

```sh
test -s "$NEXT/dist/index.html" && test -s "$NEXT/dist/hyphyvision.js" \
&& echo "dist OK" || echo "dist MISSING: stop here"
```

### 4. Smoke-test the staging build on a spare port

```sh
cd "$NEXT"
PORT=8001 node server.js &
SMOKE_PID=$!
sleep 2
curl -fsS -o /dev/null -w '%{http_code} /\n' http://localhost:8001/
curl -fsS -o /dev/null -w '%{http_code} deep link\n' \
'http://localhost:8001/fel?json=https://example.org/results.FEL.json'
kill "$SMOKE_PID"
```

Both should print `200`. The `?json=` page is rendered client-side, so curl
only proves the route serves `index.html`. Open a real deep link in a browser
too (see step 6).

### 5. Swap

```sh
git -C "$LIVE" fetch origin
git -C "$LIVE" reset --hard origin/master
(cd "$LIVE" && nvm use && yarn install --frozen-lockfile --production)
rsync -a --delete "$NEXT/dist/" "$LIVE/dist/"
pm2 restart hyphy-vision
```

The `yarn install` keeps the live `node_modules` in step with the new
commit, so `server.js` does not run against a stale Express if a release
changes the server's dependencies. `--production` skips the build toolchain,
which the live checkout does not need.

Reset the live checkout to the same commit you built in `$NEXT`. If `master`
moved between steps 2 and 5, reset to `git -C "$NEXT" rev-parse HEAD` instead.

`--delete` removes stale hashed assets from the live `dist/`. The last deploy
used rsync; whether it passed `--delete` was not recorded.

### 6. Smoke-test production

```sh
curl -fsS -o /dev/null -w '%{http_code}\n' https://vision.hyphy.org/
curl -fsS -o /dev/null -w '%{http_code}\n' \
'https://vision.hyphy.org/fel?json=https://example.org/results.FEL.json'
pm2 status hyphy-vision
```

Then open a `?json=` deep link to a real, reachable results file in a browser
and confirm that the results render. Use one of the method routes
(`/absrel`, `/busted`, `/fel`, `/meme`, `/relax`, ...); see
`src/jsx/app.jsx` for the full list.

**TODO (maintainer):** record a stable public results JSON URL to use as the
canonical deep-link smoke test.

## Rollback

```sh
git -C "$LIVE" reset --hard "$(cat "$BACKUP/HEAD.sha")"
rsync -a --delete "$BACKUP/dist/" "$LIVE/dist/"
pm2 restart hyphy-vision
```

If the backup had local edits, reapply them with
`git -C "$LIVE" apply "$BACKUP/uncommitted.diff"`. Then repeat the step 6
smoke checks.

## Release checklist

The git history records releases as a single commit titled `vX.Y.Z` that only
bumps `version` in `package.json`, plus a matching annotated tag `vX.Y.Z`
pushed to `origin` (latest: `v2.15.10`). `yarn version` / `npm version`
produce exactly that. `CONTRIBUTING.md` asks for Semantic Versioning and
publishing releases to npm.

1. CI ("Node.js CI", `.github/workflows/nodejs.yml`) is green on `master`.
2. Bump the version and tag it, then push both:
```sh
VERSION=2.15.11 # the new version
yarn version --new-version "$VERSION"
git push origin master --follow-tags
```
3. Deploy vision.hyphy.org using the procedure above. Record the deployed
commit SHA. `git -C /home/node/hyphy-vision log -1 --oneline` should match
the tag.
4. **TODO (maintainer):** decide whether every release also gets an npm
publish (the registry has `hyphy-vision@2.15.10`; the library bundle is
built with `yarn build:library`, see `CONTRIBUTING.md`) and a GitHub
Release (the latest GitHub Release is `2.14.0` from December 2023, older
than the latest tag).
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ yarn start

## Deployment

Deploy in a production environment:

```
webpack
supervisor server.js
```
Merging to `master` does not update the hosted site. See [DEPLOY.md](DEPLOY.md)
for how vision.hyphy.org is built, deployed, smoke-tested and rolled back, and
for the release checklist.

## Electron

Expand Down
25 changes: 25 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// pm2 definition for vision.hyphy.org (see DEPLOY.md). Kept as CommonJS .js,
// not .cjs, because the host runs pm2 3.5.2, which does not load .cjs files.
//
// The interpreter is an absolute path so that the app does not follow the
// node user's nvm default alias, which other pm2 apps on the host share.
// Override with HYPHY_VISION_NODE=/path/to/node if the installed v22 differs.
const path = require("path");
const os = require("os");

module.exports = {
apps: [
{
name: "hyphy-vision",
script: "server.js",
cwd: __dirname,
interpreter:
process.env.HYPHY_VISION_NODE ||
path.join(os.homedir(), ".nvm/versions/node/v22.11.0/bin/node"),
exec_mode: "fork",
instances: 1,
autorestart: true,
watch: false
}
]
};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
},
"main": "dist/hyphyvision.js",
"version": "2.15.10",
"engines": {
"node": ">=16.20.2"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.3",
"@hyphy_software/fel-analysis-result-visualization": "https://api.observablehq.com/@hyphy_software/fel-analysis-result-visualization@2311.tgz?v=3",
Expand Down Expand Up @@ -140,8 +143,8 @@
"webpack-eslint-plugin": "^1.2.0"
},
"scripts": {
"build": "export NODE_OPTIONS=--openssl-legacy-provider;webpack --mode production",
"build:library": "export NODE_OPTIONS=--openssl-legacy-provider;webpack --config webpack.config.library.js",
"build": "webpack --mode production",
"build:library": "webpack --config webpack.config.library.js",
"which-webpack": "which webpack",
"lint": "eslint --ext .js,.jsx --ignore-pattern public,static,dist ./src/",
"test": "node ./node_modules/jest-cli/bin/jest.js",
Expand Down
32 changes: 17 additions & 15 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ module.exports = (env) => {
path: path.resolve(__dirname, "dist/"),
filename: "[name].js",
library: "hyphyVision",
hashFunction: "xxhash64",
// Asset and chunk names are content hashes, so remove the previous
// build's files instead of leaving stale ones in dist/.
clean: true,
},
optimization: {
splitChunks: {
Expand Down Expand Up @@ -84,25 +88,23 @@ module.exports = (env) => {
},
},
},
// Fonts and images use webpack 5 asset modules instead of
// url-loader/file-loader. Those loaders hash file names with MD4 via
// node's crypto, which OpenSSL 3 rejects unless node runs with
// --openssl-legacy-provider (a flag older nodes refuse). Asset modules
// hash with output.hashFunction, so the build needs no flag.
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [
{
loader: "url-loader",
options: {
limit: 10000,
mimetype: "application/font-woff",
},
test: /\.woff(2)?(\?\S*)?$/,
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 10000,
},
],
},
},
{
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)(\?\S*)?$/,
use: [
{
loader: "file-loader",
},
],
test: /\.(eot|ttf|svg|png|jpg|gif)(\?\S*)?$/,
type: "asset/resource",
},
],
},
Expand Down
Loading
Loading