From 3983365a1d5e3ca020323779d4f85efc66628315 Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Fri, 20 Dec 2024 09:30:15 -0800 Subject: [PATCH 1/3] restore docker ignore --- .dockerignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.dockerignore b/.dockerignore index df9fba7b1..1e7af41bb 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,14 @@ assets/ +build/ bin/ docs/ networks/ proto/ tools/ +testing/ .github/ +.git/ .vscode/ *.md +go.sum +go.mod From 35a29bb3b1d35640daa6186fd15288164ef75861 Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Fri, 20 Dec 2024 15:04:35 -0800 Subject: [PATCH 2/3] use multi stage build --- .dockerignore | 2 - Dockerfile.beacond | 85 ++++++++++++++++++++---------- testing/files/entrypoint-docker.sh | 14 ++--- 3 files changed, 63 insertions(+), 38 deletions(-) diff --git a/.dockerignore b/.dockerignore index 1e7af41bb..d27b20264 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,11 +1,9 @@ assets/ -build/ bin/ docs/ networks/ proto/ tools/ -testing/ .github/ .git/ .vscode/ diff --git a/Dockerfile.beacond b/Dockerfile.beacond index 8b40f7818..675fd8765 100644 --- a/Dockerfile.beacond +++ b/Dockerfile.beacond @@ -1,35 +1,62 @@ -# Dockerfile for `start` command -FROM alpine:latest -FROM golang:1.23-alpine - -# Install required packages -# Install Go and other dependencies -RUN apk add --no-cache bash make curl jq go ncurses docker -RUN apk add --no-cache git -RUN apk add --no-cache build-base -RUN apk add --no-cache gcc musl-dev - -# Set environment variables and directories -ENV TESTAPP_FILES_DIR=/beacon-kit/testing/files -ENV JWT_PATH=$TESTAPP_FILES_DIR/jwt.hex -ENV ETH_GENESIS_PATH=$TESTAPP_FILES_DIR/eth-genesis.json -ENV NETHER_ETH_GENESIS_PATH=$TESTAPP_FILES_DIR/eth-nether-genesis.json -ENV ETH_DATA_DIR=/beacon-kit/.tmp/eth-home -ENV IPC_PATH=$ETH_DATA_DIR/eth-engine.ipc -ENV HTTP_URL=0.0.0.0:8551 -ENV IPC_PREFIX=ipc:// -ENV HTTP_PREFIX=http:// -ENV JWT_SECRET_PATH=$JWT_PATH - -RUN mkdir -p /beacon-kit -COPY . /beacon-kit -COPY ./kurtosis /beacon-kit/kurtosis +# Build stage +FROM golang:1.23-alpine AS builder -RUN chmod +x $TESTAPP_FILES_DIR/entrypoint-docker.sh +# Install build dependencies +RUN apk add --no-cache \ + bash \ + make \ + git \ + build-base \ + gcc \ + musl-dev \ + ncurses +# Set up build directory WORKDIR /beacon-kit + +# Copy only necessary files for building +COPY . . + +# Build the application RUN make build -# Run the start command +# Final stage +FROM alpine:latest + +# Install minimal runtime dependencies +RUN apk add --no-cache \ + bash \ + curl \ + jq \ + ncurses + +# Set environment variables +ENV TESTAPP_FILES_DIR=/beacon-kit/testing/files \ + JWT_PATH=/beacon-kit/testing/files/jwt.hex \ + ETH_GENESIS_PATH=/beacon-kit/testing/files/eth-genesis.json \ + NETHER_ETH_GENESIS_PATH=/beacon-kit/testing/files/eth-nether-genesis.json \ + ETH_DATA_DIR=/beacon-kit/.tmp/eth-home \ + IPC_PATH=/beacon-kit/.tmp/eth-home/eth-engine.ipc \ + HTTP_URL=0.0.0.0:8551 \ + IPC_PREFIX=ipc:// \ + HTTP_PREFIX=http:// \ + JWT_SECRET_PATH=/beacon-kit/testing/files/jwt.hex + +# Create necessary directories +RUN mkdir -p /beacon-kit/testing/files /beacon-kit/.tmp/eth-home + +# Copy only necessary files from builder +COPY --from=builder /beacon-kit/testing/files/entrypoint-docker.sh /beacon-kit/testing/files/ +COPY --from=builder /beacon-kit/testing/files/jwt.hex /beacon-kit/testing/files/ +COPY --from=builder /beacon-kit/testing/files/eth-genesis.json /beacon-kit/testing/files/ +COPY --from=builder /beacon-kit/testing/files/eth-nether-genesis.json /beacon-kit/testing/files/ +COPY --from=builder /beacon-kit/build/bin/beacond /bin/beacond + +# Set working directory +WORKDIR /beacon-kit + +# Make entrypoint script executable +RUN chmod +x $TESTAPP_FILES_DIR/entrypoint-docker.sh + +# Set the entrypoint CMD JWT_SECRET_PATH=$JWT_PATH $TESTAPP_FILES_DIR/entrypoint-docker.sh -# CMD ["sh", "-c", "JWT_SECRET_PATH=$JWT_PATH $TESTAPP_FILES_DIR/entrypoint.sh", "Y"] \ No newline at end of file diff --git a/testing/files/entrypoint-docker.sh b/testing/files/entrypoint-docker.sh index 0ed4edbcb..59df413d4 100755 --- a/testing/files/entrypoint-docker.sh +++ b/testing/files/entrypoint-docker.sh @@ -57,7 +57,7 @@ echo "JWT_SECRET: $JWT_SECRET_PATH" set -e # Reinstall daemon -make build +# make build overwrite="Y" # if [ -d $HOMEDIR ]; then @@ -73,13 +73,13 @@ export CHAIN_SPEC="devnet" # Setup local node if overwrite is set to Yes, otherwise skip setup if [[ $overwrite == "y" || $overwrite == "Y" ]]; then rm -rf $HOMEDIR - ./build/bin/beacond init $MONIKER \ + beacond init $MONIKER \ --chain-id $CHAINID \ --home $HOMEDIR \ --consensus-key-algo $CONSENSUS_KEY_ALGO - ./build/bin/beacond genesis add-premined-deposit --home $HOMEDIR - ./build/bin/beacond genesis collect-premined-deposits --home $HOMEDIR - ./build/bin/beacond genesis execution-payload "$ETH_GENESIS" --home $HOMEDIR + beacond genesis add-premined-deposit --home $HOMEDIR + beacond genesis collect-premined-deposits --home $HOMEDIR + beacond genesis execution-payload "$ETH_GENESIS" --home $HOMEDIR fi ADDRESS=$(jq -r '.address' $HOMEDIR/config/priv_validator_key.json) @@ -87,7 +87,7 @@ PUB_KEY=$(jq -r '.pub_key' $HOMEDIR/config/priv_validator_key.json) jq --argjson pubKey "$PUB_KEY" '.consensus["validators"]=[{"address": "'$ADDRESS'", "pub_key": $pubKey, "power": "32000000000", "name": "Rollkit Sequencer"}]' $GENESIS > temp.json && mv temp.json $GENESIS # Start the node (remove the --pruning=nothing flag if historical queries are not needed) -BEACON_START_CMD="./build/bin/beacond start --pruning=nothing "$TRACE" \ +BEACON_START_CMD="beacond start --pruning=nothing "$TRACE" \ --log_level $LOGLEVEL --api.enabled-unsafe-cors \ --rollkit.aggregator --rollkit.da_address http://local-da:7980 --rpc.laddr tcp://127.0.0.1:36657 --grpc.address 127.0.0.1:9290 --p2p.laddr "0.0.0.0:36656" \ --api.enable --api.swagger --minimum-gas-prices=0.0001abgt \ @@ -102,4 +102,4 @@ if [ -n "$RPC_DIAL_URL" ]; then fi # run the beacon node -eval $BEACON_START_CMD \ No newline at end of file +eval $BEACON_START_CMD From 2f7e88022b8b076f456e13753171ae7867c3c8fb Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Fri, 20 Dec 2024 15:20:21 -0800 Subject: [PATCH 3/3] compat --- Dockerfile.beacond | 2 ++ testing/files/entrypoint-docker.sh | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile.beacond b/Dockerfile.beacond index 675fd8765..561339422 100644 --- a/Dockerfile.beacond +++ b/Dockerfile.beacond @@ -25,6 +25,7 @@ FROM alpine:latest # Install minimal runtime dependencies RUN apk add --no-cache \ + make \ bash \ curl \ jq \ @@ -51,6 +52,7 @@ COPY --from=builder /beacon-kit/testing/files/jwt.hex /beacon-kit/testing/files/ COPY --from=builder /beacon-kit/testing/files/eth-genesis.json /beacon-kit/testing/files/ COPY --from=builder /beacon-kit/testing/files/eth-nether-genesis.json /beacon-kit/testing/files/ COPY --from=builder /beacon-kit/build/bin/beacond /bin/beacond +COPY --from=builder /beacon-kit/build/bin/beacond /beacon-kit/build/bin/beacond # Set working directory WORKDIR /beacon-kit diff --git a/testing/files/entrypoint-docker.sh b/testing/files/entrypoint-docker.sh index 59df413d4..0ed4edbcb 100755 --- a/testing/files/entrypoint-docker.sh +++ b/testing/files/entrypoint-docker.sh @@ -57,7 +57,7 @@ echo "JWT_SECRET: $JWT_SECRET_PATH" set -e # Reinstall daemon -# make build +make build overwrite="Y" # if [ -d $HOMEDIR ]; then @@ -73,13 +73,13 @@ export CHAIN_SPEC="devnet" # Setup local node if overwrite is set to Yes, otherwise skip setup if [[ $overwrite == "y" || $overwrite == "Y" ]]; then rm -rf $HOMEDIR - beacond init $MONIKER \ + ./build/bin/beacond init $MONIKER \ --chain-id $CHAINID \ --home $HOMEDIR \ --consensus-key-algo $CONSENSUS_KEY_ALGO - beacond genesis add-premined-deposit --home $HOMEDIR - beacond genesis collect-premined-deposits --home $HOMEDIR - beacond genesis execution-payload "$ETH_GENESIS" --home $HOMEDIR + ./build/bin/beacond genesis add-premined-deposit --home $HOMEDIR + ./build/bin/beacond genesis collect-premined-deposits --home $HOMEDIR + ./build/bin/beacond genesis execution-payload "$ETH_GENESIS" --home $HOMEDIR fi ADDRESS=$(jq -r '.address' $HOMEDIR/config/priv_validator_key.json) @@ -87,7 +87,7 @@ PUB_KEY=$(jq -r '.pub_key' $HOMEDIR/config/priv_validator_key.json) jq --argjson pubKey "$PUB_KEY" '.consensus["validators"]=[{"address": "'$ADDRESS'", "pub_key": $pubKey, "power": "32000000000", "name": "Rollkit Sequencer"}]' $GENESIS > temp.json && mv temp.json $GENESIS # Start the node (remove the --pruning=nothing flag if historical queries are not needed) -BEACON_START_CMD="beacond start --pruning=nothing "$TRACE" \ +BEACON_START_CMD="./build/bin/beacond start --pruning=nothing "$TRACE" \ --log_level $LOGLEVEL --api.enabled-unsafe-cors \ --rollkit.aggregator --rollkit.da_address http://local-da:7980 --rpc.laddr tcp://127.0.0.1:36657 --grpc.address 127.0.0.1:9290 --p2p.laddr "0.0.0.0:36656" \ --api.enable --api.swagger --minimum-gas-prices=0.0001abgt \ @@ -102,4 +102,4 @@ if [ -n "$RPC_DIAL_URL" ]; then fi # run the beacon node -eval $BEACON_START_CMD +eval $BEACON_START_CMD \ No newline at end of file