Skip to content

Commit a411dfb

Browse files
committed
feat: publishing pre-synced bitcoin-mutinynet
1 parent b1bcb47 commit a411dfb

File tree

2 files changed

+85
-8
lines changed

2 files changed

+85
-8
lines changed

docker-setup

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,15 @@ publish_image() {
430430

431431
# Publish the Bitcoin Docker image
432432
publish_bitcoin_image() {
433+
local presynced="false"
434+
435+
for arg in "$@"; do
436+
if [[ "$arg" == "--pre-sync" ]]; then
437+
presynced="true"
438+
break
439+
fi
440+
done
441+
433442
local username="${DOCKERHUB_USERNAME}"
434443

435444
if [ -z "$username" ]; then
@@ -445,26 +454,58 @@ publish_bitcoin_image() {
445454
local repo_name=$(echo "$BITCOIN_IMAGE_NAME" | awk -F/ '{print $NF}')
446455
local target_repo="${username}/${repo_name}"
447456

448-
# Ensure image is built
449-
build_bitcoin_image
457+
local tag="latest"
458+
if [ -f "$VERSION_FILE" ]; then
459+
tag=$(grep "^TAG=" "$VERSION_FILE" | cut -d'=' -f2)
460+
fi
450461

451-
# Get tag from version file
452-
local tag=$(grep "^TAG=" "$VERSION_FILE" | cut -d'=' -f2)
462+
if [[ "$presynced" == "true" ]]; then
463+
print_info "Preparing to publish pre-synced image to ${target_repo}:presynced-latest"
464+
print_warning "This process will build a Docker image that syncs the Bitcoin node during build."
465+
print_warning "This may take a significant amount of time."
466+
read -p "Are you sure? [y/N]: " confirm
467+
if [[ ! "${confirm}" =~ ^[Yy]$ ]]; then
468+
exit 0
469+
fi
470+
471+
print_info "Building pre-synced image using Dockerfile..."
472+
473+
if docker build \
474+
--build-arg TAG="$tag" \
475+
--network=host \
476+
-f docker/Dockerfile.bitcoin-mutinynet.presynced \
477+
-t "${target_repo}:presynced-latest" .; then
478+
479+
if [ -n "$tag" ]; then
480+
docker tag "${target_repo}:presynced-latest" "${target_repo}:presynced-${tag}"
481+
fi
482+
483+
print_info "Pushing images..."
484+
docker push "${target_repo}:presynced-latest"
485+
if [ -n "$tag" ]; then
486+
docker push "${target_repo}:presynced-${tag}"
487+
fi
488+
print_success "Published pre-synced images successfully"
489+
else
490+
print_error "Failed to build pre-synced image"
491+
exit 1
492+
fi
493+
else
494+
build_bitcoin_image
453495

454496
print_info "Tagging and pushing image to $target_repo..."
455497

456-
# Tag and push latest
457498
docker tag "${BITCOIN_IMAGE_NAME}:latest" "${target_repo}:latest"
458499
docker push "${target_repo}:latest"
459500

460-
# Tag and push version
461501
if [ -n "$tag" ]; then
462502
docker tag "${BITCOIN_IMAGE_NAME}:${tag}" "${target_repo}:${tag}"
463503
docker push "${target_repo}:${tag}"
464504
print_success "Published ${target_repo}:${tag}"
465505
fi
466506

467507
print_success "Published ${target_repo}:latest"
508+
fi
468509
}
469510

470511
# Start the full stack using docker-compose
@@ -549,7 +590,9 @@ show_help() {
549590
echo " build Build the Docker image"
550591
echo " build-bitcoin Build the Bitcoin Mutinynet Docker image"
551592
echo " publish [ver] Publish image to Docker Hub (optional version tag)"
552-
echo " publish-bitcoin Publish Bitcoin Mutinynet image to Docker Hub"
593+
echo " publish-bitcoin [options] Publish Bitcoin Mutinynet image to Docker Hub"
594+
echo " Options:"
595+
echo " --pre-sync Publish pre-synced Bitcoin image (presynced-latest)"
553596
echo " start [options] Start the full Coinswap stack"
554597
echo " Options:"
555598
echo " -d, --default Use default configuration without prompting"
@@ -594,7 +637,7 @@ case "${1:-}" in
594637
;;
595638
"publish-bitcoin")
596639
check_docker
597-
publish_bitcoin_image
640+
publish_bitcoin_image "${@:2}"
598641
;;
599642
"start")
600643
check_docker
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ARG TAG=latest
2+
FROM coinswap/bitcoin-mutinynet:${TAG}
3+
4+
USER root
5+
6+
COPY docs/bitcoin.conf /home/bitcoin/.bitcoin/bitcoin.conf
7+
RUN chown bitcoin:bitcoin /home/bitcoin/.bitcoin/bitcoin.conf
8+
9+
USER bitcoin
10+
11+
RUN bitcoind -signet -daemon && \
12+
echo "Waiting for Bitcoin to start..." && \
13+
( for i in {1..60}; do bitcoin-cli -signet -rpcwait getblockchaininfo >/dev/null 2>&1 && break || sleep 1; done ) && \
14+
echo "Bitcoin started. Syncing..." && \
15+
( \
16+
while true; do \
17+
INFO=$(bitcoin-cli -signet getblockchaininfo); \
18+
echo "[DEBUG]" $INFO \
19+
PEERS=$(bitcoin-cli -signet getconnectioncount); \
20+
BLOCKS=$(echo "$INFO" | grep '"blocks":' | awk '{print $2}' | tr -d ','); \
21+
HEADERS=$(echo "$INFO" | grep '"headers":' | awk '{print $2}' | tr -d ','); \
22+
IBD=$(echo "$INFO" | grep '"initialblockdownload":' | awk '{print $2}' | tr -d ','); \
23+
PROGRESS=$(echo "$INFO" | grep '"verificationprogress":' | awk '{print $2}' | tr -d ','); \
24+
echo "Progress: $BLOCKS / $HEADERS (IBD: $IBD, Peers: $PEERS, Verification: $PROGRESS)"; \
25+
if [ "$IBD" = "false" ] && [ "$BLOCKS" -gt 0 ]; then \
26+
echo "Sync complete!"; \
27+
break; \
28+
fi; \
29+
sleep 10; \
30+
done \
31+
) && \
32+
bitcoin-cli -signet stop && \
33+
( while pidof bitcoind >/dev/null; do sleep 1; done ) && \
34+
echo "Bitcoin stopped gracefully."

0 commit comments

Comments
 (0)