From 4db84672418149bed756c2c12683139f6ccc2e3a Mon Sep 17 00:00:00 2001 From: kant Date: Mon, 2 Oct 2023 03:42:29 -0700 Subject: [PATCH 1/3] dockerize mev network --- .gitignore | 2 ++ Dockerfile | 23 +++++++------------- config/bootnode.yml | 7 ++++++ config/builder.yml | 9 ++++++++ config/config.yml | 9 -------- config/searcher.yml | 9 ++++++++ docker-compose.yml | 52 +++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 50 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 137 insertions(+), 24 deletions(-) create mode 100644 .gitignore create mode 100644 config/bootnode.yml create mode 100644 config/builder.yml delete mode 100644 config/config.yml create mode 100644 config/searcher.yml create mode 100644 docker-compose.yml create mode 100755 entrypoint.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e383b528 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/.idea +**/.vscode diff --git a/Dockerfile b/Dockerfile index 6fead987..a4395086 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,21 @@ -# --- Build Stage --- FROM golang:1.21.1 AS builder -# Set the current working directory inside the container WORKDIR /app - -# Copy go mod and sum files -COPY go.mod go.sum ./ - -# Download all dependencies -RUN go mod download - -# Copy the entire directory to the container COPY . . -# Build the application RUN CGO_ENABLED=0 GOOS=linux go build -o mev-commit ./cmd/main.go -# --- Production Stage --- FROM alpine:latest -# Copy the binary from the builder stage -COPY --from=builder /app/mev-commit /mev-commit +RUN apk --no-cache add curl +RUN apk add --no-cache jq + +COPY --from=builder /app/mev-commit /app/mev-commit +COPY --from=builder /app/config /config +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh EXPOSE 13522 13523 -CMD ["/mev-commit"] +ENTRYPOINT ["/entrypoint.sh"] diff --git a/config/bootnode.yml b/config/bootnode.yml new file mode 100644 index 00000000..23f9b7b0 --- /dev/null +++ b/config/bootnode.yml @@ -0,0 +1,7 @@ +priv_key_file: /keys/bootnode1 +peer_type: bootnode +p2p_port: 13522 +http_port: 13523 +secret: hello +log_fmt: text +log_level: debug diff --git a/config/builder.yml b/config/builder.yml new file mode 100644 index 00000000..cf3814f9 --- /dev/null +++ b/config/builder.yml @@ -0,0 +1,9 @@ +priv_key_file: /keys/builder1 +peer_type: builder +p2p_port: 13522 +http_port: 13523 +secret: hello +log_fmt: text +log_level: debug +bootnodes: + - /ip4//tcp/13522/p2p/ diff --git a/config/config.yml b/config/config.yml deleted file mode 100644 index 0c36d940..00000000 --- a/config/config.yml +++ /dev/null @@ -1,9 +0,0 @@ -priv_key_file: ~/.mev-commit/keys/node1 -peer_type: builder -p2p_port: 13524 -http_port: 13525 -secret: hello -log_fmt: text -log_level: debug -bootnodes: - - /ip4/localhost/tcp/13522/p2p/26Uiu2HAm1T4Pc777L6VerTUXMDS5VcHmBrAW4EUKjH5EXoRtB9Ft diff --git a/config/searcher.yml b/config/searcher.yml new file mode 100644 index 00000000..1113d23c --- /dev/null +++ b/config/searcher.yml @@ -0,0 +1,9 @@ +priv_key_file: /keys/searcher1 +peer_type: searcher +p2p_port: 13522 +http_port: 13523 +secret: hello +log_fmt: text +log_level: debug +bootnodes: + - /ip4//tcp/13522/p2p/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..c6aee9c5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,52 @@ +version: '3' + +services: + bootnode: + build: + context: . + dockerfile: Dockerfile + environment: + - NODE_TYPE=bootnode + volumes: + - bootnode-keys:/keys + networks: + mev-net: + ipv4_address: 172.28.0.2 + + builder: + build: + context: . + dockerfile: Dockerfile + depends_on: + - bootnode + environment: + - NODE_TYPE=builder + volumes: + - builder-keys:/keys + networks: + - mev-net + + searcher: + build: + context: . + dockerfile: Dockerfile + depends_on: + - bootnode + environment: + - NODE_TYPE=searcher + volumes: + - searcher-keys:/keys + networks: + - mev-net + +volumes: + bootnode-keys: + builder-keys: + searcher-keys: + +networks: + mev-net: + ipam: + driver: default + config: + - subnet: 172.28.0.0/16 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..650b2527 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +echo "Node Type: $NODE_TYPE" + +# Define paths +KEY_PATH="/keys" +CONFIG_PATH="/config" + +# Generate the private key based on node type +if [ "$NODE_TYPE" = "bootnode" ]; then + /app/mev-commit create-key ${KEY_PATH}/bootnode1 + PRIV_KEY_FILE="${KEY_PATH}/bootnode1" + CONFIG_FILE="${CONFIG_PATH}/bootnode.yml" +elif [ "$NODE_TYPE" = "builder" ]; then + /app/mev-commit create-key ${KEY_PATH}/builder1 + PRIV_KEY_FILE="${KEY_PATH}/builder1" + CONFIG_FILE="${CONFIG_PATH}/builder.yml" +else + /app/mev-commit create-key ${KEY_PATH}/searcher1 + PRIV_KEY_FILE="${KEY_PATH}/searcher1" + CONFIG_FILE="${CONFIG_PATH}/searcher.yml" +fi + +# Update the private key path in the configuration +sed -i "s|priv_key_file:.*|priv_key_file: ${PRIV_KEY_FILE}|" ${CONFIG_FILE} + +# If this is not the bootnode, update the bootnodes entry with P2P ID +if [ "$NODE_TYPE" != "bootnode" ]; then + # Wait for a few seconds to ensure the bootnode is up and its API is accessible + sleep 10 + + BOOTNODE_RESPONSE=$(curl -s bootnode:13523/topology) + BOOTNODE_P2P_ID=$(echo "$BOOTNODE_RESPONSE" | jq -r '.self.Underlay') + BOOTNODE_IP=$(getent hosts bootnode | awk '{ print $1 }') + + echo "Response from bootnode:" + echo "$BOOTNODE_RESPONSE" + + if [ -n "$BOOTNODE_P2P_ID" ]; then + sed -i "s||${BOOTNODE_P2P_ID}|" ${CONFIG_FILE} + sed -i "s||${BOOTNODE_IP}|" ${CONFIG_FILE} + else + echo "Failed to fetch P2P ID from bootnode. Exiting." + exit 1 + fi +fi + +echo "starting mev-commit with config file: ${CONFIG_FILE}" +/app/mev-commit start --config ${CONFIG_FILE} + From 5ffdec30d525320732051d4eb88adc00948e6b27 Mon Sep 17 00:00:00 2001 From: kant Date: Mon, 2 Oct 2023 03:59:32 -0700 Subject: [PATCH 2/3] dockerize mev-commit network locally --- entrypoint.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 650b2527..19bd245f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,16 +8,16 @@ CONFIG_PATH="/config" # Generate the private key based on node type if [ "$NODE_TYPE" = "bootnode" ]; then - /app/mev-commit create-key ${KEY_PATH}/bootnode1 - PRIV_KEY_FILE="${KEY_PATH}/bootnode1" + /app/mev-commit create-key ${KEY_PATH}/bootnode + PRIV_KEY_FILE="${KEY_PATH}/bootnode" CONFIG_FILE="${CONFIG_PATH}/bootnode.yml" elif [ "$NODE_TYPE" = "builder" ]; then - /app/mev-commit create-key ${KEY_PATH}/builder1 - PRIV_KEY_FILE="${KEY_PATH}/builder1" + /app/mev-commit create-key ${KEY_PATH}/builder + PRIV_KEY_FILE="${KEY_PATH}/builder" CONFIG_FILE="${CONFIG_PATH}/builder.yml" else - /app/mev-commit create-key ${KEY_PATH}/searcher1 - PRIV_KEY_FILE="${KEY_PATH}/searcher1" + /app/mev-commit create-key ${KEY_PATH}/searcher + PRIV_KEY_FILE="${KEY_PATH}/searcher" CONFIG_FILE="${CONFIG_PATH}/searcher.yml" fi From 205862444c6efd2ae87d5789ed3d2101b2f3e12c Mon Sep 17 00:00:00 2001 From: kant Date: Mon, 2 Oct 2023 04:01:10 -0700 Subject: [PATCH 3/3] fix suffix --- config/bootnode.yml | 2 +- config/builder.yml | 2 +- config/searcher.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/bootnode.yml b/config/bootnode.yml index 23f9b7b0..241d7dc7 100644 --- a/config/bootnode.yml +++ b/config/bootnode.yml @@ -1,4 +1,4 @@ -priv_key_file: /keys/bootnode1 +priv_key_file: /keys/bootnode peer_type: bootnode p2p_port: 13522 http_port: 13523 diff --git a/config/builder.yml b/config/builder.yml index cf3814f9..788f8824 100644 --- a/config/builder.yml +++ b/config/builder.yml @@ -1,4 +1,4 @@ -priv_key_file: /keys/builder1 +priv_key_file: /keys/builder peer_type: builder p2p_port: 13522 http_port: 13523 diff --git a/config/searcher.yml b/config/searcher.yml index 1113d23c..d45ec0b1 100644 --- a/config/searcher.yml +++ b/config/searcher.yml @@ -1,4 +1,4 @@ -priv_key_file: /keys/searcher1 +priv_key_file: /keys/searcher peer_type: searcher p2p_port: 13522 http_port: 13523