This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from primevprotocol/feature/dockerize_mev-commit
- Loading branch information
Showing
8 changed files
with
137 additions
and
24 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,2 @@ | ||
**/.idea | ||
**/.vscode |
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 |
---|---|---|
@@ -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"] | ||
|
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,7 @@ | ||
priv_key_file: /keys/bootnode | ||
peer_type: bootnode | ||
p2p_port: 13522 | ||
http_port: 13523 | ||
secret: hello | ||
log_fmt: text | ||
log_level: debug |
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,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> |
This file was deleted.
Oops, something went wrong.
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,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> |
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,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 |
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,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} | ||
|