Skip to content

Commit

Permalink
Consensus node Dockerfile for test framework (#57)
Browse files Browse the repository at this point in the history
## What ❔

Add Dockerfile to create a container with a consensus node running in
it.

## Why ❔

This introduces a Dockerfile for the test framework proposal, enabling
the execution of a node in isolation for potential use in future
consensus among N nodes in the network. Additionally, a compose file is
included for testing purposes, facilitating the simultaneous launch of
two nodes that can initiate consensus, each running in a separate
container. This file might be replaced in the future with a script that
initializes N nodes, allowing for easier management, potentially with
Kubernetes or a similar tool.

---------

Co-authored-by: Grzegorz Prusak <[email protected]>
  • Loading branch information
IAvecilla and pompon0 committed Jan 22, 2024
1 parent 56c03f8 commit 57f037d
Show file tree
Hide file tree
Showing 13 changed files with 422 additions and 239 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node/target
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build Stage
FROM rust:latest as build
COPY /node/ /node/
COPY Makefile .
WORKDIR /node
RUN apt-get update && apt-get install -y libclang-dev
RUN cargo build --release
RUN cd .. && make docker_node_configs

# Runtime Stage
FROM debian:stable-slim as runtime

COPY --from=build /node/target/release/executor /node/
COPY --from=build /node/tools/docker-config/nodes-config /node/
COPY docker-entrypoint.sh /node/

WORKDIR /node
RUN chmod +x docker-entrypoint.sh

ENTRYPOINT ["./docker-entrypoint.sh"]

EXPOSE 3054
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.PHONY: node nodes_config docker_node_configs node_docker consensus_docker_example clean clean_docker
IP?=127.0.0.1:3054
DOCKER_IP=172.12.0.10
EXECUTABLE_NODE_DIR=node/tools

# Locally run commands

node:
export RUST_LOG=INFO && cd ${EXECUTABLE_NODE_DIR}/nodes-config/${IP} && cargo run -- --database ../../database/${IP}

nodes_config:
cd ${EXECUTABLE_NODE_DIR} && cargo run --bin localnet_config -- --input-addrs addresses.txt --output-dir nodes-config

# Docker commands

# This command will run inside the Dockerfile and it's not necessary to use it outside there.
docker_node_configs:
cd ${EXECUTABLE_NODE_DIR} && cargo run --release --bin localnet_config -- --input-addrs docker-config/addresses.txt --output-dir docker-config/nodes-config

node_docker:
mkdir -p ${EXECUTABLE_NODE_DIR}/docker-config
cd ${EXECUTABLE_NODE_DIR}/docker-config && rm -rf addresses.txt && echo ${DOCKER_IP}:3054 >> addresses.txt
docker-compose up -d node-1

consensus_docker_example:
mkdir -p ${EXECUTABLE_NODE_DIR}/docker-config
cd ${EXECUTABLE_NODE_DIR}/docker-config && rm -rf addresses.txt && touch addresses.txt && echo 172.12.0.10:3054 >> addresses.txt && echo 172.12.0.11:3054 >> addresses.txt
docker-compose up -d

stop_docker_nodes:
docker stop consensus-node-1 consensus-node-2

# Clean commands

clean: clean_docker
rm -rf ${EXECUTABLE_NODE_DIR}/nodes-config
rm -rf ${EXECUTABLE_NODE_DIR}/database

clean_docker:
rm -rf ${EXECUTABLE_NODE_DIR}/docker-config
docker rm -f consensus-node-1
docker rm -f consensus-node-2
docker network rm -f node-net
docker image rm -f consensus-node
28 changes: 28 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "3.9"

services:
node-1:
build: .
image: consensus-node
container_name: consensus-node-1
networks:
node_net:
# This allow us to know the ip of the node-1 container to fill the address in the config file
# Only for test purposes, may be removed in the future
ipv4_address: 172.12.0.10
node-2:
image: consensus-node
container_name: consensus-node-2
networks:
node_net:
# This allow us to know the ip of the node-2 container to fill the address in the config file
# Only for test purposes, may be removed in the future
ipv4_address: 172.12.0.11

networks:
node_net:
name: node-net
ipam:
config:
- subnet: "172.12.0.0/24"
gateway: "172.12.0.1"
6 changes: 6 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# This file works as an entrypoint of the docker container running the node binary copied inside of it.

cd $(hostname -i):3054
export RUST_LOG=INFO
../executor
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd $(hostname -i):3054
export RUST_LOG=INFO
../executor
Loading

0 comments on commit 57f037d

Please sign in to comment.