Skip to content

Instantly share code, notes, and snippets.

@gsaslis
Last active March 28, 2024 11:30
Show Gist options
  • Save gsaslis/dbd6b059afe8147cbdb12a8a89345e14 to your computer and use it in GitHub Desktop.
Save gsaslis/dbd6b059afe8147cbdb12a8a89345e14 to your computer and use it in GitHub Desktop.
Running Radicle Nodes in Containers

Running in Containers

In case you want to run radicle in containers, on the same host (e.g. your laptop), you can use the docker-compose.yml file provided within this repo.

1. Create a profile

  1. Create a folder where you will store the data of your node. e.g. mkdir -p ~/radicle/profiles/bob/.radicle
  2. Set RAD_HOME : export RAD_HOME=~/radicle/profiles/bob/.radicle
  3. Create a key:
    • Pick a good passphrase and store it in your password manager
    • go ahead with creating the key rad auth --stdin (or use RAD_PASSPHRASE env var)
    • your profile should be created in ~/radicle/profiles/bob/.radicle.

2. Build the container images

This takes a couple of minutes - depending on your machine - as it needs to download the parent container images, and also all the rust dependencies and then compile the code:

docker-compose build

3. Choose scenario

Choose your scenario:

3A. Run a single Radicle node

This is as simple as using the existing docker-compose.yml and simply passing in the path to the parent folder of RAD_HOME, where you previously created the profile.

RAD_ROOT=~/radicle/profiles/bob docker-compose up radicle-node radicle-httpd 

3B. Run Multiple Radicle Nodes Locally

You would probably use this setup if you want to play around with multiple nodes and study, understand and learn how Radicle works and how projects (and their data) are replicated across nodes. This setup is not recommended for production use!

The setup is slightly different between the first node you run and the additional ones.

Run First Node

For the first node you want to start on your machine, you can:

  1. Create a .env.$nodename file that will store all your environment variables:
    # these options are especially useful in a development setting - probably not for production use
    RADICLE_NODE_OPTIONS=--tracking-policy track --tracking-scope all
    # Note the difference between RAD_ROOT vs. RAD_HOME.
    RAD_ROOT=~/radicle/profiles/bob
    # ensure these ports are free on your machine
    RADICLE_API_PORT=8888
    RADICLE_NODE_PORT=8778
  2. Start the containers:
    # we don't need to start the included `caddy` service
    docker-compose --env-file=.env.bob --project-name=bob up radicle-node radicle-httpd

Run additional nodes in your network

For each additional node:

  1. Create a new profile in a new directory, using the steps in the "Create a profile" section above.
  2. Create a .env.$nodename file that will store all your environment variables:
    # IMPORTANT: substitute `<FIRST_NODE_ID>` with the node id of your **first** node ( `RAD_HOME=<path_to_first_node_profile> rad self | grep "Node ID"` ). 
    # IMPORTANT: substitute `<FIRST_NODE_PROJECT_NAME>` with the `--project-name` value you used in your first node. In our example, this would be `bob`.
    RADICLE_NODE_OPTIONS=--tracking-policy track --tracking-scope all  --connect <FIRST_NODE_ID>@<FIRST_NODE_PROJECT_NAME>_radicle-node_1.radicle-services:8776
    # Use the new profile directory
    RAD_ROOT=~/radicle/profiles/alice
    # pick a new set of ports that are free on your machine
    RADICLE_API_PORT=8887
    RADICLE_NODE_PORT=8777
  3. Start the containers:
    # we don't need to start the included `caddy` service
    docker-compose --env-file=.env.alice --project-name=alice up radicle-node radicle-httpd
  4. The 2 nodes should now connect to each other ! You should be able to see a "Connected to " message and after a couple of minutes some Ping messages (and Pong responses) being exchanged. 🚀
version: "3.7"
services:
radicle-node:
image: gcr.io/radicle-services/radicle-node:${RADICLE_IMAGE_TAG:-latest}
command: ${RADICLE_NODE_OPTIONS}
build:
dockerfile: ./radicle-node/Dockerfile
context: .
environment:
RUST_LOG: debug
RAD_PASSPHRASE: ${RAD_PASSPHRASE:-seed}
RUST_BACKTRACE: 1
GIT_TRACE: 1
GIT_TRACE_PACKET: 1
volumes:
- ${RAD_ROOT:-/mnt/radicle/heartwood}:/root/
init: true
restart: unless-stopped
networks:
- radicle-services
deploy:
resources:
limits:
memory: 6gb
ports:
- ${RADICLE_NODE_PORT:-8776}:8776
radicle-httpd:
image: gcr.io/radicle-services/radicle-httpd:${RADICLE_IMAGE_TAG:-latest}
build:
dockerfile: ./radicle-httpd/Dockerfile
context: .
environment:
RUST_LOG: debug
RUST_BACKTRACE: 1
volumes:
- ${RAD_ROOT:-/mnt/radicle/heartwood}:/root/
init: true
restart: unless-stopped
networks:
- radicle-services
deploy:
resources:
limits:
memory: 6gb
ports:
- ${RADICLE_API_PORT:-8886}:8080
caddy:
image: caddy:2.4.5
entrypoint:
- sh
- -euc
- |
cat <<EOF >/etc/caddy/Caddyfile
$RADICLE_DOMAIN {
reverse_proxy radicle-httpd:8080
}
EOF
caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
ports:
- 80:80
- 443:443
environment:
RADICLE_DOMAIN: $RADICLE_DOMAIN
container_name: caddy
restart: unless-stopped
networks:
- radicle-services
networks:
radicle-services:
name: radicle-services
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment