From 495ffcd6770dc66700c6937c24209630af31fc9e Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Thu, 29 Aug 2024 18:11:03 -0700 Subject: [PATCH 1/9] Use new dl-pipe utility to get resumable piped downloads --- Dockerfile | 3 ++- init.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5837eb9..da796c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM golang:1.22.5-bookworm AS base-build RUN go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.5.0 RUN go install github.com/hashicorp/go-getter/cmd/go-getter@v1.7.6 +RUN go install github.com/zeta-chain/dl-pipe/cmd/dl-pipe@latest FROM debian:bookworm AS base @@ -14,7 +15,7 @@ RUN apt update && \ apt install -y ca-certificates curl jq && \ rm -rf /var/lib/apt/lists/* -COPY --from=base-build /go/bin/cosmovisor /go/bin/go-getter /usr/local/bin +COPY --from=base-build /go/bin/cosmovisor /go/bin/go-getter /go/bin/dl-pipe /usr/local/bin COPY run.sh init.sh / diff --git a/init.sh b/init.sh index 5437bb6..4527b33 100755 --- a/init.sh +++ b/init.sh @@ -89,7 +89,7 @@ install_genesis_zetacored() { restore_snapshot() { snapshot_link=$($CURL "${ZETACHAIN_SNAPSHOT_METADATA_URL}" | jq -r '.snapshots[0].link') echo "Restoring snapshot from ${snapshot_link}" - $CURL "$snapshot_link" | tar x -C $HOME/.zetacored + dl-pipe "$snapshot_link" | tar x -C $HOME/.zetacored } cd $HOME From a5142993cfd85b7a3a7e417ca9ac98e656834194 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Fri, 30 Aug 2024 10:27:07 -0700 Subject: [PATCH 2/9] move genesis bin creation and link to init.sh This is to tolerate .zetacored being mounted on a volume --- Dockerfile | 3 --- init.sh | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index da796c9..52e3ae0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,6 @@ RUN go install github.com/zeta-chain/dl-pipe/cmd/dl-pipe@latest FROM debian:bookworm AS base -RUN mkdir -p /root/.zetacored/cosmovisor/genesis/bin && \ - ln -s /root/.zetacored/cosmovisor/genesis /root/.zetacored/cosmovisor/current - ENV PATH=/root/.zetacored/cosmovisor/current/bin/:${PATH} RUN apt update && \ diff --git a/init.sh b/init.sh index 4527b33..40fb5bd 100755 --- a/init.sh +++ b/init.sh @@ -66,6 +66,14 @@ download_configs() { install_genesis_zetacored() { echo "Installing genesis zetacored" + + # create the genesis bin path and symlink it to the current path + genesis_path=".zetacored/cosmovisor/genesis" + mkdir -p "$genesis_path" + mkdir -p "${genesis_path}/bin" + current_path=".zetacored/cosmovisor/current" + ln -s "${HOME}/${genesis_path}" "${HOME}/${current_path}" + if [[ -z $ZETACORED_BINARY_URL ]]; then max_height=$($CURL "${ZETACHAIN_SNAPSHOT_METADATA_URL}" | jq -r '.snapshots[0].height') echo "Getting latest passed upgrade plan before ${max_height}" From 383d790313e026c546acba507a0e60b6ca5d5315 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Fri, 30 Aug 2024 10:42:01 -0700 Subject: [PATCH 3/9] fix snapshotter build --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e434749..54c96cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,7 +59,7 @@ jobs: with: platforms: linux/amd64,linux/arm64 push: true - target: base + target: snapshotter provenance: mode=max tags: "${{ env.IMAGE_BASE }}:${{ env.VERSION }}-snapshotter" cache-from: type=registry,ref=${{ env.IMAGE_BASE }}:buildcache From 8757f468ac1b6d9c21d59d7ebb315fcf7beb867f Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Fri, 30 Aug 2024 11:23:43 -0700 Subject: [PATCH 4/9] add hash verification --- init.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/init.sh b/init.sh index 40fb5bd..f8bd22f 100755 --- a/init.sh +++ b/init.sh @@ -95,9 +95,12 @@ install_genesis_zetacored() { } restore_snapshot() { - snapshot_link=$($CURL "${ZETACHAIN_SNAPSHOT_METADATA_URL}" | jq -r '.snapshots[0].link') + snapshot=$($CURL "${ZETACHAIN_SNAPSHOT_METADATA_URL}" | jq -r '.snapshots[0]') + snapshot_link=$(echo "$snapshot" | jq -r '.link') + snapshot_md5=$(echo "$snapshot" | jq -r '.checksums.md5') echo "Restoring snapshot from ${snapshot_link}" - dl-pipe "$snapshot_link" | tar x -C $HOME/.zetacored + # https://github.com/zeta-chain/dl-pipe + dl-pipe -hash "md5:${snapshot_md5}" "$snapshot_link" | tar x -C $HOME/.zetacored } cd $HOME From b1cb69228854084fc86f6fd0f2faf4fa021a565d Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Fri, 30 Aug 2024 12:40:21 -0700 Subject: [PATCH 5/9] add procps --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 52e3ae0..4804f94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ FROM base AS snapshotter ARG TARGETARCH RUN apt update && \ - apt install -y rclone && \ + apt install -y rclone procps && \ rm -rf /var/lib/apt/lists/* RUN ARCH=$( [ "$TARGETARCH" = "amd64" ] && echo "x86_64" || echo "$TARGETARCH" ) && \ From ec7d72b0f8f4972c33e2e16efc4ac693f64b77d6 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Fri, 30 Aug 2024 13:23:28 -0700 Subject: [PATCH 6/9] use testnet snapshot for CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54c96cc..c584e92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: timeout-minutes: 45 steps: - name: Start container - run: docker run -d --name zetacored -p 8545:8545 -e MONIKER=$(uuidgen) ${{ needs.build.outputs.IMAGE }} + run: docker run -d --name zetacored -p 8545:8545 -e MONIKER=$(uuidgen) -e ZETACHAIN_NETWORK=testnet ${{ needs.build.outputs.IMAGE }} - name: Wait for healthy run: | while ! curl -s -f --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' -H 'Content-Type: application/json' http://localhost:8545; do From 0e2433ac4062cb02697e67834444aa55b810ce33 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Tue, 3 Sep 2024 13:16:35 -0700 Subject: [PATCH 7/9] fix init_completed --- init.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.sh b/init.sh index f8bd22f..ff9988e 100755 --- a/init.sh +++ b/init.sh @@ -111,12 +111,12 @@ if [[ -f /root/init_started && ! -f /root/init_completed ]]; then fi touch /root/init_started -if [[ ! -f /root/init_complete ]]; then +if [[ ! -f /root/init_completed ]]; then echo "Starting initialization" download_configs install_genesis_zetacored restore_snapshot - touch /root/init_complete + touch /root/init_completed else echo "Initialization already completed" fi From 51405c66f126f04c54106c1d8ba908d33f959ac1 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Wed, 4 Sep 2024 10:06:57 -0700 Subject: [PATCH 8/9] remove VOLUME --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4804f94..99e8e53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,6 @@ COPY --from=base-build /go/bin/cosmovisor /go/bin/go-getter /go/bin/dl-pipe /usr COPY run.sh init.sh / -VOLUME /root/.zetacored/data/ - ENTRYPOINT ["/run.sh"] FROM base AS snapshotter From 0f4165a477d8ce40a5d5a08b6a22e133f931683d Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Thu, 5 Sep 2024 10:22:36 -0700 Subject: [PATCH 9/9] add restart CI --- .github/workflows/ci.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c584e92..68d6ed5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,4 +85,23 @@ jobs: - name: Dump logs if: always() run: docker logs zetacored + - name: Ensure we can restart + run: | + docker stop zetacored + docker start zetacored + - name: Wait for healthy + run: | + while ! curl -s -f --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' -H 'Content-Type: application/json' http://localhost:8545; do + if ! docker ps | grep zetacored; then + echo "Container stopped?" + exit 1 + fi + df -h / + echo "waiting for zetacored health" + sleep 15 + done + - name: Dump logs (restart) + if: always() + run: docker logs --since 1m zetacored +