diff --git a/tools/pi-gen-tipote/Dockerfile b/tools/pi-gen-tipote/Dockerfile index 58646fd..dfa0c78 100644 --- a/tools/pi-gen-tipote/Dockerfile +++ b/tools/pi-gen-tipote/Dockerfile @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y \ WORKDIR /build -# Clone pi-gen +# Clone pi-gen (bookworm branch for Raspberry Pi OS stable) RUN git clone --depth 1 --branch bookworm https://github.com/RPi-Distro/pi-gen.git /build/pi-gen # Copy config and stage @@ -24,10 +24,13 @@ COPY stage-tipote/ /build/pi-gen/stage-tipote/ # Skip stage2 image export (we export from stage-tipote) RUN touch /build/pi-gen/stage2/SKIP_IMAGES -# Patch pi-gen for Docker Desktop compatibility: -# 1. Remove setarch linux32 calls (fails on Docker Desktop) +# Patch pi-gen for Docker compatibility: +# 1. Remove setarch linux32 calls (fails on some Docker setups) # 2. Remove qemu-user-binfmt from dependency check (conflicts with qemu-user-static) RUN find /build/pi-gen -name "*.sh" -exec sed -i 's/setarch linux32 //g' {} + 2>/dev/null || true \ && sed -i '/qemu-user-binfmt/d' /build/pi-gen/depends -CMD ["bash", "-c", "modprobe binfmt_misc 2>/dev/null || true && mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc 2>/dev/null || true && cd /build/pi-gen && ./build.sh && mkdir -p /output && cp deploy/*.img.xz /output/ 2>/dev/null || cp deploy/*.img /output/ 2>/dev/null && ls -lh /output/"] +COPY entrypoint.sh /build/entrypoint.sh +RUN chmod +x /build/entrypoint.sh + +CMD ["/build/entrypoint.sh"] diff --git a/tools/pi-gen-tipote/entrypoint.sh b/tools/pi-gen-tipote/entrypoint.sh new file mode 100755 index 0000000..e01a8b9 --- /dev/null +++ b/tools/pi-gen-tipote/entrypoint.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -euo pipefail + +# Load binfmt_misc for ARM emulation +modprobe binfmt_misc 2>/dev/null || true +mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc 2>/dev/null || true + +cd /build/pi-gen + +# Retry build up to 3 times (Raspbian mirrors can be flaky) +MAX_RETRIES=3 +for attempt in $(seq 1 $MAX_RETRIES); do + echo "=== Build attempt $attempt/$MAX_RETRIES ===" + + if ./build.sh; then + echo "=== Build succeeded on attempt $attempt ===" + mkdir -p /output + cp deploy/*.img.xz /output/ 2>/dev/null || cp deploy/*.img /output/ 2>/dev/null + ls -lh /output/ + exit 0 + fi + + if [ "$attempt" -lt "$MAX_RETRIES" ]; then + echo "=== Build failed, cleaning up for retry... ===" + # Clean debootstrap rootfs so it starts fresh + rm -rf work/*/stage0/rootfs 2>/dev/null || true + rm -rf work/*/stage0/debootstrap* 2>/dev/null || true + sleep 5 + fi +done + +echo "=== All $MAX_RETRIES attempts failed ===" +exit 1