From b5f39a4b6275fc6132c32397d0bbd4f7e22ed80f Mon Sep 17 00:00:00 2001 From: Cameron Clough Date: Sun, 14 Jul 2024 19:00:59 +0100 Subject: [PATCH] Build kernel in CI (#231) * build workflow * submodule example * just agnos-kernel-sdm845 * filter * ubuntu20 * unecessary * cancel in progress * upload * try ccache... * test ccache * cache out dir * v4 * cleanup * ccache again... * skip system for now * try this * allow override CC * improve cache hit * fix * test if this matters * don't append timestamp * try again * empty * doesn't help * test * Revert "test" This reverts commit e3a7db8bd511b006a169c60ce0d0c18b8ec437a2. * test * Revert "test" This reverts commit 42e9ebaaac4cc8a597b5cee202bd9e0b5b1a14c0. * build system again * more space * longer timeout... * CI froze * use namespace labs remote builder * permissions * try again * nscloud * permissions * ubuntu 20 * wip * upload kernel modules * build_kernel arch fix Co-authored-by: Andrei Radulescu * lfs clone * . * namespace doesn't support git filter * no perms * fix typo * namespace ubuntu2004 doesn't have python2... * update name * oh * no wget * fix arm64 check * mount container Co-authored-by: Andrei Radulescu * missing deps * switch to pyenv-action which caches * update nscloud-checkout-action * reduce timeout * run network stuff in container * test cache * cache kernel: does this work? * try again * test kernel cache * use github cache action * test kernel cache * try actions/checkout * kernel: cache intermediate build outputs * name * test cache 1 * don't skip kernel build * always set arch to arm64 * just kernel * fix that --------- Co-authored-by: Andrei Radulescu Co-authored-by: Adeeb Shihadeh --- .github/workflows/build.yaml | 70 ++++++++++++++++++++++++++++++++++++ build_kernel.sh | 13 ++++--- build_system.sh | 33 +++++++++-------- 3 files changed, 97 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..77328e3 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,70 @@ +name: build + +on: + push: + branches: [ master ] + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.run_id || github.head_ref || github.ref }}-${{ github.workflow }}-${{ github.event_name }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + build: + name: build kernel #and system + runs-on: namespace-profile-arm64-8x16-2004-caching + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + with: + lfs: true + + - name: get kernel submodule ref + id: kernel-submodule + run: echo "ref=$(git ls-tree HEAD | awk '$4 == "agnos-kernel-sdm845"' | awk '{print $3}')" >> "$GITHUB_OUTPUT" + + - name: Checkout agnos-kernel-sdm845 + uses: actions/checkout@v4 + with: + repository: commaai/agnos-kernel-sdm845 + ref: ${{ steps.kernel-submodule.outputs.ref }} + path: agnos-kernel-sdm845 + + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y bc img2simg + + - name: Install python2 + uses: gabrielfalcao/pyenv-action@2f49ca7587f9d0663d13f1147b78d3361417eaf7 + with: + default: '2.7.18' + + - name: Cache kernel build + uses: actions/cache@v4 + id: cache-kernel + with: + key: kernel-${{ steps.kernel-submodule.outputs.ref }} + path: | + agnos-kernel-sdm845/out + restore-keys: kernel- + + - name: Build kernel + run: ./build_kernel.sh + + - uses: actions/upload-artifact@v4 + with: + name: boot.img + path: output/boot.img + - uses: actions/upload-artifact@v4 + with: + name: kernel-modules + path: output/*.ko + + #- run: ./build_system.sh + #- uses: actions/upload-artifact@v4 + # with: + # name: system.img + # path: output/system.img diff --git a/build_kernel.sh b/build_kernel.sh index bb70289..6df7b85 100755 --- a/build_kernel.sh +++ b/build_kernel.sh @@ -16,13 +16,16 @@ if git submodule status --cached agnos-kernel-sdm845/ | grep "^-"; then fi cd agnos-kernel-sdm845 -$DIR/tools/extract_tools.sh - # Build parameters +ARCH=$(uname -m) +if [ "$ARCH" != "arm64" ] && [ "$ARCH" != "aarch64" ]; then + export CROSS_COMPILE=$TOOLS/aarch64-linux-gnu-gcc/bin/aarch64-linux-gnu- + export CC=$TOOLS/aarch64-linux-gnu-gcc/bin/aarch64-linux-gnu-gcc + export LD=$TOOLS/aarch64-linux-gnu-gcc/bin/aarch64-linux-gnu-ld.bfd + + $DIR/tools/extract_tools.sh +fi export ARCH=arm64 -export CROSS_COMPILE=$TOOLS/aarch64-linux-gnu-gcc/bin/aarch64-linux-gnu- -export CC=$TOOLS/aarch64-linux-gnu-gcc/bin/aarch64-linux-gnu-gcc -export LD=$TOOLS/aarch64-linux-gnu-gcc/bin/aarch64-linux-gnu-ld.bfd # these do anything? export KCFLAGS="-w" diff --git a/build_system.sh b/build_system.sh index 0244870..0badd50 100755 --- a/build_system.sh +++ b/build_system.sh @@ -48,45 +48,50 @@ echo "Building image" export DOCKER_CLI_EXPERIMENTAL=enabled docker build -f Dockerfile.agnos -t agnos-builder $DIR +# Setup mount container +MOUNT_CONTAINER_ID=$(docker run -d --privileged --volume $BUILD_DIR:$BUILD_DIR ubuntu:latest sleep infinity) + # Create filesystem ext4 image echo "Creating empty filesystem" -fallocate -l $ROOTFS_IMAGE_SIZE $ROOTFS_IMAGE -mkfs.ext4 $ROOTFS_IMAGE > /dev/null +docker exec $MOUNT_CONTAINER_ID fallocate -l $ROOTFS_IMAGE_SIZE $ROOTFS_IMAGE +docker exec $MOUNT_CONTAINER_ID mkfs.ext4 $ROOTFS_IMAGE > /dev/null # Mount filesystem echo "Mounting empty filesystem" -mkdir -p $ROOTFS_DIR -sudo umount -l $ROOTFS_DIR > /dev/null || true -sudo mount $ROOTFS_IMAGE $ROOTFS_DIR +docker exec $MOUNT_CONTAINER_ID mkdir -p $ROOTFS_DIR +docker exec $MOUNT_CONTAINER_ID mount -o loop $ROOTFS_IMAGE $ROOTFS_DIR # Extract image echo "Extracting docker image" CONTAINER_ID=$(docker container create --entrypoint /bin/bash agnos-builder:latest) docker container export -o $BUILD_DIR/filesystem.tar $CONTAINER_ID docker container rm $CONTAINER_ID > /dev/null +docker exec $MOUNT_CONTAINER_ID tar -xf $BUILD_DIR/filesystem.tar -C $ROOTFS_DIR > /dev/null + cd $ROOTFS_DIR -sudo tar -xf $BUILD_DIR/filesystem.tar > /dev/null # Add hostname and hosts. This cannot be done in the docker container... echo "Setting network stuff" HOST=comma -sudo bash -c "ln -sf /proc/sys/kernel/hostname etc/hostname" -sudo bash -c "echo \"127.0.0.1 localhost.localdomain localhost\" > etc/hosts" -sudo bash -c "echo \"127.0.0.1 $HOST\" >> etc/hosts" +docker exec -w $ROOTFS_DIR $MOUNT_CONTAINER_ID bash -c "\ +ln -sf /proc/sys/kernel/hostname etc/hostname; \ +echo \"127.0.0.1 localhost.localdomain localhost\" > etc/hosts \ +echo \"127.0.0.1 $HOST\" >> etc/hosts" # Fix resolv config -sudo bash -c "ln -sf /run/systemd/resolve/stub-resolv.conf etc/resolv.conf" +docker exec -w $ROOTFS_DIR $MOUNT_CONTAINER_ID bash -c "ln -sf /run/systemd/resolve/stub-resolv.conf etc/resolv.conf" # Write build info DATETIME=$(date '+%Y-%m-%dT%H:%M:%S') GIT_HASH=$(git --git-dir=$DIR/.git rev-parse HEAD) -sudo bash -c "printf \"$GIT_HASH\n$DATETIME\" > BUILD" - -cd $DIR +docker exec -w $ROOTFS_DIR $MOUNT_CONTAINER_ID bash -c "printf \"$GIT_HASH\n$DATETIME\" > BUILD" # Unmount image echo "Unmount filesystem" -sudo umount -l $ROOTFS_DIR +docker exec $MOUNT_CONTAINER_ID umount -l $ROOTFS_DIR +docker rm -f $MOUNT_CONTAINER_ID > /dev/null + +cd $DIR # Sparsify echo "Sparsify image"