-
Notifications
You must be signed in to change notification settings - Fork 31
Feat: Howto for running local networking infra #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6a605b7
fix: rename howtos/index.html to index.md
pdaoust e897be7
feat: draft copy for running network infrastructure
pdaoust e547cc2
chore: add running network infrastructure to all the navs
pdaoust bc9b012
edit: more server reqs, warnings about running prod server
pdaoust bfc6837
fix: missing dict items
pdaoust e6eb4d3
fix: accept suggestions from coderabbit review
pdaoust f6e095e
fix: accept coderabbit suggestion
pdaoust 99f9a27
edit: be agnostic to container management tools
pdaoust 1915db8
fix: even LAN hApps need discovery services
pdaoust 7c9f085
fix: correct the language around bootstrap, signal, and relay
pdaoust 939c211
edit/fix: even more container-tool-agnostic, remove sudo, full arg names
pdaoust 723a732
edit: more complete recommendations on running production server
pdaoust d3bd862
edit: remove superfluous lines in diff
pdaoust f3dcc70
Edit: clarify certbot / Let's Encrypt
pdaoust 32d5155
edit: make the server OS agnostic
pdaoust ce75124
edit: better / even more agnostic paths and commands
pdaoust 9541d5a
edit: improve documentation of sbd params
pdaoust f98ad6d
edit: improve documentation of server sizing and authentication
pdaoust f6cbeea
edit: comments
pdaoust 6b8085d
Merge branch 'feat/local-infra-howto' of github.com:holochain/docs-pa…
pdaoust 832008a
edit: less root please
pdaoust 9fe853c
fix: unclosed code block
pdaoust 6b4cf6e
edit: mention network seed for bootstrap servers that are used for bo…
pdaoust c3816f1
fix: Oxford comma
pdaoust 583a072
fix: use American spelling of signalling
pdaoust 22c3c5e
fix: untagged admonition
pdaoust 02c8e93
fix: mount letsencrypt read-only
pdaoust 400e7fb
fix: lower networking privileges for docker container
pdaoust File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ howto | |
| howtos | ||
| ified | ||
| interoperating | ||
| kbps | ||
| lifecycle | ||
| lifecycles | ||
| passcode | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| title: Howtos | ||
| --- | ||
|
|
||
| ::: intro | ||
| Instructions for common practical tasks | ||
| ::: | ||
|
|
||
| * [**Debugging a Running Holochain Conductor**](/resources/howtos/debugging/) --- tips on enabling and disabling log messages and interpreting what you see | ||
| * [**Running Network Infrastructure**](/resources/howtos/running-network-infrastructure/) --- instructions on using Docker to run a bootstrap and relay server for testing or production |
185 changes: 185 additions & 0 deletions
185
src/pages/resources/howtos/running-network-infrastructure.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| --- | ||
| title: Running Network Infrastructure | ||
| --- | ||
|
|
||
| ::: intro | ||
| This howto will walk you through downloading, configuring, and running a containerized setup that provides a bootstrap and signal/relay server for a Holochain application. This server is necessary to help peers discover each other and establish a direct peer-to-peer WebRTC connection, and it also provides a message relay service as a fallback in case a direct connection can't be established. | ||
| ::: | ||
pdaoust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| The [kitsune2 bootstrap server](https://github.com/holochain/kitsune2/tree/main/crates/bootstrap_srv) provides: | ||
|
|
||
| * Peer discovery | ||
| * WebSocket-based signaling for WebRTC connection setup between peers | ||
| * Optionally, the same WebSocket protocol can be used as a relay by peers who can't establish a direct connection to each other in the signaling step | ||
|
|
||
| Any user-friendly hApp will need these services in order to operate. | ||
|
|
||
| !!! info Public server | ||
| The Holochain Foundation provides a public bootstrap server at `https://dev-test-bootstrap2.holochain.org/` that you're welcome to use for testing. It's not appropriate for production hApps, though, because it's low-bandwidth and has no uptime guarantees. | ||
| !!! | ||
pdaoust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Requirements | ||
|
|
||
| * A server with a container management tool that can use [OCI containers](https://opencontainers.org/) and understands docker-compose v2 files (e.g., [Docker](https://www.docker.com/) or [Podman](https://podman.io/)). In this guide we'll use Linux-specific commands and paths and the `docker` command. | ||
| * TLS certificate and key files for your server's domain name stored in the server's filesystem in [PEM](https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail) format. In this guide we're using certificates issued by Let's Encrypt and managed by [certbot](https://certbot.eff.org/). You can choose any other method of issuing certificates, as long as the certificates will be trusted by your users. | ||
|
|
||
| ## Create a Docker compose file | ||
|
|
||
| Create a `docker-compose.yaml` file in an appropriate place in your server's filesystem, then open it for editing. Here we'll be storing the file in `/opt/kitsune2-bootstrap` and editing it in Vim: | ||
|
|
||
| ```bash | ||
| sudo mkdir -p /opt/kitsune2-bootstrap | ||
| ``` | ||
| ```bash | ||
| sudo touch /opt/kitsune2-bootstrap/docker-compose.yaml | ||
| ``` | ||
| ```bash | ||
| sudo chown $(whoami) /opt/kitsune2-bootstrap/docker-compose.yaml | ||
| ``` | ||
| ```bash | ||
pdaoust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| vim /opt/kitsune2-bootstrap/docker-compose.yaml | ||
| ``` | ||
pdaoust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Copy this code into the file, edit the locations of your TLS certificate and key files, and save it. | ||
|
|
||
| <!-- TODO(upgrade): Update the docker image URL --> | ||
| ```yaml | ||
| services: | ||
| bootstrap: | ||
| image: ghcr.io/holochain/kitsune2_bootstrap_srv:v0.2.11 | ||
| command: | ||
pdaoust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - kitsune2-bootstrap-srv | ||
| - --production | ||
| - --listen | ||
| - "[::]:443" | ||
| # Replace these with actual paths to your cert and key files, | ||
| # relative to the local volume mount point you specify further down. | ||
| - --tls-cert | ||
| - /etc/letsencrypt/live/bootstrap.example.org/fullchain.pem | ||
| - --tls-key | ||
| - /etc/letsencrypt/live/bootstrap.example.org/privkey.pem | ||
| environment: | ||
| - RUST_LOG=info | ||
| ports: | ||
| - "443:443" | ||
| volumes: | ||
| # Replace this with the path to the TLS certificate files on the host | ||
| # and your desired mount point inside the container, in this format: | ||
| # <host path>:<mount point> | ||
| - /etc/letsencrypt/:/etc/letsencrypt/:ro | ||
| restart: unless-stopped | ||
| ``` | ||
| !!! info Tuning the bootstrap server's performance | ||
| You can pass various parameters to `kitsune2-bootstrap-srv` to tune the relay performance. The [`sbd_server` crate documentation](https://docs.rs/sbd-server/latest/sbd_server/struct.Config.html#structfield.limit_clients) shows the data structure; the tuning parameters are `limit_clients` onward. To pass them as arguments to the Docker container, prefix them with `sbd` and convert them to hyphen-case, like this: | ||
|
|
||
| ```yaml | ||
| # ... | ||
| command: | ||
| - kitsune2-bootstrap-srv | ||
| - --sbd-limit-clients | ||
| - 50 | ||
| # ... | ||
| ``` | ||
| !!! | ||
pdaoust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Run the container | ||
|
|
||
| Test the configuration: | ||
|
|
||
| ```bash | ||
| docker compose up | ||
| ``` | ||
|
|
||
| You should see a lot of log messages, ending with this line: | ||
|
|
||
| ::: output-block | ||
| ```text | ||
| bootstrap-1 | #kitsune2_bootstrap_srv#listening#[::]:443# | ||
| ``` | ||
| ::: | ||
|
|
||
| If you see this, you know your server is running and should be able to respond to requests from Holochain conductors. You can now run the container in detached/daemon mode: | ||
|
|
||
| ```bash | ||
| docker compose up --detach | ||
| ``` | ||
|
|
||
| !!! info Running a production server | ||
| At this point your bootstrap server is ready for testing, but it probably isn't ready for production use. Operating a production server is outside of the scope of this documentation, and will require thinking about things like securing the server, denial-of-service protection, handling container or server failures, monitoring, logging, etc. Here are things to know about the bootstrap server: | ||
|
|
||
| * Even though the server keeps its own state, this state is ephemeral and can safely be disposed of (e.g., in case of a server crash and failover to another instance) with only temporary disruptions to service as peers re-announce themselves to the new server. This disruption will mostly be felt by newcomers and peers using the relay fallback. | ||
| * The state can't be shared among instances of the bootstrap server for load-sharing. | ||
| * One instance can be used as a bootstrap server while another can be used as a signal/relay server to spread the load; the only configuration necessary is to specify different URLs in your conductor configuration (see the next section). | ||
| * The Docker compose file above configures the server as an open relay without authentication; we're working on making it easier to [build authentication](https://github.com/holochain/sbd/blob/main/spec-auth.md) appropriate for your hApp. | ||
| * You'll need to size your server instance for your expected peak level of usage --- it may be helpful to simulate this using a multi-conductor [Tryorama](/build/testing-with-tryorama/) test or real humans. Depending on your server specs and bandwidth, the server binary can theoretically scale to support thousands of concurrent peers, with a couple hundred using relayed connections. | ||
| * The server hasn't been tested extensively with Holochain in high-load or failure scenarios. | ||
| !!! | ||
ThetaSinner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Configure your hApp to use your bootstrap server | ||
|
|
||
| <!-- TODO: eventually it should be possible to specify the server URLs in the DNA manifest. When that happens, add instructions here. See https://github.com/holochain/holochain/issues/4761 --> | ||
|
|
||
| ### Testing | ||
|
|
||
| To use your server in testing, and to test that the server is running and accessible, open your project's `package.json` file and edit the following lines. | ||
|
|
||
| !!! info Use a network seed during testing | ||
| If you use the same server for production and testing, you might end up writing test data to a production DHT. The example below adds a [network seed](/build/cloning/#network-seed) for test runs so that test data ends up in its own DHT. | ||
| !!! | ||
pdaoust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| <!-- TODO(upgrade): update the package.json file with any changes, and bump dep version numbers --> | ||
|
|
||
| ```diff:json | ||
| ... | ||
| "scripts": { | ||
| - "start": "AGENTS=${AGENTS:-3} BOOTSTRAP_PORT=$(get-port) npm run network", | ||
| + "start": "AGENTS=${AGENTS:-3} npm run network", | ||
| "network": "hc sandbox clean && npm run build:happ && UI_PORT=$(get-port) concurrently \"npm run start --workspace ui\" \"npm run launch:happ\" \"hc playground\"", | ||
| "test": "npm run build:zomes && hc app pack workdir --recursive && npm run test --workspace tests", | ||
| // Replace the hApp bundle name and URLs with your actual values. | ||
| - "launch:happ": "hc-spin -n $AGENTS --ui-port $UI_PORT workdir/my_app.happ", | ||
| + // Use bootstrap server | ||
| + "launch:happ": "hc-spin -n $AGENTS --ui-port $UI_PORT --bootstrap-url \"https://bootstrap.example.org\" --signaling-url \"wss://bootstrap.example.org\" --network-seed \"bootstrap-testing-network-only\" workdir/my_app.happ", | ||
| // If you use the Tauri-based launcher, you can also make the following | ||
| // edits. | ||
| - "start:tauri": "AGENTS=${AGENTS:-2} BOOTSTRAP_PORT=$(get-port) npm run network:tauri", | ||
| + "start:tauri": "AGENTS=${AGENTS:-2} npm run network:tauri", | ||
| "network:tauri": "hc sandbox clean && npm run build:happ && UI_PORT=$(get-port) concurrently \"npm run start --workspace ui\" \"npm run launch:tauri\" \"hc playground\"", | ||
| - "launch:tauri": "concurrently \"kitsune2-bootstrap-srv --listen \"127.0.0.1:$BOOTSTRAP_PORT\"\" \"echo pass | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/my_forum_app.happ --ui-port $UI_PORT network --bootstrap http://127.0.0.1:\"$BOOTSTRAP_PORT\" webrtc ws://127.0.0.1:\"$BOOTSTRAP_PORT\"\"", | ||
| + "launch:tauri": "echo pass | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/my_forum_app.happ --ui-port $UI_PORT --network-seed \"bootstrap-testing-network-only\" network --bootstrap \"https://bootstrap.example.org\" webrtc \"wss://bootstrap.example.org\"", | ||
| "package": "npm run build:happ && npm run package --workspace ui && hc web-app pack workdir --recursive", | ||
| "build:happ": "npm run build:zomes && hc app pack workdir --recursive", | ||
| "build:zomes": "cargo build --release --target wasm32-unknown-unknown" | ||
| }, | ||
| ... | ||
| ``` | ||
|
|
||
| ### Production | ||
|
|
||
| If you're using [Kangaroo](https://github.com/holochain/kangaroo-electron) to build an Electron-based app, open up your project's `kangaroo.config.ts` file, then edit the following lines: | ||
|
|
||
| <!-- TODO(upgrade): Update Holochain/lair versions and hashes as needed --> | ||
|
|
||
| ```diff:typescript | ||
| import { defineConfig } from './src/main/defineConfig'; | ||
| export default defineConfig({ | ||
| // ... | ||
| // Use your actual domain name here. | ||
| - bootstrapUrl: 'https://dev-test-bootstrap2.holochain.org/', | ||
| + bootstrapUrl: 'https://bootstrap.example.org/', | ||
| - signalUrl: 'wss://dev-test-bootstrap2.holochain.org/', | ||
| + signalUrl: 'wss://bootstrap.example.org/', | ||
| iceUrls: ['stun:stun.l.google.com:19302','stun:stun.cloudflare.com:3478'], | ||
| // ... | ||
| }); | ||
| ``` | ||
|
|
||
| !!! info Hardening your server against unintended use | ||
| We've shown how to configure the server without authentication. In a production scenario, you'll likely want to authenticate incoming connections to the server because: | ||
|
|
||
| * Unauthorized requests to the bootstrap endpoint could leak details about what devices are running what hApps, and | ||
matthme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * Unauthorized requests to the signal/relay endpoint allow users of other hApps to freeload on your server's bandwidth. | ||
|
|
||
| We plan to discuss [authentication options](https://github.com/holochain/sbd/blob/main/spec-auth.md) in the future. | ||
| !!! | ||
pdaoust marked this conversation as resolved.
Show resolved
Hide resolved
pdaoust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.