Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from primevprotocol/feature/dockerize_mev-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kant777 authored Oct 2, 2023
2 parents ae57486 + 2058624 commit d2a5646
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/.idea
**/.vscode
23 changes: 8 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

7 changes: 7 additions & 0 deletions config/bootnode.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions config/builder.yml
Original file line number Diff line number Diff line change
@@ -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/<localhost>/tcp/13522/p2p/<p2p_ID>
9 changes: 0 additions & 9 deletions config/config.yml

This file was deleted.

9 changes: 9 additions & 0 deletions config/searcher.yml
Original file line number Diff line number Diff line change
@@ -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/<localhost>/tcp/13522/p2p/<p2p_ID>
52 changes: 52 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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|<p2p_ID>|${BOOTNODE_P2P_ID}|" ${CONFIG_FILE}
sed -i "s|<localhost>|${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}

0 comments on commit d2a5646

Please sign in to comment.