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..241d7dc7 --- /dev/null +++ b/config/bootnode.yml @@ -0,0 +1,7 @@ +priv_key_file: /keys/bootnode +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..788f8824 --- /dev/null +++ b/config/builder.yml @@ -0,0 +1,9 @@ +priv_key_file: /keys/builder +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..d45ec0b1 --- /dev/null +++ b/config/searcher.yml @@ -0,0 +1,9 @@ +priv_key_file: /keys/searcher +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..19bd245f --- /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}/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}/builder + PRIV_KEY_FILE="${KEY_PATH}/builder" + CONFIG_FILE="${CONFIG_PATH}/builder.yml" +else + /app/mev-commit create-key ${KEY_PATH}/searcher + PRIV_KEY_FILE="${KEY_PATH}/searcher" + 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} +