Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: image

on:
push:
branches: ['**']
tags: ['v*']
pull_request:
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 120
env:
GHCR_IMAGE: ghcr.io/runonflux/blockbook-docker
HUB_IMAGE: runonflux/blockbook-docker
HAS_HUB: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }}
steps:
- uses: actions/checkout@v4

- name: Shell syntax
run: for f in *.sh test/*.sh; do bash -n "$f"; done && python3 -m py_compile snapshot_server.py

- uses: docker/setup-buildx-action@v3

- name: Build
uses: docker/build-push-action@v6
with:
context: .
load: true
tags: blockbook-docker:test
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Smoke test
run: bash test/smoke.sh blockbook-docker:test

- name: Log in to ghcr.io
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to Docker Hub
if: startsWith(github.ref, 'refs/tags/v') && env.HAS_HUB == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push
if: startsWith(github.ref, 'refs/tags/v')
run: |
TAG=${GITHUB_REF_NAME}
# Flux nodes check an app's image tag every 6 hours and redeploy the app
# in place, data kept, when the tag points at a new image; a spec update
# installs it afresh wherever the network places it. So a v3 release also
# moves v3 and v3.0.0, the tag the app specs use.
TAGS=$(case $TAG in v3.*) echo "$TAG v3 v3.0.0" ;; *) echo "$TAG" ;; esac | tr ' ' '\n' | sort -u)
for image in $GHCR_IMAGE $([ "$HAS_HUB" = "true" ] && echo $HUB_IMAGE); do
for t in $TAGS; do
docker tag blockbook-docker:test $image:$t
docker push $image:$t
done
done
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
180 changes: 118 additions & 62 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,72 +1,128 @@
FROM debian:11
ENV DEBIAN_FRONTEND noninteractive
# Blockbook + coin daemon launcher for Flux.
#
# Blockbook, RocksDB and every coin's config files are built into the image at
# a pinned upstream commit, so all instances of an app run the same code and a
# container starts in seconds instead of compiling for half an hour. Daemon
# binaries are still downloaded on first start, from the URL pinned in the
# coin config of that same commit (plus overrides.json).
ARG ZEBRA_VERSION=7.0.0

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git wget autoconf automake jq bc supervisor procps curl \
graphviz libsnappy-dev libzstd-dev zlib1g-dev libbz2-dev liblz4-dev libunwind-dev \
bsdmainutils build-essential g++-multilib libc6-dev pv libarchive-tools cron unzip libtool \
m4 ncurses-dev pkg-config python3 python3-zmq zlib1g-dev libzmq3-dev libgflags-dev
FROM zfnd/zebra:${ZEBRA_VERSION} AS zebra

ENV BLOCKBOOKGIT_URL=${BLOCKBOOKGIT_URL:-https://github.com/trezor/blockbook.git}
ENV TAG=${TAG:-master}
ENV RPC_USER=${RPC_USER:-user}
ENV RPC_PASS=${RPC_PASS:-pass}
ENV HOME=/opt
ENV BOOTSTRAP=${BOOTSTRAP:-0}
ENV DAEMON=${DAEMON:-1}
ENV CONFIG=${CONFIG:-AUTO}
ENV GOLANG_VERSION="go1.23.7"
ENV ROCKSDB_VERSION=${ROCKSDB_VERSION:-v9.10.0}
ENV DAEMON_CONFIG=${DAEMON_CONFIG:-AUTO}
ENV GOPATH=$HOME/go
ENV PATH=$PATH:$GOPATH/bin
ENV CGO_CFLAGS="-I$HOME/rocksdb/include -O -D__BLST_PORTABLE__"
ENV CGO_LDFLAGS="-L$HOME/rocksdb -lrocksdb -lstdc++ -lm -lz -ldl -lbz2 -lsnappy -llz4 -lzstd"
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"
# Same Debian as the runtime stage: zmq4 refuses to start when the libzmq it
# was built against differs from the one it runs with (4.3.4 vs 4.3.5).
FROM debian:13 AS build
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Zelcore's fork of trezor/blockbook: the Flux/Zelcore explorer UI and an optional Insight API
ARG BLOCKBOOK_REPO=https://github.com/ZelCore-io/blockbook.git
ARG BLOCKBOOK_COMMIT=f4595896869d663c2e69bdd2b86524f8a5049e4c
ARG GOLANG_VERSION=go1.25.4
ARG GOLANG_SHA256=9fa5ffeda4170de60f67f3aa0f824e426421ba724c21e133c1e35d6159ca1bec
ARG ROCKSDB_VERSION=v9.10.0
ENV DEBIAN_FRONTEND=noninteractive

# Install GOLANG
RUN echo "Installing GOLANG [$GOLANG_VERSION]..." && \
cd /opt && wget https://dl.google.com/go/$GOLANG_VERSION.linux-amd64.tar.gz && \
tar xf $GOLANG_VERSION.linux-amd64.tar.gz && \
rm $GOLANG_VERSION.linux-amd64.tar.gz
RUN ln -s /opt/go/bin/go /usr/bin/go
RUN mkdir -p $GOPATH
RUN echo -n "GO version: " && go version
RUN echo -n "GOPATH: " && echo $GOPATH
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential ca-certificates git wget jq pkg-config libzmq3-dev libgflags-dev \
libsnappy-dev zlib1g-dev libbz2-dev libzstd-dev liblz4-dev libjemalloc-dev && \
rm -rf /var/lib/apt/lists/*

# Install RocksDB
#RUN echo "Installing RocksDB [$ROCKSDB_VERSION]..." && \
#cd $HOME && git clone -b $ROCKSDB_VERSION --depth 1 https://github.com/facebook/rocksdb.git && \
#cd $HOME/rocksdb && CFLAGS=-fPIC CXXFLAGS='-fPIC -Wno-error=deprecated-copy -Wno-error=pessimizing-move -Wno-error=class-memaccess' PORTABLE=1 make -j 4 release
RUN cd /opt && wget -q https://dl.google.com/go/${GOLANG_VERSION}.linux-amd64.tar.gz && \
echo "${GOLANG_SHA256} ${GOLANG_VERSION}.linux-amd64.tar.gz" | sha256sum -c - && \
tar xf ${GOLANG_VERSION}.linux-amd64.tar.gz && rm ${GOLANG_VERSION}.linux-amd64.tar.gz
ENV PATH=$PATH:/opt/go/bin GOPATH=/go GOTOOLCHAIN=local

# Install BlockBook
#RUN echo "Installing BlockBook..." && \
#REPO_UNCAT=${BLOCKBOOKGIT_URL##*/} && \
#REPO=${REPO_UNCAT%%.*} && \
#GIT_USER=$(echo "$BLOCKBOOKGIT_URL" | grep -oP "(?<=github.com.)\w+(?=.$REPO)"); \
#VERSION=$(curl -ssL https://raw.githubusercontent.com/$GIT_USER/$REPO/$TAG/configs/environ.json | jq -r .version); \
#echo -e "REPO: $REPO, VERSION: $VERSION" && \
#cd $HOME && git clone $BLOCKBOOKGIT_URL && \
#cd $HOME/blockbook && \
#git checkout "$TAG" && \
#go mod download && \
#BUILDTIME=$(date --iso-8601=seconds); GITCOMMIT=$(git describe --always --dirty); \
#LDFLAGS="-X github.com/trezor/blockbook/common.version=${VERSION}-${TAG} -X github.com/trezor/blockbook/common.gitcommit=${GITCOMMIT} -X github.com/trezor/blockbook/common.buildtime=${BUILDTIME}" && \
#go build -tags rocksdb_6_16 -ldflags="-s -w ${LDFLAGS}"
# PORTABLE: Flux nodes run on every kind of CPU, and an instruction the build
# host has but the node lacks is a SIGILL at start.
RUN git clone -b ${ROCKSDB_VERSION} --depth 1 https://github.com/facebook/rocksdb.git /opt/rocksdb && \
cd /opt/rocksdb && ROCKSDB_DISABLE_JEMALLOC=1 CFLAGS=-fPIC CXXFLAGS=-fPIC PORTABLE=1 \
DISABLE_WARNING_AS_ERROR=1 make -j"$(nproc)" release && strip ldb

