Skip to content

Commit

Permalink
protocols/relay: Simplify running the relay example
Browse files Browse the repository at this point in the history
with all peers run together via docker compose libp2p#2052
  • Loading branch information
r-zig committed May 26, 2021
1 parent d931f36 commit 349d5fb
Show file tree
Hide file tree
Showing 5 changed files with 335 additions and 8 deletions.
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md
**/target
**/Cargo.lock
**/docker-compose.debug.yml
**/docker-compose.yml
2 changes: 2 additions & 0 deletions protocols/relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ prost-build = "0.7"

[dev-dependencies]
env_logger = "0.8.3"
hex = "0.4.2"
structopt = "0.3.21"
libp2p = { path = "../.." }
libp2p-kad = { path = "../kad" }
libp2p-ping = { path = "../ping" }
Expand Down
22 changes: 22 additions & 0 deletions protocols/relay/examples/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 1: Build the exe
FROM rust:latest as builder
LABEL Name=libp2p-relay Version=0.0.1
# 1a: Prepare for static linking
RUN apt-get update && \
apt-get dist-upgrade -y && \
apt-get install -y musl-tools && \
rustup target add x86_64-unknown-linux-musl
# 1b: Download and compile Rust dependencies (and store as a separate Docker layer)
RUN USER=root cargo new rust-libp2p
WORKDIR /usr/src/libp2p

COPY . /usr/src/libp2p
RUN cargo build --target x86_64-unknown-linux-musl --example=relay --package=libp2p-relay

# 2: Copy the exe and extra files ("static") to an empty Docker image
FROM debian:buster-slim

COPY --from=builder /usr/src/libp2p/target/x86_64-unknown-linux-musl/debug/examples/relay .
USER 1000

ENTRYPOINT ./relay -d $deterministic_peer_env --mode $relay_command_arg_env --address $address_env
56 changes: 56 additions & 0 deletions protocols/relay/examples/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: '3.4'
services:
relay:
image: libp2p-relay
environment:
- relay_command_arg_env=relay
- deterministic_peer_env=1
# - address_env=/ip4/0.0.0.0/tcp/4444
- address_env=/ip6/2001:3984:3989::10/tcp/4444
build:
context: ../../../.
dockerfile: ./protocols/relay/examples/Dockerfile
networks:
default:
ipv4_address: 172.16.238.10
ipv6_address: 2001:3984:3989::10

client-listen:
image: libp2p-relay
environment:
- relay_command_arg_env=client-listen
- deterministic_peer_env=2
# - address_env=/ip4/172.16.238.10/tcp/4444/p2p/12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X/p2p-circuit
- address_env=/ip6/2001:3984:3989::10/tcp/4444/p2p/12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X/p2p-circuit
build:
context: ../../../.
dockerfile: ./protocols/relay/examples/Dockerfile
networks:
default:
ipv4_address: 172.16.238.11
ipv6_address: 2001:3984:3989::11
client-dial:
image: libp2p-relay
environment:
- relay_command_arg_env=client-dial
- deterministic_peer_env=3
# - address_env=/ip4/172.16.238.10/tcp/4444/p2p/12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X/p2p-circuit/p2p/12D3KooWH3uVF6wv47WnArKHk5p6cvgCJEb74UTmxztmQDc298L3
- address_env=/ip6/2001:3984:3989::10/tcp/4444/p2p/12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X/p2p-circuit/p2p/12D3KooWH3uVF6wv47WnArKHk5p6cvgCJEb74UTmxztmQDc298L3
build:
context: ../../../.
dockerfile: ./protocols/relay/examples/Dockerfile
networks:
default:
ipv4_address: 172.16.238.12
ipv6_address: 2001:3984:3989::12
networks:
default:
driver: bridge
enable_ipv6: true
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
gateway: 172.16.238.1
- subnet: 2001:3984:3989::/64
gateway: 2001:3984:3989::1
Loading

0 comments on commit 349d5fb

Please sign in to comment.