From b3f1621d706878bb1efa28544dfdb053d64e8832 Mon Sep 17 00:00:00 2001 From: Yorick Date: Sun, 11 Aug 2024 18:13:03 +0000 Subject: [PATCH] OCD eth1 rename --- besu.yml | 6 ++--- besu/Dockerfile.binary | 1 + besu/Dockerfile.source | 1 + besu/docker-entrypoint.sh | 11 ++++++++-- ethd | 29 ++++++++++++++++++++---- geth.yml | 8 +++---- geth/Dockerfile.binary | 3 ++- geth/Dockerfile.source | 3 ++- geth/docker-entrypoint.sh | 39 +++++++++++++++++++-------------- nethermind.yml | 6 ++--- nethermind/Dockerfile.binary | 2 ++ nethermind/Dockerfile.source | 2 ++ nethermind/docker-entrypoint.sh | 9 +++++++- 13 files changed, 85 insertions(+), 35 deletions(-) diff --git a/besu.yml b/besu.yml index a7cd8956..6cb6db41 100644 --- a/besu.yml +++ b/besu.yml @@ -28,7 +28,8 @@ services: - ARCHIVE_NODE=${ARCHIVE_NODE:-} - NETWORK=${NETWORK} volumes: - - besu-eth1-data:/var/lib/besu + - besu-el-data:/var/lib/besu + - besu-eth1-data:/var/lib/besu-og - /etc/localtime:/etc/localtime:ro - jwtsecret:/var/lib/besu/ee-secret ports: @@ -43,8 +44,6 @@ services: entrypoint: - docker-entrypoint.sh - /opt/besu/bin/besu - - --data-path - - /var/lib/besu - --p2p-port - ${EL_P2P_PORT:-30303} - --rpc-http-enabled @@ -92,6 +91,7 @@ services: command: /bin/sh volumes: + besu-el-data: besu-eth1-data: jwtsecret: diff --git a/besu/Dockerfile.binary b/besu/Dockerfile.binary index ff024867..113c2f86 100644 --- a/besu/Dockerfile.binary +++ b/besu/Dockerfile.binary @@ -23,6 +23,7 @@ RUN set -eux; \ gosu nobody true # Create data mount point with permissions +RUN mkdir -p /var/lib/besu-og && chown -R ${USER}:${USER} /var/lib/besu-og && chmod -R 700 /var/lib/besu-og RUN mkdir -p /var/lib/besu/ee-secret && chown -R ${USER}:${USER} /var/lib/besu && chmod -R 700 /var/lib/besu && chmod 777 /var/lib/besu/ee-secret # Cannot assume buildkit, hence no chmod diff --git a/besu/Dockerfile.source b/besu/Dockerfile.source index 34f0768f..9ca521c4 100644 --- a/besu/Dockerfile.source +++ b/besu/Dockerfile.source @@ -47,6 +47,7 @@ RUN adduser \ --ingroup "${USER}" \ "${USER}" +RUN mkdir -p /var/lib/besu-og && chown -R ${USER}:${USER} /var/lib/besu-og && chmod -R 700 /var/lib/besu-og RUN mkdir -p /var/lib/besu/ee-secret && chown -R besu:besu /var/lib/besu && chmod -R 700 /var/lib/besu && chmod 777 /var/lib/besu/ee-secret # Cannot assume buildkit, hence no chmod diff --git a/besu/docker-entrypoint.sh b/besu/docker-entrypoint.sh index aa5ec239..e4a131be 100755 --- a/besu/docker-entrypoint.sh +++ b/besu/docker-entrypoint.sh @@ -65,6 +65,13 @@ else __spec="" fi +# New or old datadir +if [ -d /var/lib/besu-og/database ]; then + __datadir="--data-path /var/lib/besu-og" +else + __datadir="--data-path /var/lib/besu" +fi + if [ -f /var/lib/besu/prune-marker ]; then rm -f /var/lib/besu/prune-marker if [ "${ARCHIVE_NODE}" = "true" ]; then @@ -73,9 +80,9 @@ if [ -f /var/lib/besu/prune-marker ]; then fi # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 - exec "$@" ${__network} ${__prune} ${EL_EXTRAS} storage trie-log prune + exec "$@" ${__datadir} ${__network} ${__prune} ${EL_EXTRAS} storage trie-log prune else # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 - exec "$@" ${__network} ${__prune} ${__spec} ${EL_EXTRAS} + exec "$@" ${__datadir} ${__network} ${__prune} ${__spec} ${EL_EXTRAS} fi diff --git a/ethd b/ethd index 61fbdde3..cb610956 100755 --- a/ethd +++ b/ethd @@ -1361,10 +1361,10 @@ resync-execution() { case "${value}" in *erigon.yml* ) __el_volume='erigon-el-data'; __el_client="erigon";; - *geth.yml* ) __el_volume='geth-eth1-data'; __el_client="geth";; + *geth.yml* ) __el_volume='geth-el-data'; __el_client="geth";; *reth.yml* ) __el_volume='reth-el-data'; __el_client="reth";; - *besu.yml* ) __el_volume='besu-eth1-data'; __el_client="besu";; - *nethermind.yml* ) __el_volume='nm-eth1-data'; __el_client="nethermind";; + *besu.yml* ) __el_volume='besu-el-data'; __el_client="besu";; + *nethermind.yml* ) __el_volume='nethermind-el-data'; __el_client="nethermind";; * ) echo "You do not appear to be running an execution layer client. Nothing to do."; return 0;; esac @@ -1384,6 +1384,20 @@ resync-execution() { echo "Stopping ${__el_client} container" docompose stop execution && docompose rm -f execution dodocker volume rm "$(dodocker volume ls -q -f "name=${__el_volume}")" + __volume_id="" + if [[ "${__el_volume}" =~ geth-el-data ]]; then + __legacy_volume="$(basename "$(realpath .)")_geth-eth1-data" + __volume_id="$(dodocker volume ls -q -f "name=${__legacy_volume}")" + elif [[ "${__el_volume}" =~ besu-el-data ]]; then + __legacy_volume="$(basename "$(realpath .)")_besu-eth1-data" + __volume_id="$(dodocker volume ls -q -f "name=${__legacy_volume}")" + elif [[ "${__el_volume}" =~ nethermind-el-data ]]; then + __legacy_volume="$(basename "$(realpath .)")_nm-eth1-data" + __volume_id="$(dodocker volume ls -q -f "name=${__legacy_volume}")" + fi + if [ -n "${__volume_id}" ]; then + dodocker volume rm "${__volume_id}" + fi echo echo "${__el_client} stopped and database deleted." echo @@ -1467,8 +1481,15 @@ attach-geth() { echo "You do not appear to be using Geth, aborting." exit 1 fi + __legacy_datadir=$(dodocker run --rm -v "$(dodocker volume ls -q -f \ + "name=$(basename "$(realpath .)")[_-]geth-eth1-data")":"/var/lib/goethereum" \ + alpine:3 sh -c 'if [ -d "/var/lib/goethereum/geth/chaindata" ]; then echo true; else echo false; fi') - docompose exec -it execution bash -c "geth attach /var/lib/goethereum/geth.ipc" + if [ "${__legacy_datadir}" = "true" ]; then + docompose exec -it execution bash -c "geth attach /var/lib/goethereum/geth.ipc" + else + docompose exec -it execution bash -c "geth attach /var/lib/geth/geth.ipc" + fi } diff --git a/geth.yml b/geth.yml index 638f8b1c..b0c7ad5d 100644 --- a/geth.yml +++ b/geth.yml @@ -31,9 +31,10 @@ services: - ANCIENT_DIR=${ANCIENT_DIR:-} volumes: - geth-eth1-data:/var/lib/goethereum + - geth-el-data:/var/lib/geth - ${ANCIENT_DIR:-.nada}:/var/lib/ancient - /etc/localtime:/etc/localtime:ro - - jwtsecret:/var/lib/goethereum/ee-secret + - jwtsecret:/var/lib/geth/ee-secret ports: - ${HOST_IP:-}:${EL_P2P_PORT:-30303}:${EL_P2P_PORT:-30303}/tcp - ${HOST_IP:-}:${EL_P2P_PORT:-30303}:${EL_P2P_PORT:-30303}/udp @@ -51,8 +52,6 @@ services: - 0.0.0.0 - --http.vhosts=* - --http.corsdomain=* - - --datadir - - /var/lib/goethereum - --port - ${EL_P2P_PORT:-30303} - --http.port @@ -68,7 +67,7 @@ services: - --pprof.addr - 0.0.0.0 - --authrpc.jwtsecret - - /var/lib/goethereum/ee-secret/jwtsecret + - /var/lib/geth/ee-secret/jwtsecret - --authrpc.addr - 0.0.0.0 - --authrpc.port @@ -84,6 +83,7 @@ services: - metrics.network=${NETWORK} volumes: + geth-el-data: geth-eth1-data: jwtsecret: diff --git a/geth/Dockerfile.binary b/geth/Dockerfile.binary index 9d2263e2..a30f82a3 100644 --- a/geth/Dockerfile.binary +++ b/geth/Dockerfile.binary @@ -27,7 +27,8 @@ RUN adduser \ --ingroup "${USER}" \ "${USER}" -RUN mkdir -p /var/lib/goethereum/ee-secret && chown -R ${USER}:${USER} /var/lib/goethereum && chmod -R 700 /var/lib/goethereum && chmod 777 /var/lib/goethereum/ee-secret +RUN mkdir -p /var/lib/goethereum && chown -R ${USER}:${USER} /var/lib/goethereum && chmod -R 700 /var/lib/goethereum +RUN mkdir -p /var/lib/geth/ee-secret && chown -R ${USER}:${USER} /var/lib/geth && chmod -R 700 /var/lib/geth && chmod 777 /var/lib/geth/ee-secret # Cannot assume buildkit, hence no chmod COPY --chown=${USER}:${USER} ./docker-entrypoint.sh /usr/local/bin/ diff --git a/geth/Dockerfile.source b/geth/Dockerfile.source index a9ead3c3..c9d96960 100644 --- a/geth/Dockerfile.source +++ b/geth/Dockerfile.source @@ -38,7 +38,8 @@ RUN adduser \ --ingroup "${USER}" \ "${USER}" -RUN mkdir -p /var/lib/goethereum/ee-secret && chown -R ${USER}:${USER} /var/lib/goethereum && chmod -R 700 /var/lib/goethereum && chmod 777 /var/lib/goethereum/ee-secret +RUN mkdir -p /var/lib/goethereum && chown -R ${USER}:${USER} /var/lib/goethereum && chmod -R 700 /var/lib/goethereum +RUN mkdir -p /var/lib/geth/ee-secret && chown -R ${USER}:${USER} /var/lib/geth && chmod -R 700 /var/lib/geth && chmod 777 /var/lib/geth/ee-secret # Cannot assume buildkit, hence no chmod COPY --from=builder --chown=${USER}:${USER} /src/go-ethereum/build/bin/geth /usr/local/bin/ diff --git a/geth/docker-entrypoint.sh b/geth/docker-entrypoint.sh index 1238801c..d7410a4b 100755 --- a/geth/docker-entrypoint.sh +++ b/geth/docker-entrypoint.sh @@ -2,28 +2,28 @@ set -euo pipefail if [ "$(id -u)" = '0' ]; then - chown -R geth:geth /var/lib/goethereum + chown -R geth:geth /var/lib/geth exec su-exec geth docker-entrypoint.sh "$@" fi if [ -n "${JWT_SECRET}" ]; then - echo -n "${JWT_SECRET}" > /var/lib/goethereum/ee-secret/jwtsecret + echo -n "${JWT_SECRET}" > /var/lib/geth/ee-secret/jwtsecret echo "JWT secret was supplied in .env" fi -if [[ ! -f /var/lib/goethereum/ee-secret/jwtsecret ]]; then +if [[ ! -f /var/lib/geth/ee-secret/jwtsecret ]]; then echo "Generating JWT secret" __secret1=$(head -c 8 /dev/urandom | od -A n -t u8 | tr -d '[:space:]' | sha256sum | head -c 32) __secret2=$(head -c 8 /dev/urandom | od -A n -t u8 | tr -d '[:space:]' | sha256sum | head -c 32) - echo -n "${__secret1}""${__secret2}" > /var/lib/goethereum/ee-secret/jwtsecret + echo -n "${__secret1}""${__secret2}" > /var/lib/geth/ee-secret/jwtsecret fi -if [[ -O "/var/lib/goethereum/ee-secret" ]]; then +if [[ -O "/var/lib/geth/ee-secret" ]]; then # In case someone specifies JWT_SECRET but it's not a distributed setup - chmod 777 /var/lib/goethereum/ee-secret + chmod 777 /var/lib/geth/ee-secret fi -if [[ -O "/var/lib/goethereum/ee-secret/jwtsecret" ]]; then - chmod 666 /var/lib/goethereum/ee-secret/jwtsecret +if [[ -O "/var/lib/geth/ee-secret/jwtsecret" ]]; then + chmod 666 /var/lib/geth/ee-secret/jwtsecret fi __ancient="" @@ -41,26 +41,33 @@ if [[ "${NETWORK}" =~ ^https?:// ]]; then echo "This appears to be the ${repo} repo, branch ${branch} and config directory ${config_dir}." # For want of something more amazing, let's just fail if git fails to pull this set -e - if [ ! -d "/var/lib/goethereum/testnet/${config_dir}" ]; then - mkdir -p /var/lib/goethereum/testnet - cd /var/lib/goethereum/testnet + if [ ! -d "/var/lib/geth/testnet/${config_dir}" ]; then + mkdir -p /var/lib/geth/testnet + cd /var/lib/geth/testnet git init --initial-branch="${branch}" git remote add origin "${repo}" git config core.sparseCheckout true echo "${config_dir}" > .git/info/sparse-checkout git pull origin "${branch}" fi - bootnodes="$(paste -s -d, "/var/lib/goethereum/testnet/${config_dir}/bootnode.txt")" - networkid="$(jq -r '.config.chainId' "/var/lib/goethereum/testnet/${config_dir}/genesis.json")" + bootnodes="$(paste -s -d, "/var/lib/geth/testnet/${config_dir}/bootnode.txt")" + networkid="$(jq -r '.config.chainId' "/var/lib/geth/testnet/${config_dir}/genesis.json")" set +e __network="--bootnodes=${bootnodes} --networkid=${networkid} --http.api=eth,net,web3,debug,admin,txpool" - if [ ! -d "/var/lib/goethereum/geth/chaindata/" ]; then - geth init --state.scheme path --datadir /var/lib/goethereum "/var/lib/goethereum/testnet/${config_dir}/genesis.json" + if [ ! -d "/var/lib/geth/geth/chaindata/" ]; then + geth init --datadir /var/lib/geth "/var/lib/geth/testnet/${config_dir}/genesis.json" fi else __network="--${NETWORK}" fi +# New or old datadir +if [ -d /var/lib/goethereum/geth/chaindata ]; then + __datadir="--datadir /var/lib/goethereum" +else + __datadir="--datadir /var/lib/geth" +fi + # Set verbosity shopt -s nocasematch case ${LOG_LEVEL} in @@ -101,4 +108,4 @@ fi # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 -exec "$@" ${__ancient} ${__ipv6} ${__network} ${__prune} ${__verbosity} ${EL_EXTRAS} +exec "$@" ${__datadir} ${__ancient} ${__ipv6} ${__network} ${__prune} ${__verbosity} ${EL_EXTRAS} diff --git a/nethermind.yml b/nethermind.yml index f85d92b7..0a233b2c 100644 --- a/nethermind.yml +++ b/nethermind.yml @@ -29,7 +29,8 @@ services: - AUTOPRUNE_NM=${AUTOPRUNE_NM:-true} - NETWORK=${NETWORK} volumes: - - nm-eth1-data:/var/lib/nethermind + - nethermind-el-data:/var/lib/nethermind + - nm-eth1-data:/var/lib/nethermind-og - /etc/localtime:/etc/localtime:ro - jwtsecret:/var/lib/nethermind/ee-secret ports: @@ -44,8 +45,6 @@ services: entrypoint: - docker-entrypoint.sh - /nethermind/nethermind - - --datadir - - /var/lib/nethermind - --Init.WebSocketsEnabled - "true" - --Network.DiscoveryPort @@ -92,6 +91,7 @@ services: - metrics.network=${NETWORK} volumes: + nethermind-el-data: nm-eth1-data: jwtsecret: diff --git a/nethermind/Dockerfile.binary b/nethermind/Dockerfile.binary index 24bad15d..a2724458 100644 --- a/nethermind/Dockerfile.binary +++ b/nethermind/Dockerfile.binary @@ -36,6 +36,8 @@ RUN adduser \ # This only goes so far. keystore, logs and nethermind_db are volumes and need to be chown'd in the entrypoint RUN chown -R ${USER}:${USER} /nethermind +RUN mkdir -p /var/lib/nethermind-og && chown -R ${USER}:${USER} /var/lib/nethermind-og \ +&& chmod -R 700 /var/lib/nethermind-og RUN mkdir -p /var/lib/nethermind/ee-secret && chown -R ${USER}:${USER} /var/lib/nethermind \ && chmod -R 700 /var/lib/nethermind && chmod 777 /var/lib/nethermind/ee-secret diff --git a/nethermind/Dockerfile.source b/nethermind/Dockerfile.source index d86f92be..c27891c8 100644 --- a/nethermind/Dockerfile.source +++ b/nethermind/Dockerfile.source @@ -49,6 +49,8 @@ WORKDIR /nethermind COPY --from=builder --chown=${USER}:${USER} /nethermind/out . RUN chown -R ${USER}:${USER} /nethermind +RUN mkdir -p /var/lib/nethermind-og && chown -R ${USER}:${USER} /var/lib/nethermind-og \ +&& chmod -R 700 /var/lib/nethermind-og RUN mkdir -p /var/lib/nethermind/ee-secret && chown -R ${USER}:${USER} /var/lib/nethermind \ && chmod -R 700 /var/lib/nethermind && chmod 777 /var/lib/nethermind/ee-secret diff --git a/nethermind/docker-entrypoint.sh b/nethermind/docker-entrypoint.sh index a8bf6533..cea716ba 100755 --- a/nethermind/docker-entrypoint.sh +++ b/nethermind/docker-entrypoint.sh @@ -82,6 +82,13 @@ else echo "${__prune}" fi +# New or old datadir +if [ -d /var/lib/nethermind-og/nethermind_db ]; then + __datadir="--datadir /var/lib/nethermind-og" +else + __datadir="--datadir /var/lib/nethermind" +fi + # Word splitting is desired for the command line parameters # shellcheck disable=SC2086 -exec "$@" ${__network} ${__prune} ${EL_EXTRAS} +exec "$@" ${__datadir} ${__network} ${__prune} ${EL_EXTRAS}