COPY build.sh /build.sh
COPY daemon.sh /daemon.sh
COPY blockbook.sh /blockbook.sh
COPY check-health.sh /check-health.sh
COPY consensus.sh /consensus.sh
COPY utils.sh /utils.sh
COPY corruption.sh /corruption.sh
RUN git clone ${BLOCKBOOK_REPO} /src/blockbook && cd /src/blockbook && git checkout ${BLOCKBOOK_COMMIT}
WORKDIR /src/blockbook
COPY patches /tmp/patches
RUN for p in /tmp/patches/*.patch; do git apply --verbose "$p" || exit 1; done
RUN go mod download
# patches/0001 against a fake pruned bitcoind, patches/0002 against a zmq publisher
RUN go test -count=1 -run 'Pruned' ./bchain/coins/btc/ && go test -count=1 -run 'MQShutdown' ./bchain/ && \
go test -count=1 ./explorercontent/ ./static/templates/

RUN chmod 755 /blockbook.sh /daemon.sh /build.sh /check-health.sh /consensus.sh /utils.sh /corruption.sh
RUN mkdir -p /var/log/supervisor
ENV CGO_CFLAGS="-I/opt/rocksdb/include -O -D__BLST_PORTABLE__" \
CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"
RUN VERSION=$(jq -r .version configs/environ.json) && \
export CGO_LDFLAGS="-L/opt/rocksdb -ldl -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd $(gcc -print-file-name=libjemalloc_pic.a)" && \
go build -o /out/blockbook -ldflags="-s -w \
-X github.com/trezor/blockbook/common.version=${VERSION} \
-X github.com/trezor/blockbook/common.gitcommit=$(git rev-parse HEAD) \
-X github.com/trezor/blockbook/common.buildtime=$(date --iso-8601=seconds)"

# The config generator writes bitcoind's rpcauth line with
# build/scripts/rpcauth.py; without python3 it silently leaves the line out
# and the daemon refuses every RPC login.
RUN apt-get update && apt-get install -y --no-install-recommends python3 && rm -rf /var/lib/apt/lists/*

# Coin overrides (daemon versions we need ahead of upstream), then every coin's
# blockchaincfg.json and backend server.conf rendered with the container's
# paths, so nothing has to be compiled or fetched from GitHub at run time.
COPY overrides.json /tmp/overrides.json
RUN for coin in $(jq -r 'keys[]' /tmp/overrides.json); do \
jq -s '.[0] * .[1]' configs/coins/$coin.json <(jq --arg c $coin '.[$c]' /tmp/overrides.json) > /tmp/c.json && \
mv /tmp/c.json configs/coins/$coin.json; \
done && \
jq '.backend_install_path="/root" | .backend_data_path="/root"' configs/environ.json > /tmp/e.json && \
mv /tmp/e.json configs/environ.json && \
go build -o /tmp/generate build/templates/generate.go && \
for f in configs/coins/*.json; do \
coin=$(basename $f .json); rm -rf build/pkg-defs; \
if BB_BUILD_ENV=prod /tmp/generate $coin > /dev/null 2>&1; then \
mkdir -p /out/pkg/$coin; \
cp build/pkg-defs/blockbook/blockchaincfg.json /out/pkg/$coin/ 2>/dev/null || true; \
cp build/pkg-defs/backend/server.conf /out/pkg/$coin/ 2>/dev/null || true; \
fi; \
done && \
echo "coins rendered: $(ls /out/pkg | wc -l)" && \
test -f /out/pkg/flux/blockchaincfg.json && test -f /out/pkg/zcash/server.conf && \
grep -q 'cache_dir = "/root/zcash/backend/zebra"' /out/pkg/zcash/server.conf && \
grep -q '^rpcauth=rpc:' /out/pkg/bitcoin/server.conf && grep -q '^rpcauth=rpc:' /out/pkg/bitcoin_regtest/server.conf && \
mkdir -p /out/configs && cp -r configs/coins /out/configs/ && cp configs/environ.json /out/configs/ && \
cp -r static /out/static && \
echo "blockbook $(jq -r .version configs/environ.json) $(git rev-parse --short HEAD)" > /out/VERSION

# zebrad (copied from zfnd/zebra, built on Debian 13) needs glibc 2.39 and
# CXXABI_1.3.15.
FROM debian:13-slim
# Links the ghcr.io package to this repository.
LABEL org.opencontainers.image.source=https://github.com/RunOnFlux/blockbook-docker
ENV DEBIAN_FRONTEND=noninteractive
# The daemons downloaded at start need only glibc (2.34 at most), libgcc_s,
# libstdc++ (fluxd) and libatomic (Bitcoin Cash Node 29), checked 2026-10-21.
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl wget jq bc supervisor cron procps pv libarchive-tools unzip xz-utils \
python3 libsnappy1v5 libzstd1 liblz4-1 libbz2-1.0 zlib1g libzmq5 libgflags2.2 libstdc++6 libatomic1 && \
rm -rf /var/lib/apt/lists/*

COPY --from=build /out/blockbook /opt/blockbook/blockbook
COPY --from=build /out/configs /opt/blockbook/configs
# blockbook loads its explorer templates from ./static (blockbook.sh runs it from /opt/blockbook)
COPY --from=build /out/static /opt/blockbook/static
COPY --from=build /out/pkg /opt/blockbook/pkg
COPY --from=build /out/VERSION /opt/blockbook/VERSION
COPY --from=build /opt/rocksdb/ldb /opt/rocksdb/ldb
COPY --from=zebra /usr/local/bin/zebrad /usr/local/bin/zebrad
RUN /opt/blockbook/blockbook -help > /dev/null 2>&1; test $? -le 2 && zebrad --version

ENV HOME=/opt \
RPC_USER=user \
RPC_PASS=pass \
BOOTSTRAP=0 \
DAEMON=1 \
CONFIG=AUTO \
DAEMON_CONFIG=AUTO \
PEER_BOOTSTRAP=1

COPY build.sh daemon.sh blockbook.sh check-health.sh consensus.sh utils.sh corruption.sh heal.sh snapshot.sh prune.sh snapshot_server.py /
RUN chmod 755 /*.sh /snapshot_server.py && mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
VOLUME /root
EXPOSE $BLOCKBOOK_PORT 1337
HEALTHCHECK --start-period=10m --interval=4m --retries=5 --timeout=40s CMD ./check-health.sh
EXPOSE 1337
HEALTHCHECK --start-period=10m --interval=4m --retries=5 --timeout=40s CMD /check-health.sh
ENTRYPOINT ["/usr/bin/supervisord"]
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
# Multicoin Blockbook Explorer

### v3: pinned image
Images are published as `ghcr.io/runonflux/blockbook-docker:<tag>` from `v*` git tags (CI builds and
runs `test/smoke.sh` first). Pin app specs to a tag, never `latest`. Every `v3.*` release also
moves `v3` and `v3.0.0` (the tag the app specs use): Flux nodes check an app's tag every 6 hours
and redeploy it in place with its data kept, while a spec update installs the app afresh
wherever the network places it.

- Blockbook, RocksDB and every coin's configs are built into the image from the
[ZelCore-io/blockbook](https://github.com/ZelCore-io/blockbook) commit pinned in the `Dockerfile`
(trezor/blockbook with the Flux/Zelcore explorer UI); nothing is compiled or fetched from GitHub
at container start. The fork's dashboard feed (`-explorercontenturl`) and Insight API
(`-insight`) are off unless passed in `BLOCKBOOK_PARAMS`.
Daemon versions come from that commit's coin configs, with `overrides.json` on top
(fluxd 9.1.0, zebrad for Zcash, which is copied in from `zfnd/zebra`).
- When the image changes, an existing container re-renders its configs and downloads the new
daemon; chain data is kept.
- **Peer snapshots** (`snapshot.sh`, `snapshot_server.py`): a synced instance keeps a hard-link
snapshot of its chain data and serves it on container port 1337 to the other instances of the same
Flux app. A new or far-behind instance seeds from the best peer instead of syncing from block 0.
Needs port 1337 mapped in the app spec. `PEER_BOOTSTRAP=0` disables seeding,
`SNAPSHOT_PEERS="ip:port ..."` seeds from given peers. A peer serves two downloads at a time
and answers the rest busy. A download that breaks off continues from the file it was writing.
An instance keeps its own data until the download is complete, unless the disk cannot hold
both; then it deletes it only once a peer is sending, so a busy or unreachable peer leaves it
as it was.
- `heal.sh` runs `reconsiderblock` when the daemon has marked the network's chain invalid and
stopped on its last good block.
- Blockbook stops cleanly (`patches/0002`). It closed its ZMQ socket from another thread while a
receive was waiting on it, so libzmq aborted the process now and then and the index was left
marked open. After such a stop, `/api/` showed the last stored height (0 on a new index) until
the next block.
- `corruption.sh` only wipes a database its own process reports as corrupt or refuses to open
(another coin, other index settings); `log_clean` only empties named log files (it used to empty
LevelDB/RocksDB write-ahead logs). It runs every 30 minutes.
- The first sync with several workers is a bulk import: blockbook holds large maps of
transactions and balances in memory and marks the index inconsistent until it ends. Killed
before that (out of memory, shared with the daemon), it leaves an index it refuses to open.
`corruption.sh` rebuilds such an index (from a peer's snapshot if one has it) and
`/root/blockbook-db.sequential` makes blockbook sync with one worker from then on: slower,
much less memory, consistent after every block. Blockbook runs with `GOMEMLIMIT` at half the
container's memory (80% without a local daemon).
- `PRUNE_BACKEND=1` (Bitcoin): the daemon runs without txindex and with manual pruning, and
`prune.sh` keeps it `PRUNE_KEEP_BLOCKS` (2000) behind blockbook, pausing it at
`PRUNE_MAX_BLOCKS_GB` (80) of unindexed blocks. Blockbook (`-prunedbackend`, `patches/0001`)
gets a confirmed transaction from the block its index places it in, and downloads a pruned
block again from a peer that keeps every block (`getblockfrompeer`), so transactions, address
and xpub histories, `tx-specific` and blocks come back complete. The first request for an old
transaction waits for that download (about a second; a history page downloads up to 8 blocks
at once, and at most 8 run at a time overall); after that it is in the tx cache, which is
emptied when it passes `TXCACHE_MAX_GB` (20). Without `-extendedindex` Bitcoin needs ~640 GB
instead of ~1.1 TB plus 886 GB of blocks (2026); as on every other coin without it, a spent
output gets `spentTxId` only with `?spending=true`. If no peer sends a block, the transaction
comes from the index: fee and vsize included, scripts and input txids not.
- Zebra releases stop at an end-of-support height, 8 to 16 weeks after release (zebrad
panics in `end_of_support.rs` at every start): bump `ZEBRA_VERSION` in time. 7.0.0 (NU7)
halts about 56 days after its release, around mid-December 2026.

### USAGE
```
bash -i <(curl -s https://raw.githubusercontent.com/RunOnFlux/blockbook-docker/master/blockbook-docker_manager.sh)
Expand Down
Loading
Loading