Skip to content

Commit 28295d5

Browse files
committed
pipeline for building pi image
1 parent ca214cc commit 28295d5

4 files changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This workflow builds a Raspberry Pi image with Docker and Bitbot pre-installed
2+
# and uploads the bootable image as an artifact.
3+
4+
name: Build Raspberry Pi Image
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches: [ main ]
10+
11+
jobs:
12+
build-pi-image:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up QEMU
19+
uses: docker/setup-qemu-action@v3
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- name: Install dependencies
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y coreutils kpartx qemu-user-static debootstrap dosfstools rsync parted wget git
28+
29+
- name: Build Raspberry Pi image
30+
run: |
31+
cd build-image
32+
sudo bash build.sh
33+
34+
- name: Upload image artifact
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: bitbot-pi-image
38+
path: build-image/output/bitbot-pi.img

.vscode/mcp.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"servers": {
3+
"context7": {
4+
"url": "https://mcp.context7.com/mcp"
5+
}
6+
}
7+
}

build-image/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Directory for output image and mount point
2+
output/
3+
mnt/

build-image/build.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# build.sh: Build a minimal Raspberry Pi OS image with Docker and Bitbot Docker Compose
3+
set -e
4+
5+
IMG=output/bitbot-pi.img
6+
IMG_SIZE=4G
7+
MOUNT_DIR=mnt
8+
9+
# Clean up previous build
10+
sudo umount -lf $MOUNT_DIR || true
11+
rm -rf $MOUNT_DIR output
12+
mkdir -p $MOUNT_DIR output
13+
14+
# Download minimal Raspberry Pi OS Lite image
15+
wget -O output/rpi-os-lite.img https://downloads.raspberrypi.com/raspios_lite_armhf_latest
16+
17+
# Extract the image
18+
mv output/rpi-os-lite.img $IMG
19+
20+
# Mount the image
21+
LOOPDEV=$(sudo losetup -f --show $IMG)
22+
PART=$(sudo kpartx -av $LOOPDEV | grep -m1 'p2' | awk '{print $3}')
23+
sudo mount /dev/mapper/$PART $MOUNT_DIR
24+
25+
# Copy Bitbot project and Docker Compose files
26+
sudo mkdir -p $MOUNT_DIR/home/pi/bitbot
27+
sudo rsync -a --exclude 'build-image' --exclude '.git' ../../ $MOUNT_DIR/home/pi/bitbot/
28+
29+
# Install Docker and Docker Compose on first boot
30+
cat <<'EOF' | sudo tee $MOUNT_DIR/etc/rc.local > /dev/null
31+
#!/bin/bash
32+
# rc.local
33+
set -e
34+
if ! command -v docker &> /dev/null; then
35+
curl -fsSL https://get.docker.com -o get-docker.sh
36+
sh get-docker.sh
37+
usermod -aG docker pi
38+
fi
39+
if ! command -v docker-compose &> /dev/null; then
40+
pip3 install docker-compose
41+
fi
42+
cd /home/pi/bitbot
43+
/usr/local/bin/docker-compose up -d
44+
exit 0
45+
EOF
46+
sudo chmod +x $MOUNT_DIR/etc/rc.local
47+
48+
# Unmount and clean up
49+
sudo umount $MOUNT_DIR
50+
sudo kpartx -d $LOOPDEV
51+
sudo losetup -d $LOOPDEV
52+
53+
echo "Image ready: $IMG"

0 commit comments

Comments
 (0)