Skip to content

Commit 0df18b2

Browse files
authored
feat: create @waku/run package for local dev env (#2678)
* feat: create @waku/run package for local dev env * chore: add @waku/run to release please config * feat: test @waku/run with playwright * fix: don't run waku/run tests in CI * fix: cache images so docker-compose can work offline * feat: set nodekey and staticnode flags for each nwaku node * fix: use constants for node ids * chore: set directories for running via npx * fix: remove .env, support env vars for nwaku ports * fix: use separate db (same instance) for each node * feat: add command to test dev env * chore: use package version in container name * fix: replace hardcoded WS/REST ports with constants/env vars * chore: clean up README * fix: refactor config printing into own function * fix: add run package to release please manifest * fix: defer to root folder gitignore/cspell * fix: update node version and remove tsx * fix: remove browser tests and express dep * fix: replace magic values with constants * fix: move to root .gitignore * fix: move cspell to root
1 parent ff9c430 commit 0df18b2

25 files changed

+1307
-3
lines changed

.cspell.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@
5555
"fontsource",
5656
"globby",
5757
"gossipsub",
58+
"hackathons",
5859
"huilong",
5960
"iasked",
6061
"ihave",
6162
"ihaves",
6263
"ineed",
6364
"IPAM",
6465
"ipfs",
66+
"isready",
6567
"iwant",
6668
"jdev",
6769
"jswaku",
@@ -165,6 +167,7 @@
165167
"gen",
166168
"proto",
167169
"*.spec.ts",
170+
"*.log",
168171
"CHANGELOG.md"
169172
],
170173
"patterns": [

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ packages/discovery/mock_local_storage
1717
.giga
1818
.cursor
1919
.DS_Store
20-
CLAUDE.md
20+
CLAUDE.md
21+
.env
22+
postgres-data/

.release-please-manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"packages/discovery": "0.0.12",
1111
"packages/sds": "0.0.7",
1212
"packages/rln": "0.1.9",
13-
"packages/react": "0.0.7"
13+
"packages/react": "0.0.7",
14+
"packages/run": "0.0.1"
1415
}

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"packages/rln",
1515
"packages/sdk",
1616
"packages/relay",
17+
"packages/run",
1718
"packages/tests",
1819
"packages/reliability-tests",
1920
"packages/browser-tests",

packages/run/.eslintrc.cjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
parserOptions: {
3+
tsconfigRootDir: __dirname,
4+
project: "./tsconfig.dev.json"
5+
},
6+
rules: {
7+
"@typescript-eslint/no-non-null-assertion": "off"
8+
},
9+
globals: {
10+
process: true
11+
},
12+
overrides: [
13+
{
14+
files: ["*.js"],
15+
rules: {
16+
"no-console": "error"
17+
}
18+
}
19+
]
20+
};

packages/run/.mocharc.cjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
extension: ['ts'],
3+
require: ['ts-node/register'],
4+
loader: 'ts-node/esm',
5+
'node-option': [
6+
'experimental-specifier-resolution=node',
7+
'loader=ts-node/esm'
8+
],
9+
timeout: 90000,
10+
exit: true
11+
};

packages/run/README.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# @waku/run
2+
3+
> **Spin up a local Waku network for development without relying on external infrastructure**
4+
5+
Perfect for hackathons, offline development, or when you need a controlled testing environment for your js-waku application.
6+
7+
## What's Included
8+
9+
- **2 nwaku nodes** connected to each other with all protocols enabled:
10+
- **PostgreSQL database** for message persistence
11+
- **Isolated network** - nodes only connect to each other
12+
13+
## Requirements
14+
15+
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) or Docker Engine with Compose plugin
16+
17+
## Quick Start
18+
19+
### 1. Start the Network
20+
21+
```bash
22+
npx @waku/run start
23+
```
24+
25+
This will:
26+
- Start 2 nwaku nodes and a PostgreSQL database
27+
- Run in the background (detached mode)
28+
- Display connection information you need for your app
29+
30+
**Example output:**
31+
```typescript
32+
import { createLightNode } from "@waku/sdk";
33+
34+
const waku = await createLightNode({
35+
defaultBootstrap: false,
36+
bootstrapPeers: [
37+
"/ip4/127.0.0.1/tcp/60000/ws/p2p/16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2",
38+
"/ip4/127.0.0.1/tcp/60001/ws/p2p/16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ"
39+
],
40+
numPeersToUse: 2,
41+
libp2p: {
42+
filterMultiaddrs: false
43+
},
44+
networkConfig: {
45+
clusterId: 0,
46+
numShardsInCluster: 8
47+
}
48+
});
49+
```
50+
51+
### 2. Connect Your js-waku App
52+
53+
Copy the configuration from the output above and paste it into your application. Then start your node:
54+
55+
```typescript
56+
await waku.start();
57+
58+
// Your app is now connected to your local Waku network!
59+
```
60+
61+
### 3. Stop When Done
62+
63+
```bash
64+
npx @waku/run stop
65+
```
66+
67+
## Available Commands
68+
69+
### Using npx (published package)
70+
71+
| Command | Description |
72+
|---------|-------------|
73+
| `npx @waku/run start` | Start the network (detached) and show connection info |
74+
| `npx @waku/run stop` | Stop the network and clean up |
75+
| `npx @waku/run info` | Show connection info for running network |
76+
| `npx @waku/run logs` | View and follow logs from all nodes |
77+
| `npx @waku/run test` | Test the network by sending a message |
78+
79+
## Configuration
80+
81+
All configuration is done via environment variables passed to the command.
82+
83+
### Custom Ports
84+
85+
If the default ports are in use, specify custom ports:
86+
87+
```bash
88+
NODE1_WS_PORT=50000 NODE2_WS_PORT=50001 npx @waku/run start
89+
```
90+
91+
Available port configuration:
92+
- `NODE1_WS_PORT` (default: 60000)
93+
- `NODE2_WS_PORT` (default: 60001)
94+
- `NODE1_REST_PORT` (default: 8646)
95+
- `NODE2_REST_PORT` (default: 8647)
96+
97+
### Cluster Configuration
98+
99+
The default configuration uses:
100+
- Cluster ID: 0
101+
- Number of shards: 8
102+
103+
To test with a different cluster:
104+
105+
```bash
106+
CLUSTER_ID=16 npx @waku/run start
107+
```
108+
109+
### Custom nwaku Version
110+
111+
To use a different nwaku image version:
112+
113+
```bash
114+
NWAKU_IMAGE=wakuorg/nwaku:v0.35.0 npx @waku/run start
115+
```
116+
117+
## Debugging
118+
119+
### View Node Logs
120+
121+
```bash
122+
npx @waku/run logs
123+
```
124+
125+
### Check Node Health
126+
127+
```bash
128+
# Node 1
129+
curl http://127.0.0.1:8646/health
130+
131+
# Node 2
132+
curl http://127.0.0.1:8647/health
133+
```
134+
135+
### Check Peer Connections
136+
137+
```bash
138+
# Node 1 debug info
139+
curl http://127.0.0.1:8646/debug/v1/info
140+
141+
# Node 2 debug info
142+
curl http://127.0.0.1:8647/debug/v1/info
143+
```
144+
145+
146+
## License
147+
148+
MIT OR Apache-2.0

0 commit comments

Comments
 (0)