Skip to content

Commit 643077a

Browse files
docs: add sops (#147)
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com> Co-authored-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com>
1 parent ccc7553 commit 643077a

13 files changed

+322
-38
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ The steps below will give you a general idea of how to prepare your local enviro
108108
npm run test:e2e
109109
```
110110
111-
10. Once you're happy with your changes, add and commit them to your branch, then push the branch to your fork.
111+
10. To run the worker locally, see [Dev Setup](./docs/dev-setup.md).
112+
113+
11. Once you're happy with your changes, add and commit them to your branch, then push the branch to your fork.
112114

113115
```bash
114116
git add .
@@ -119,7 +121,7 @@ The steps below will give you a general idea of how to prepare your local enviro
119121
> [!IMPORTANT]\
120122
> Before committing and opening a Pull Request, please go first through our [Commit](#commit-guidelines) and [Pull Request](#pull-request-policy) guidelines outlined below.
121123

122-
11. Create a Pull Request.
124+
12. Create a Pull Request.
123125

124126
### CLI Commands
125127

docs/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Documentation
2+
3+
Documentation for the Release Worker.
4+
5+
## Table of Contents
6+
7+
- [Architecture](./architecture.md)
8+
- [Dev Setup](./dev-setup.md)
9+
- [Debugging Production](./debugging-prod.md)
10+
- [Deploying](./deploying.md)
11+
- [R2](./r2.md)
12+
- [Node.js Release Process](./release-process.md)

docs/architecture.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Architecture
2+
3+
Documentation on the architecture of the worker (i.e. how it works, how it fits into Node.js' infrastructure, etc.).
4+
5+
## Network Request Flow
6+
7+
A high-level overview of how a request flows through Node.js' infrastructure:
8+
9+
```mermaid
10+
flowchart LR
11+
request[Request] --> cloudflare(Cloudflare Routing Rules)
12+
cloudflare -- /dist/, /download/, /docs/, /api/, /metrics/ --> worker@{ shape: procs, label: "Release Worker"}
13+
cloudflare -- /... --> website(Website)
14+
worker -- Cache miss --> r2[(R2 bucket)]
15+
worker -- Error --> originServer(Origin Server)
16+
originServer
17+
website
18+
r2
19+
```
20+
21+
## Worker Request Flow
22+
23+
The Release Worker uses a middleware approach to routing requests.
24+
25+
When an instance of the worker starts up, it registers a number of routes and their middlewares.
26+
It then builds a "chain" of middlewares to call in the same order they're given to handle the request.
27+
28+
When a request hits the worker, the router gives it to the first middleware in the chain.
29+
That middleware can then either handle the request and return a response or pass it onto the next middleware.
30+
This goes on until the request is handled or we run out of middlewares to handle the request, upon which we throw an error.
31+
32+
We currently have the following middlewares (in no particular order):
33+
34+
- [CacheMiddleware](../src/middleware/cacheMiddleware.ts) - Caches responses to GET request.
35+
- [R2Middleware](../src/middleware/r2Middleware.ts) - Fetches resource from R2.
36+
- [OriginMiddleware](../src/middleware/originMiddleware.ts) - Fetches resource from the origin server.
37+
Used as a fallback if the R2 middleware fails.
38+
- [NotFoundMiddleware](../src/middleware/notFoundMiddleware.ts) - Handles not found requests.
39+
- [OptionsMiddleware](../src/middleware/optionsMiddleware.ts) - Handles OPTIONS requests.
40+
- [SubstituteMiddleware](../src/middleware/subtituteMiddleware.ts) - Handles requests that need URL substituing (i.e. `/dist/latest/` -> `/dist/<latest version>`) and then feeds them back into the router.
41+
42+
### Diagram
43+
44+
```mermaid
45+
flowchart TD
46+
request[Request] --> worker(Release Worker)
47+
worker --> routerHandle("Router.handle")
48+
routerHandle -- HTTP GET --> cacheMiddleware("Cache Middleware")
49+
routerHandle -- HTTP HEAD --> r2Middleware
50+
routerHandle -- HTTP OPTIONS --> optionsMiddleware("Options Middleware")
51+
routerHandle -- Request --> substituteMiddleware("Substitute Middleware")
52+
substituteMiddleware -- Substituted Request --> routerHandle
53+
cacheMiddleware -- Cache miss --> r2Middleware("R2 Middleware")
54+
r2Middleware -- Error --> originMiddleware("Origin Middleware")
55+
```

docs/debugging-prod.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Debugging Prod
2+
3+
Steps to aid with debugging the Release Worker's production environment.
4+
5+
> [!NOTE]
6+
> This is mostly meant for Node.js Web Infra team members.
7+
> Some of these steps require access to resources only made available to Collaborators.
8+
9+
## Steps
10+
11+
- Check [Sentry](https://nodejs-org.sentry.io/issues/?project=4506191181774848).
12+
All errors should be reported here.
13+
14+
- If a local reproduction is found, Cloudflare has an implementation of [Chrome's DevTools](https://developers.cloudflare.com/workers/observability/dev-tools/).
15+
16+
- Cloudflare provides basic stats on the worker's Cloudflare dash page [here](https://dash.cloudflare.com/07be8d2fbc940503ca1be344714cb0d1/workers/services/view/dist-worker/production).

docs/deploy.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/deploying.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Deploying the Worker
2+
3+
Guide on how to deploy the Release Worker.
4+
5+
## Staging Deployments
6+
7+
The Release Worker is automatically deployed to its staging environment when a new commit is pushed to the `main` branch through the [Deploy Worker](https://github.com/nodejs/release-cloudflare-worker/actions/workflows/deploy.yml) action.
8+
9+
## Production Deployments
10+
11+
The Release Worker is deployed to its production environment by a Collaborator manually running the [Deploy Worker](https://github.com/nodejs/release-cloudflare-worker/actions/workflows/deploy.yml) action.

docs/dev-setup.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
# Dev Setup
22

3-
Guide to setting up this worker for development.
3+
Documentation on how to run the Release Worker locally.
44

5-
## Have Node Installed
5+
## Steps
66

7-
Node needs to be installed for the thing that serves Node downloads (latest LTS/even numbered major recommended)
7+
### 1. Prepare environment
88

9-
## Install Dependencies
9+
Read and follow the [Getting Started](../CONTRIBUTING.md) guide to get your local environment setup.
1010

11-
Run `npm install`
11+
### 2. Setup your Cloudflare account
1212

13-
## Testing
13+
Currently we run the worker in [remote mode](https://developers.cloudflare.com/workers/testing/local-development/#develop-using-remote-resources-and-bindings) as there isn't a nice way to locally populate an R2 bucket.
14+
This means that, to run the Release Worker locally, you must have a Cloudflare account that has an R2 bucket named
15+
`dist-prod`.
16+
You will also need to populate the bucket yourself.
1417

15-
To run unit tests, `npm run test:unit`. To run e2e (end-to-end) tests, `npm run test:e2e`.
18+
Both of these will hopefully change in the future to make running the Release Worker easier.
1619

17-
See the [/test](../tests/) folder for more info on testing.
20+
### 3. Create secrets for directory listings
1821

19-
## Running Locally
22+
This step is optional but recommended.
2023

21-
Spin up a Workerd instance on your machine that serves this worker
24+
The Release Worker uses R2's S3 API for directory listings.
25+
In order for directory listings to work, you need to make an R2 API key for your `dist-prod` bucket and provide it to the worker.
2226

23-
### Login to Cloudflare Dash From Wrangler CLI
27+
Generating the API key can be done through the Cloudflare dashboard [here](https://dash.cloudflare.com/?account=/r2/api-tokens).
2428

25-
Run `wrangler login`
29+
Then, make a `.dev.vars` file in the root of this repository with the following:
2630

27-
### R2 Bucket
31+
```
32+
S3_ACCESS_KEY_ID=<your access key id>
33+
S3_ACCESS_KEY_SECRET=<your access key secret>
34+
```
2835

29-
Create a R2 bucket named `dist-prod`. This is the bucket that the worker read from. It will either need to have a copy of Node's dist folder in it or something mimicing the folder there.
36+
### 4. Run the worker
3037

31-
### Starting the Local Server
32-
33-
Run `npm start`. This starts a Workerd instance in remote mode.
38+
Start the worker locally with `npm start`. You may be prompted to log into your Cloudflare account.

docs/r2.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# R2
2+
3+
## What is it?
4+
5+
[R2](https://developers.cloudflare.com/r2/) is Cloudflare's blob storage provider.
6+
We use it to store all of the release assets stored by the Release Worker.
7+
8+
## Noteworthy points
9+
10+
### Directories
11+
12+
R2 stores files flatly, meaning a directory does not exist in R2.
13+
14+
However, R2 allows characters such as slashes (/) in an object's name.
15+
For directories we can then specify a prefix (like `nodejs/release/`) and R2 will only return objects that has a name that starts with that prefix.
16+
17+
### Bindings API
18+
19+
R2 allows integration with Workers through their [bindings API](https://developers.cloudflare.com/r2/api/workers/workers-api-usage/).
20+
We use this when fetching files.
21+
22+
### S3 API
23+
24+
Due to some performance issues we were seeing with R2's `list` binding command, we opted to use R2's S3 API for listing directories.
25+
26+
### Buckets
27+
28+
We have two R2 buckets:
29+
30+
- `dist-staging` - Holds staged releases. This bucket is private and should not be publicly accessible.
31+
32+
- `dist-prod` - Holds released versions of Node.js. Everything in this bucket should be considered publicly accessible.
33+
34+
(see [Release Process](./release-process.md) for more information on how we use these buckets)

docs/release-process.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Release Process
2+
3+
Documentation on the general order of events that happen when releasing a new version of Node.js
4+
5+
> [!NOTE]
6+
> This focuses on the flow of release assets (binaries, doc files).
7+
> This may not include the full process for releases (i.e. getting necessary approvals).
8+
9+
## Release types
10+
11+
### Mainline releases
12+
13+
Mainline releases refer to the main release branch of Node.js
14+
15+
### Nightly releases
16+
17+
Node.js has multiple release branches that are promoted nightly.
18+
19+
- `nightly` - Nightly builds from the `main` Node.js branch
20+
- `v8-canary` - Builds with the latest V8 canary
21+
- `rc` - Release candidates
22+
- `test` - Test builds
23+
24+
<details>
25+
<summary><b>Deprecated release branches</b></summary>
26+
27+
These branches no longer receive new releases.
28+
29+
- `chakracore-nightly` - Chakracore nightly builds
30+
- `chakracore-rc` - Chakracore release candidates
31+
- `chakracore-release` - Chakracore releases
32+
33+
</details>
34+
35+
## Release flow
36+
37+
### 1. Release CI is triggered
38+
39+
New builds are scheduled on the release CI (https://ci-release.nodejs.org).
40+
These builds compile Node.js on the various platforms and compile the docs.
41+
42+
Upon a build completing successfully, the build's output (binaries, doc files) will then be uploaded to the origin server and the `dist-staging` bucket in Node.js' Cloudflare account.
43+
44+
The release assets synced to the origin server are under `/home/staging/nodejs/` path.
45+
The release assets synced to the `dist-staging` bucket are under the `/nodejs/` [_prefix_](./r2.md#directories).
46+
47+
### 2. Release promotion
48+
49+
When a release is ready to be released, it is promoted.
50+
For mainline releases, this is done by the releaser running the [`release.sh`](https://github.com/nodejs/node/tree/main/tools/release.sh) script in the Node.js repository.
51+
For nightly releases, this is done once a day by [automated tooling](https://github.com/nodejs/build/blob/main/ansible/www-standalone/tools/promote/promote_nightly.sh).
52+
53+
On the origin server, the release's assets are copied from `/home/staging/nodejs/` to `/home/dist/nodejs/`.
54+
55+
For R2, the release's assets are copied from the `dist-staging` bucket to the `dist-prod` bucket.

docs/sops/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Standard Operating Procedures
2+
3+
Documents detailing standardized processes for the Release Worker.
4+
5+
## Table of Contents
6+
7+
- [Incident Flow](./incident-flow.md)
8+
- [Rolling Back a Release](./rolling-back-a-release.md)
9+
- [Switching between the Worker and Origin Server](./switch-between-worker-and-origin.md)

0 commit comments

Comments
 (0)