Skip to content

Commit d2a194b

Browse files
committed
feat: build by github action
1 parent 9a85c49 commit d2a194b

File tree

3 files changed

+316
-0
lines changed

3 files changed

+316
-0
lines changed

.github/workflows/build.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Build
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-24.04-arm
10+
11+
strategy:
12+
matrix:
13+
signaling: [MQTT, HTTP]
14+
build_type: [Debug, Release]
15+
16+
steps:
17+
- name: Download prebuilt library
18+
run: |
19+
wget https://github.com/TzuHuanTai/Native-WebRTC-Build/releases/download/5790/libwebrtc-arm64.tar.gz
20+
tar -xzf libwebrtc-arm64.tar.gz
21+
sudo mkdir -p /usr/local/include/webrtc
22+
sudo cp -r include/* /usr/local/include/webrtc
23+
sudo cp -r lib/* /usr/local/lib
24+
sudo mkdir -p /usr/local/include/nlohmann
25+
sudo curl -L https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp -o /usr/local/include/nlohmann/json.hpp
26+
27+
- name: Install dependencies
28+
run: |
29+
sudo apt update --fix-missing
30+
sudo apt install -y \
31+
mosquitto-dev \
32+
libboost-program-options-dev \
33+
libavformat-dev \
34+
libavcodec-dev \
35+
libavutil-dev \
36+
libswscale-dev \
37+
libpulse-dev \
38+
libasound2-dev \
39+
libjpeg-dev \
40+
libcamera-dev \
41+
libmosquitto-dev
42+
43+
- name: Check out code
44+
uses: actions/checkout@v4
45+
46+
- name: Build project
47+
run: |
48+
mkdir build && cd build
49+
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DUSE_${{ matrix.signaling }}_SIGNALING=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
50+
make -j$(nproc)
51+
52+
- name: Zip binary
53+
id: zip-binary
54+
run: |
55+
cd build
56+
if [ "${{ matrix.build_type }}" == "Release" ]; then
57+
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_ubuntu-24.04-arm64.tar.gz"
58+
else
59+
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_ubuntu-24.04-arm64_debug.tar.gz"
60+
fi
61+
tar -czvf $FILENAME pi_webrtc
62+
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
63+
64+
- name: Upload to GitHub
65+
uses: softprops/action-gh-release@v2
66+
with:
67+
files: build/${{ steps.zip-binary.outputs.filename }}

.github/workflows/docker_build.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: Build in Docker
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
prepare-env:
10+
runs-on: ubuntu-24.04-arm
11+
outputs:
12+
raspios_version: ${{ steps.os_version.outputs.name }}
13+
steps:
14+
- name: Extract OS Version
15+
id: os_version
16+
run: |
17+
FILE_URL=$(curl -sI https://downloads.raspberrypi.org/raspios_lite_arm64_latest | grep -i '^location:' | awk '{print $2}' | tr -d '\r')
18+
FILENAME=$(basename $FILE_URL)
19+
OS_NAME=$(echo $FILENAME | grep -oP 'raspios-[a-z]+-arm64')
20+
echo "name=$OS_NAME" >> $GITHUB_OUTPUT
21+
22+
- name: Download and Prepare Raspberry Pi OS Image
23+
run: |
24+
wget -q https://downloads.raspberrypi.org/raspios_lite_arm64_latest -O rpi-os.img.xz
25+
xz -d rpi-os.img.xz
26+
sudo mkdir boot
27+
sudo mount -o loop,offset=541065216 rpi-os.img boot
28+
sudo tar -C boot -cf rpi-rootfs.tar .
29+
docker import rpi-rootfs.tar rpi-docker-image
30+
sudo umount boot
31+
32+
- name: Install dependencies
33+
run: |
34+
docker run --name rpi-container -v ${{ github.workspace }}:/app rpi-docker-image /usr/bin/bash -c "
35+
apt update --fix-missing &&
36+
apt install -y \
37+
wget \
38+
curl \
39+
cmake \
40+
clang \
41+
build-essential \
42+
mosquitto-dev \
43+
libboost-program-options-dev \
44+
libavformat-dev \
45+
libavcodec-dev \
46+
libavutil-dev \
47+
libswscale-dev \
48+
libpulse-dev \
49+
libasound2-dev \
50+
libjpeg-dev \
51+
libcamera-dev \
52+
libmosquitto-dev &&
53+
cd /app &&
54+
wget -q https://github.com/TzuHuanTai/Native-WebRTC-Build/releases/download/5790/libwebrtc-arm64.tar.gz &&
55+
tar -xzf libwebrtc-arm64.tar.gz &&
56+
mkdir -p /usr/local/include/webrtc &&
57+
cp -r include/* /usr/local/include/webrtc &&
58+
cp -r lib/* /usr/local/lib &&
59+
mkdir -p /usr/local/include/nlohmann &&
60+
curl -L https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp -o /usr/local/include/nlohmann/json.hpp
61+
"
62+
63+
- name: Commit Docker Image
64+
run: |
65+
docker commit rpi-container rpi-docker-env
66+
docker rm rpi-container
67+
68+
- name: Save Docker image
69+
run: docker save rpi-docker-env -o rpi-docker-env.tar
70+
71+
- name: Cache Docker Image
72+
uses: actions/cache@v4
73+
with:
74+
path: rpi-docker-env.tar
75+
key: rpi-docker-env-${{ runner.os }}-${{ hashFiles('**/Dockerfile', '.github/workflows/**') }}
76+
restore-keys: |
77+
rpi-docker-env-${{ runner.os }}-
78+
79+
build:
80+
runs-on: ubuntu-24.04-arm
81+
needs: prepare-env
82+
strategy:
83+
matrix:
84+
signaling: [MQTT, HTTP]
85+
build_type: [Debug, Release]
86+
87+
steps:
88+
- name: Checkout code
89+
uses: actions/checkout@v4
90+
91+
- name: Restore Docker Image from Cache
92+
uses: actions/cache@v4
93+
with:
94+
path: rpi-docker-env.tar
95+
key: rpi-docker-env-${{ runner.os }}-${{ hashFiles('**/Dockerfile', '.github/workflows/**') }}
96+
restore-keys: |
97+
rpi-docker-env-${{ runner.os }}-
98+
99+
- name: Load Docker Image
100+
run: docker load -i rpi-docker-env.tar
101+
102+
- name: Build inside Docker
103+
run: |
104+
docker run --rm -v ${{ github.workspace }}:/app rpi-docker-env /usr/bin/bash -c "
105+
cd /app &&
106+
mkdir -p build &&
107+
cd build &&
108+
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DUSE_${{ matrix.signaling }}_SIGNALING=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} &&
109+
make -j$(nproc)
110+
"
111+
112+
- name: Zip binary
113+
id: zip-binary
114+
run: |
115+
cd build
116+
if [ "${{ matrix.build_type }}" == "Release" ]; then
117+
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_${{ needs.prepare-env.outputs.raspios_version }}.tar.gz"
118+
else
119+
FILENAME="pi_webrtc-${{ github.ref_name }}_${{ matrix.signaling }}_${{ needs.prepare-env.outputs.raspios_version }}_debug.tar.gz"
120+
fi
121+
sudo tar -czvf $FILENAME pi_webrtc
122+
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
123+
124+
- name: Upload to GitHub
125+
uses: softprops/action-gh-release@v2
126+
with:
127+
files: build/${{ steps.zip-binary.outputs.filename }}

.github/workflows/qemu_build.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Build Raspberry Pi OS App in QEMU
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v**-qemu'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-24.04-arm
11+
12+
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 install -y \
78+
wget \
79+
curl \
80+
cmake \
81+
clang \
82+
build-essential \
83+
mosquitto-dev \
84+
libboost-program-options-dev \
85+
libavformat-dev \
86+
libavcodec-dev \
87+
libavutil-dev \
88+
libswscale-dev \
89+
libpulse-dev \
90+
libasound2-dev \
91+
libjpeg-dev \
92+
libcamera-dev \
93+
libmosquitto-dev
94+
"
95+
96+
- name: Install Additional libwebrtc and json.hpp in QEMU
97+
run: |
98+
sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\
99+
wget https://github.com/TzuHuanTai/Native-WebRTC-Build/releases/download/5790/libwebrtc-arm64.tar.gz &&
100+
tar -xzf libwebrtc-arm64.tar.gz &&
101+
sudo mkdir -p /usr/local/include/webrtc &&
102+
sudo mv include/* /usr/local/include/webrtc &&
103+
sudo mv lib/* /usr/local/lib &&
104+
sudo mkdir -p /usr/local/include/nlohmann &&
105+
sudo curl -L https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp -o /usr/local/include/nlohmann/json.hpp
106+
"
107+
108+
- name: Checkout code
109+
uses: actions/checkout@v4
110+
111+
- name: Build project inside Raspberry Pi OS
112+
run: |
113+
sshpass -p "raspberry" scp -P 5555 -r . pi@localhost:~/project
114+
sshpass -p "raspberry" ssh -o StrictHostKeyChecking=no -p 5555 pi@localhost "\
115+
ls ~/project && \
116+
cd project && \
117+
mkdir build && \
118+
cd build && \
119+
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DUSE_MQTT_SIGNALING=ON -DCMAKE_BUILD_TYPE=Release && \
120+
make -j$(nproc) && \
121+
tar -czvf pi_webrtc-${{ github.ref_name }}_MQTT_Release.tar.gz pi_webrtc
122+
"

0 commit comments

Comments
 (0)