-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consensus node Dockerfile for test framework (#57)
## 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
Showing
13 changed files
with
422 additions
and
239 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
/node/target |
This file contains 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,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 |
This file contains 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,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 |
This file contains 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,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" |
This file contains 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,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 |
This file contains 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,5 @@ | ||
#!/bin/bash | ||
|
||
cd $(hostname -i):3054 | ||
export RUST_LOG=INFO | ||
../executor |
Oops, something went wrong.