|
1 | | -name: Build Raspberry Pi OS App in QEMU |
| 1 | +name: Build in QEMU |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | tags: |
6 | | - - 'v**-qemu' |
| 6 | + - 'v**-rc.[0-9]+' |
7 | 7 |
|
8 | 8 | jobs: |
| 9 | + prepare-image: |
| 10 | + runs-on: ubuntu-24.04-arm |
| 11 | + outputs: |
| 12 | + raspios_version: ${{ steps.os_version.outputs.name }} |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Install QEMU and Dependencies |
| 16 | + run: | |
| 17 | + sudo apt update |
| 18 | + sudo apt install -y qemu-system qemu-user-static binfmt-support libfdt-dev |
| 19 | +
|
| 20 | + - name: Install Tool dtmerge |
| 21 | + run: | |
| 22 | + git clone https://github.com/raspberrypi/utils.git |
| 23 | + cd utils/dtmerge |
| 24 | + cmake . |
| 25 | + make |
| 26 | + sudo make install |
| 27 | +
|
| 28 | + - name: Extract OS Version |
| 29 | + id: os_version |
| 30 | + run: | |
| 31 | + FILE_URL=$(curl -sI https://downloads.raspberrypi.org/raspios_lite_arm64_latest | grep -i '^location:' | awk '{print $2}' | tr -d '\r') |
| 32 | + FILENAME=$(basename $FILE_URL) |
| 33 | + OS_NAME=$(echo $FILENAME | grep -oP 'raspios-[a-z]+-arm64') |
| 34 | + echo "name=$OS_NAME" >> $GITHUB_OUTPUT |
| 35 | +
|
| 36 | + - name: Download and Prepare Raspberry Pi OS Image |
| 37 | + run: | |
| 38 | + wget -q https://downloads.raspberrypi.org/raspios_lite_arm64_latest -O rpi-os.img.xz |
| 39 | + xz -d rpi-os.img.xz |
| 40 | +
|
| 41 | + sudo mkdir boot |
| 42 | + sudo mount -o loop,offset=4194304 rpi-os.img boot |
| 43 | +
|
| 44 | + cp boot/kernel8.img kernel8.img |
| 45 | + cp boot/bcm2710-rpi-3-b-plus.dtb custom.dtb |
| 46 | +
|
| 47 | + dtmerge custom.dtb merged.dtb - uart0=on |
| 48 | + mv merged.dtb custom.dtb |
| 49 | + dtmerge custom.dtb merged.dtb boot/overlays/disable-bt.dtbo |
| 50 | + mv merged.dtb custom.dtb |
| 51 | + |
| 52 | + sudo touch boot/ssh |
| 53 | + echo 'pi:$6$uQd.Z0f45vuTlnIM$fH2KnG/2zM/c7oQNYKf/VOhqPlkR82IFNIjmDWftvrmw/K1XPLNJVMvWgmqq0iMjn9dd7gfJAl2tM5e8vgiu8/' | sudo tee boot/userconf.txt > /dev/null |
| 54 | + echo -e "\ndtoverlay=disable-bt\ndtparam=uart0=on" | sudo tee -a boot/config.txt > /dev/null |
| 55 | +
|
| 56 | + sudo umount boot |
| 57 | +
|
| 58 | + qemu-img resize rpi-os.img 8g |
| 59 | +
|
| 60 | + - name: Install Dependencies in QEMU |
| 61 | + run: | |
| 62 | + qemu-system-aarch64 \ |
| 63 | + -machine raspi3b \ |
| 64 | + -cpu cortex-a72 \ |
| 65 | + -smp 4 -m 1G \ |
| 66 | + -kernel kernel8.img \ |
| 67 | + -dtb custom.dtb \ |
| 68 | + -drive "file=rpi-os.img,format=raw,index=0,if=sd" \ |
| 69 | + -append "rw console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4" \ |
| 70 | + -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22 \ |
| 71 | + -display none \ |
| 72 | + -daemonize |
| 73 | +
|
| 74 | + sleep 300 |
| 75 | +
|
| 76 | + sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\ |
| 77 | + sudo parted /dev/mmcblk0 resizepart 2 100% && \ |
| 78 | + sudo resize2fs -fp /dev/mmcblk0p2 && \ |
| 79 | + df -h && \ |
| 80 | + lsblk && \ |
| 81 | + echo "CONF_SWAPSIZE=1024" | sudo tee -a /etc/dphys-swapfile && \ |
| 82 | + sudo systemctl restart dphys-swapfile |
| 83 | + " |
| 84 | +
|
| 85 | + sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\ |
| 86 | + sudo apt update && \ |
| 87 | + sudo apt full-upgrade -y && \ |
| 88 | + sudo apt install -y \ |
| 89 | + wget \ |
| 90 | + curl \ |
| 91 | + cmake \ |
| 92 | + clang \ |
| 93 | + build-essential \ |
| 94 | + mosquitto-dev \ |
| 95 | + libboost-program-options-dev \ |
| 96 | + libavformat-dev \ |
| 97 | + libavcodec-dev \ |
| 98 | + libavutil-dev \ |
| 99 | + libswscale-dev \ |
| 100 | + libpulse-dev \ |
| 101 | + libasound2-dev \ |
| 102 | + libjpeg-dev \ |
| 103 | + libcamera-dev \ |
| 104 | + libmosquitto-dev |
| 105 | + " |
| 106 | +
|
| 107 | + - name: Install Additional libwebrtc and json.hpp in QEMU |
| 108 | + run: | |
| 109 | + sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\ |
| 110 | + wget -q https://github.com/TzuHuanTai/Native-WebRTC-Build/releases/download/5790/libwebrtc-arm64.tar.gz && |
| 111 | + tar -xzf libwebrtc-arm64.tar.gz && |
| 112 | + sudo mkdir -p /usr/local/include/webrtc && |
| 113 | + sudo mv include/* /usr/local/include/webrtc && |
| 114 | + sudo mv lib/* /usr/local/lib && |
| 115 | + sudo mkdir -p /usr/local/include/nlohmann && |
| 116 | + sudo curl -L https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp -o /usr/local/include/nlohmann/json.hpp |
| 117 | + " |
| 118 | +
|
| 119 | + - name: Upload Raspberry Pi OS Image |
| 120 | + uses: actions/upload-artifact@v4 |
| 121 | + with: |
| 122 | + name: rpi-os-image |
| 123 | + path: | |
| 124 | + rpi-os.img |
| 125 | + kernel8.img |
| 126 | + custom.dtb |
| 127 | +
|
9 | 128 | build: |
10 | 129 | runs-on: ubuntu-24.04-arm |
| 130 | + needs: prepare-image |
| 131 | + strategy: |
| 132 | + matrix: |
| 133 | + signaling: [MQTT, HTTP] |
| 134 | + build_type: [Debug, Release] |
11 | 135 |
|
12 | 136 | steps: |
13 | | - - name: Install QEMU and Dependencies |
14 | | - run: | |
15 | | - sudo apt update |
16 | | - sudo apt install -y qemu-system qemu-user-static binfmt-support libfdt-dev |
17 | | -
|
18 | | - - name: Install Tool dtmerge |
19 | | - run: | |
20 | | - git clone https://github.com/raspberrypi/utils.git |
21 | | - cd utils/dtmerge |
22 | | - cmake . |
23 | | - make |
24 | | - sudo make install |
25 | | -
|
26 | | - - name: Download and Prepare Raspberry Pi OS Image |
27 | | - run: | |
28 | | - wget -q https://downloads.raspberrypi.org/raspios_lite_arm64_latest -O rpi-os.img.xz |
29 | | - xz -d rpi-os.img.xz |
30 | | - fdisk -l rpi-os.img |
31 | | -
|
32 | | - sudo mkdir boot |
33 | | - sudo mount -o loop,offset=4194304 rpi-os.img boot |
34 | | -
|
35 | | - cp boot/kernel8.img kernel8.img |
36 | | - cp boot/bcm2710-rpi-3-b-plus.dtb custom.dtb |
37 | | -
|
38 | | - dtmerge custom.dtb merged.dtb - uart0=on |
39 | | - mv merged.dtb custom.dtb |
40 | | - dtmerge custom.dtb merged.dtb boot/overlays/disable-bt.dtbo |
41 | | - mv merged.dtb custom.dtb |
42 | | - |
43 | | - sudo touch boot/ssh |
44 | | - echo 'pi:$6$uQd.Z0f45vuTlnIM$fH2KnG/2zM/c7oQNYKf/VOhqPlkR82IFNIjmDWftvrmw/K1XPLNJVMvWgmqq0iMjn9dd7gfJAl2tM5e8vgiu8/' | sudo tee boot/userconf.txt > /dev/null |
45 | | - echo -e "\ndtoverlay=disable-bt\ndtparam=uart0=on" | sudo tee -a boot/config.txt > /dev/null |
46 | | -
|
47 | | - sudo umount boot |
48 | | -
|
49 | | - qemu-img resize rpi-os.img 8g |
50 | | -
|
51 | | - - name: Run Raspberry Pi OS with QEMU |
52 | | - run: | |
53 | | - qemu-system-aarch64 \ |
54 | | - -machine raspi3b \ |
55 | | - -cpu cortex-a72 \ |
56 | | - -smp 4 -m 1G \ |
57 | | - -kernel kernel8.img \ |
58 | | - -dtb custom.dtb \ |
59 | | - -drive "file=rpi-os.img,format=raw,index=0,if=sd" \ |
60 | | - -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1 fsck.repair=yes rootfstype=ext4" \ |
61 | | - -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22 \ |
62 | | - -display none \ |
63 | | - -daemonize |
64 | | -
|
65 | | - sleep 180 |
66 | | - sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\ |
67 | | - sudo parted /dev/mmcblk0 resizepart 2 100% && \ |
68 | | - sudo resize2fs -fp /dev/mmcblk0p2 && \ |
69 | | - df -h && \ |
70 | | - lsblk |
71 | | - " |
72 | | -
|
73 | | - - name: Install Dependencies in QEMU |
74 | | - run: | |
75 | | - sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\ |
76 | | - sudo apt update && \ |
77 | | - sudo apt full-upgrade -y && \ |
78 | | - sudo apt install -y \ |
79 | | - wget \ |
80 | | - curl \ |
81 | | - cmake \ |
82 | | - clang \ |
83 | | - build-essential \ |
84 | | - mosquitto-dev \ |
85 | | - libboost-program-options-dev \ |
86 | | - libavformat-dev \ |
87 | | - libavcodec-dev \ |
88 | | - libavutil-dev \ |
89 | | - libswscale-dev \ |
90 | | - libpulse-dev \ |
91 | | - libasound2-dev \ |
92 | | - libjpeg-dev \ |
93 | | - libcamera-dev \ |
94 | | - libmosquitto-dev |
95 | | - " |
96 | | -
|
97 | | - - name: Install Additional libwebrtc and json.hpp in QEMU |
98 | | - run: | |
99 | | - sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\ |
100 | | - wget https://github.com/TzuHuanTai/Native-WebRTC-Build/releases/download/5790/libwebrtc-arm64.tar.gz && |
101 | | - tar -xzf libwebrtc-arm64.tar.gz && |
102 | | - sudo mkdir -p /usr/local/include/webrtc && |
103 | | - sudo mv include/* /usr/local/include/webrtc && |
104 | | - sudo mv lib/* /usr/local/lib && |
105 | | - sudo mkdir -p /usr/local/include/nlohmann && |
106 | | - sudo curl -L https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp -o /usr/local/include/nlohmann/json.hpp |
107 | | - " |
108 | | -
|
109 | | - - name: Checkout code |
110 | | - uses: actions/checkout@v4 |
111 | | - |
112 | | - - name: Build project inside Raspberry Pi OS |
113 | | - run: | |
114 | | - sshpass -p "raspberry" scp -P 5555 -r . pi@localhost:~/project |
115 | | - sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\ |
116 | | - ls ~/project && \ |
117 | | - cd project && \ |
118 | | - mkdir build && \ |
119 | | - cd build && \ |
120 | | - cmake .. -DCMAKE_CXX_COMPILER=clang++ -DUSE_MQTT_SIGNALING=ON -DCMAKE_BUILD_TYPE=Release && \ |
121 | | - make -j$(nproc) && \ |
122 | | - tar -czvf pi_webrtc-${{ github.ref_name }}_MQTT_Release.tar.gz pi_webrtc |
123 | | - " |
| 137 | + - name: Install QEMU and Dependencies |
| 138 | + run: | |
| 139 | + sudo apt update |
| 140 | + sudo apt install -y qemu-system qemu-user-static binfmt-support libfdt-dev |
| 141 | +
|
| 142 | + - name: Download Raspberry Pi OS Image |
| 143 | + uses: actions/download-artifact@v4 |
| 144 | + with: |
| 145 | + name: rpi-os-image |
| 146 | + path: . |
| 147 | + |
| 148 | + - name: Run Raspberry Pi OS with QEMU |
| 149 | + run: | |
| 150 | + qemu-system-aarch64 \ |
| 151 | + -machine raspi3b \ |
| 152 | + -cpu cortex-a72 \ |
| 153 | + -smp 4 -m 1G \ |
| 154 | + -kernel kernel8.img \ |
| 155 | + -dtb custom.dtb \ |
| 156 | + -drive "file=rpi-os.img,format=raw,index=0,if=sd" \ |
| 157 | + -append "rw console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4" \ |
| 158 | + -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22 \ |
| 159 | + -display none \ |
| 160 | + -daemonize |
| 161 | +
|
| 162 | + sleep 300 |
| 163 | +
|
| 164 | + - name: Checkout code |
| 165 | + uses: actions/checkout@v4 |
| 166 | + |
| 167 | + - name: Build project inside Raspberry Pi OS |
| 168 | + run: | |
| 169 | + sshpass -p "raspberry" scp -P 5555 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r . pi@localhost:~/project |
| 170 | + sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\ |
| 171 | + cd project && \ |
| 172 | + mkdir build && \ |
| 173 | + cd build && \ |
| 174 | + cmake .. -DCMAKE_CXX_COMPILER=clang++ -DUSE_${{ matrix.signaling }}_SIGNALING=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} && \ |
| 175 | + make -j$(nproc) |
| 176 | + " |
| 177 | + sshpass -p "raspberry" scp -P 5555 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null pi@localhost:~/project/build/pi_webrtc . |
| 178 | +
|
| 179 | + - name: Zip binary |
| 180 | + id: zip-binary |
| 181 | + run: | |
| 182 | + if [ "${{ matrix.build_type }}" == "Release" ]; then |
| 183 | + FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_${{ needs.prepare-image.outputs.raspios_version }}.tar.gz" |
| 184 | + else |
| 185 | + FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_${{ needs.prepare-image.outputs.raspios_version }}_debug.tar.gz" |
| 186 | + fi |
| 187 | + sudo tar -czvf $FILENAME pi_webrtc |
| 188 | + echo "filename=$FILENAME" >> $GITHUB_OUTPUT |
| 189 | +
|
| 190 | + - name: Upload to GitHub |
| 191 | + uses: softprops/action-gh-release@v2 |
| 192 | + with: |
| 193 | + files: ${{ steps.zip-binary.outputs.filename }} |
0 commit comments