Skip to content

Commit 7b470c9

Browse files
authored
Use new dl-pipe utility to get resumable piped downloads (#6)
* Use new dl-pipe utility to get resumable piped downloads * move genesis bin creation and link to init.sh This is to tolerate .zetacored being mounted on a volume * fix snapshotter build * add hash verification * add procps * use testnet snapshot for CI * fix init_completed * remove VOLUME * add restart CI
1 parent 72406b1 commit 7b470c9

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
with:
6060
platforms: linux/amd64,linux/arm64
6161
push: true
62-
target: base
62+
target: snapshotter
6363
provenance: mode=max
6464
tags: "${{ env.IMAGE_BASE }}:${{ env.VERSION }}-snapshotter"
6565
cache-from: type=registry,ref=${{ env.IMAGE_BASE }}:buildcache
@@ -70,7 +70,7 @@ jobs:
7070
timeout-minutes: 45
7171
steps:
7272
- name: Start container
73-
run: docker run -d --name zetacored -p 8545:8545 -e MONIKER=$(uuidgen) ${{ needs.build.outputs.IMAGE }}
73+
run: docker run -d --name zetacored -p 8545:8545 -e MONIKER=$(uuidgen) -e ZETACHAIN_NETWORK=testnet ${{ needs.build.outputs.IMAGE }}
7474
- name: Wait for healthy
7575
run: |
7676
while ! curl -s -f --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' -H 'Content-Type: application/json' http://localhost:8545; do
@@ -85,4 +85,23 @@ jobs:
8585
- name: Dump logs
8686
if: always()
8787
run: docker logs zetacored
88+
- name: Ensure we can restart
89+
run: |
90+
docker stop zetacored
91+
docker start zetacored
92+
- name: Wait for healthy
93+
run: |
94+
while ! curl -s -f --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' -H 'Content-Type: application/json' http://localhost:8545; do
95+
if ! docker ps | grep zetacored; then
96+
echo "Container stopped?"
97+
exit 1
98+
fi
99+
df -h /
100+
echo "waiting for zetacored health"
101+
sleep 15
102+
done
103+
- name: Dump logs (restart)
104+
if: always()
105+
run: docker logs --since 1m zetacored
106+
88107

Dockerfile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,28 @@ FROM golang:1.22.5-bookworm AS base-build
22

33
RUN go install cosmossdk.io/tools/cosmovisor/cmd/[email protected]
44
RUN go install github.com/hashicorp/go-getter/cmd/[email protected]
5+
RUN go install github.com/zeta-chain/dl-pipe/cmd/dl-pipe@latest
56

67
FROM debian:bookworm AS base
78

8-
RUN mkdir -p /root/.zetacored/cosmovisor/genesis/bin && \
9-
ln -s /root/.zetacored/cosmovisor/genesis /root/.zetacored/cosmovisor/current
10-
119
ENV PATH=/root/.zetacored/cosmovisor/current/bin/:${PATH}
1210

1311
RUN apt update && \
1412
apt install -y ca-certificates curl jq && \
1513
rm -rf /var/lib/apt/lists/*
1614

17-
COPY --from=base-build /go/bin/cosmovisor /go/bin/go-getter /usr/local/bin
15+
COPY --from=base-build /go/bin/cosmovisor /go/bin/go-getter /go/bin/dl-pipe /usr/local/bin
1816

1917
COPY run.sh init.sh /
2018

21-
VOLUME /root/.zetacored/data/
22-
2319
ENTRYPOINT ["/run.sh"]
2420

2521
FROM base AS snapshotter
2622

2723
ARG TARGETARCH
2824

2925
RUN apt update && \
30-
apt install -y rclone && \
26+
apt install -y rclone procps && \
3127
rm -rf /var/lib/apt/lists/*
3228

3329
RUN ARCH=$( [ "$TARGETARCH" = "amd64" ] && echo "x86_64" || echo "$TARGETARCH" ) && \

init.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ download_configs() {
6666

6767
install_genesis_zetacored() {
6868
echo "Installing genesis zetacored"
69+
70+
# create the genesis bin path and symlink it to the current path
71+
genesis_path=".zetacored/cosmovisor/genesis"
72+
mkdir -p "$genesis_path"
73+
mkdir -p "${genesis_path}/bin"
74+
current_path=".zetacored/cosmovisor/current"
75+
ln -s "${HOME}/${genesis_path}" "${HOME}/${current_path}"
76+
6977
if [[ -z $ZETACORED_BINARY_URL ]]; then
7078
max_height=$($CURL "${ZETACHAIN_SNAPSHOT_METADATA_URL}" | jq -r '.snapshots[0].height')
7179
echo "Getting latest passed upgrade plan before ${max_height}"
@@ -87,9 +95,12 @@ install_genesis_zetacored() {
8795
}
8896

8997
restore_snapshot() {
90-
snapshot_link=$($CURL "${ZETACHAIN_SNAPSHOT_METADATA_URL}" | jq -r '.snapshots[0].link')
98+
snapshot=$($CURL "${ZETACHAIN_SNAPSHOT_METADATA_URL}" | jq -r '.snapshots[0]')
99+
snapshot_link=$(echo "$snapshot" | jq -r '.link')
100+
snapshot_md5=$(echo "$snapshot" | jq -r '.checksums.md5')
91101
echo "Restoring snapshot from ${snapshot_link}"
92-
$CURL "$snapshot_link" | tar x -C $HOME/.zetacored
102+
# https://github.com/zeta-chain/dl-pipe
103+
dl-pipe -hash "md5:${snapshot_md5}" "$snapshot_link" | tar x -C $HOME/.zetacored
93104
}
94105

95106
cd $HOME
@@ -100,12 +111,12 @@ if [[ -f /root/init_started && ! -f /root/init_completed ]]; then
100111
fi
101112

102113
touch /root/init_started
103-
if [[ ! -f /root/init_complete ]]; then
114+
if [[ ! -f /root/init_completed ]]; then
104115
echo "Starting initialization"
105116
download_configs
106117
install_genesis_zetacored
107118
restore_snapshot
108-
touch /root/init_complete
119+
touch /root/init_completed
109120
else
110121
echo "Initialization already completed"
111122
fi

0 commit comments

Comments
 (0)