From 028a45d19f4b8e3515fbe36c59cfb463b021be79 Mon Sep 17 00:00:00 2001 From: Florian Wilhelm <2292245+fwilhe@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:13:40 +0000 Subject: [PATCH] Build multi-arch images (amd64, arm64), upload images --- .github/workflows/build.yml | 16 ------- .github/workflows/image.yml | 29 ++++++++++++ .github/workflows/repo.yml | 28 +++++++++++ features/ostree/makeRepo.sh | 28 ----------- features/{ostree => ostreeImage}/file.exclude | 0 features/{ostree => ostreeImage}/fstab | 0 .../{ostree => ostreeImage}/image.ostree.raw | 33 +++++++------ features/{ostree => ostreeImage}/info.yaml | 0 features/{ostree => ostreeRepo}/exec.config | 0 features/{ostree => ostreeRepo}/exec.late | 0 features/{ostree => ostreeRepo}/exec.post | 0 features/ostreeRepo/file.exclude | 1 + .../serial-getty@.service.d/autologin.conf | 0 .../any.conf | 0 .../file.include/network/99-default.network | 0 .../usr/lib/tmpfiles.d/ostree.conf | 0 features/ostreeRepo/fstab | 3 ++ features/ostreeRepo/image.ostreeRepo.tar.gz | 47 +++++++++++++++++++ features/ostreeRepo/info.yaml | 2 + features/{ostree => ostreeRepo}/pkg.include | 0 20 files changed, 128 insertions(+), 59 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/image.yml create mode 100644 .github/workflows/repo.yml delete mode 100755 features/ostree/makeRepo.sh rename features/{ostree => ostreeImage}/file.exclude (100%) rename features/{ostree => ostreeImage}/fstab (100%) rename features/{ostree => ostreeImage}/image.ostree.raw (68%) rename features/{ostree => ostreeImage}/info.yaml (100%) rename features/{ostree => ostreeRepo}/exec.config (100%) rename features/{ostree => ostreeRepo}/exec.late (100%) rename features/{ostree => ostreeRepo}/exec.post (100%) create mode 100644 features/ostreeRepo/file.exclude rename features/{ostree => ostreeRepo}/file.include/etc/systemd/system/serial-getty@.service.d/autologin.conf (100%) rename features/{ostree => ostreeRepo}/file.include/etc/systemd/system/systemd-networkd-wait-online.service.d/any.conf (100%) rename features/{ostree => ostreeRepo}/file.include/network/99-default.network (100%) rename features/{ostree => ostreeRepo}/file.include/usr/lib/tmpfiles.d/ostree.conf (100%) create mode 100644 features/ostreeRepo/fstab create mode 100755 features/ostreeRepo/image.ostreeRepo.tar.gz create mode 100644 features/ostreeRepo/info.yaml rename features/{ostree => ostreeRepo}/pkg.include (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 46a098c..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: CI - -on: - push: - branches: [ "main", "ostree" ] - pull_request: - branches: [ "main" ] - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Build the image - run: ./build ostree diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml new file mode 100644 index 0000000..79c932e --- /dev/null +++ b/.github/workflows/image.yml @@ -0,0 +1,29 @@ +name: CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + workflow_dispatch: + +jobs: + image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Build the repo + run: ./build ostreeImage-amd64 ostreeImage-arm64 + - name: Upload amd64 + uses: actions/upload-artifact@v3 + with: + name: ostree-amd64-trixie-image + path: .build/*amd64-trixie-*raw + - name: Upload arm64 + uses: actions/upload-artifact@v3 + with: + name: ostree-arm64-trixie-image + path: .build/*arm64-trixie-*raw + diff --git a/.github/workflows/repo.yml b/.github/workflows/repo.yml new file mode 100644 index 0000000..55df566 --- /dev/null +++ b/.github/workflows/repo.yml @@ -0,0 +1,28 @@ +name: CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + workflow_dispatch: + +jobs: + repo: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Build the repo + run: ./build ostreeRepo-amd64 ostreeRepo-arm64 + - name: Upload amd64 + uses: actions/upload-artifact@v3 + with: + name: ostree-amd64-trixie-repo + path: .build/ostreeRepo-amd64-trixie-*.ostreeRepo.tar.gz + - name: Upload arm64 + uses: actions/upload-artifact@v3 + with: + name: ostree-arm64-trixie-repo + path: .build/ostreeRepo-arm64-trixie-*.ostreeRepo.tar.gz diff --git a/features/ostree/makeRepo.sh b/features/ostree/makeRepo.sh deleted file mode 100755 index 5208136..0000000 --- a/features/ostree/makeRepo.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -set -eufo pipefail - -# Call this script from the root of the repo as: -# ./features/ostree/makeRepo.sh .build/ostree-arm64-trixie*.tar -# Can be served with this command from the root of the repo: -# docker run --name ostree-repo -v $PWD/.build/ostree-repo:/usr/share/nginx/html:ro -p 8000:80 nginx - -OSTREE_REPO=.build/ostree-repo -OSTREE_ROOTFS=.build/ostree-rootfs -# fixme: don't hardcode architecture -OSTREE_REF=debian/testing/arm64 - -if [ $# -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -ROOTFS_TARBALL=$1 - -mkdir -p $OSTREE_ROOTFS -mkdir -p $OSTREE_REPO -tar xf "$ROOTFS_TARBALL" --directory=$OSTREE_ROOTFS -date > $OSTREE_ROOTFS/timestamp -mv $OSTREE_ROOTFS/etc $OSTREE_ROOTFS/usr/etc -ostree init --mode=archive --repo=$OSTREE_REPO -ostree commit --repo=$OSTREE_REPO --branch $OSTREE_REF --skip-if-unchanged -s "Debian testing build $(date)" $OSTREE_ROOTFS diff --git a/features/ostree/file.exclude b/features/ostreeImage/file.exclude similarity index 100% rename from features/ostree/file.exclude rename to features/ostreeImage/file.exclude diff --git a/features/ostree/fstab b/features/ostreeImage/fstab similarity index 100% rename from features/ostree/fstab rename to features/ostreeImage/fstab diff --git a/features/ostree/image.ostree.raw b/features/ostreeImage/image.ostree.raw similarity index 68% rename from features/ostree/image.ostree.raw rename to features/ostreeImage/image.ostree.raw index bf14c44..b6b7499 100755 --- a/features/ostree/image.ostree.raw +++ b/features/ostreeImage/image.ostree.raw @@ -10,6 +10,8 @@ mount -t tmpfs tmpfs "$rootfs_work" MYROOT="$(mktemp -d)" mount -t tmpfs tmpfs "$MYROOT" mkdir -p "$MYROOT"/sysroot +mkdir -p "$MYROOT"/sysroot/ostree/deploy +mkdir -p "$MYROOT"/sysroot/ostree/deploy/debian/var OSTREE_SYSROOT="$MYROOT/sysroot" OSTREE_REPO=$OSTREE_SYSROOT/ostree/repo OSTREE_REF="debian/testing/$BUILDER_ARCH" @@ -19,27 +21,28 @@ output="$2" tar xf "$rootfs" -C "$rootfs_work" -mv "$rootfs_work"/etc "$rootfs_work"/usr/etc mkdir -p $OSTREE_REPO -ostree init --mode=archive --repo=$OSTREE_REPO -ostree admin init-fs --modern $OSTREE_SYSROOT -ostree admin os-init --sysroot=$OSTREE_SYSROOT gardenlinux -ostree config --repo=$OSTREE_REPO set sysroot.bootloader none -ostree commit --repo=$OSTREE_REPO --branch $OSTREE_REF --skip-if-unchanged -s "Debian testing build $(date --utc +%Y-%m-%dT%H:%M:%S%Z)" "$rootfs_work" -ostree remote --repo=$OSTREE_REPO add --no-gpg-verify --no-sign-verify origin http://172.16.48.131:8000 $OSTREE_REF # fixme: hardcoded ip address +mkdir -p $OSTREE_SYSROOT +download="$(mktemp -d)" +pushd $download +curl --remote-name http://ostree.gardenlinux.io/debian-testing-$BUILDER_ARCH.tar.gz +tar xf debian-testing-$BUILDER_ARCH.tar.gz --directory $OSTREE_REPO +ls -l $OSTREE_REPO +popd +rm -rf $download ostree admin deploy --karg=root=LABEL=ROOT --karg-append=rw --karg-append=efi=runtime --karg-append=systemd.journald.forward_to_console=1 --sysroot=$OSTREE_SYSROOT --os=gardenlinux $OSTREE_REF -boot_hash=`ls "$OSTREE_SYSROOT"/ostree/boot.1.1/gardenlinux/` -mkdir -p "$OSTREE_SYSROOT"/ostree/boot.1.1/gardenlinux/$boot_hash/0/sysroot +boot_hash=`ls "$OSTREE_SYSROOT"/ostree/boot.1.1/debian/` +mkdir -p "$OSTREE_SYSROOT"/ostree/boot.1.1/debian/$boot_hash/0/sysroot -mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/home -mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/home/user -mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/roothome -mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/opt -mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/srv +mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/home +mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/home/user +mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/roothome +mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/opt +mkdir -p "$OSTREE_SYSROOT"/ostree/deploy/debian/var/srv -chown 1000:1000 "$OSTREE_SYSROOT"/ostree/deploy/gardenlinux/var/home/user +chown 1000:1000 "$OSTREE_SYSROOT"/ostree/deploy/debian/var/home/user # Build disk image, this is hacky as of now, needs rework # Setup bootloader diff --git a/features/ostree/info.yaml b/features/ostreeImage/info.yaml similarity index 100% rename from features/ostree/info.yaml rename to features/ostreeImage/info.yaml diff --git a/features/ostree/exec.config b/features/ostreeRepo/exec.config similarity index 100% rename from features/ostree/exec.config rename to features/ostreeRepo/exec.config diff --git a/features/ostree/exec.late b/features/ostreeRepo/exec.late similarity index 100% rename from features/ostree/exec.late rename to features/ostreeRepo/exec.late diff --git a/features/ostree/exec.post b/features/ostreeRepo/exec.post similarity index 100% rename from features/ostree/exec.post rename to features/ostreeRepo/exec.post diff --git a/features/ostreeRepo/file.exclude b/features/ostreeRepo/file.exclude new file mode 100644 index 0000000..2e0f9df --- /dev/null +++ b/features/ostreeRepo/file.exclude @@ -0,0 +1 @@ +/boot/efi/loader/random-seed diff --git a/features/ostree/file.include/etc/systemd/system/serial-getty@.service.d/autologin.conf b/features/ostreeRepo/file.include/etc/systemd/system/serial-getty@.service.d/autologin.conf similarity index 100% rename from features/ostree/file.include/etc/systemd/system/serial-getty@.service.d/autologin.conf rename to features/ostreeRepo/file.include/etc/systemd/system/serial-getty@.service.d/autologin.conf diff --git a/features/ostree/file.include/etc/systemd/system/systemd-networkd-wait-online.service.d/any.conf b/features/ostreeRepo/file.include/etc/systemd/system/systemd-networkd-wait-online.service.d/any.conf similarity index 100% rename from features/ostree/file.include/etc/systemd/system/systemd-networkd-wait-online.service.d/any.conf rename to features/ostreeRepo/file.include/etc/systemd/system/systemd-networkd-wait-online.service.d/any.conf diff --git a/features/ostree/file.include/network/99-default.network b/features/ostreeRepo/file.include/network/99-default.network similarity index 100% rename from features/ostree/file.include/network/99-default.network rename to features/ostreeRepo/file.include/network/99-default.network diff --git a/features/ostree/file.include/usr/lib/tmpfiles.d/ostree.conf b/features/ostreeRepo/file.include/usr/lib/tmpfiles.d/ostree.conf similarity index 100% rename from features/ostree/file.include/usr/lib/tmpfiles.d/ostree.conf rename to features/ostreeRepo/file.include/usr/lib/tmpfiles.d/ostree.conf diff --git a/features/ostreeRepo/fstab b/features/ostreeRepo/fstab new file mode 100644 index 0000000..bcb6fda --- /dev/null +++ b/features/ostreeRepo/fstab @@ -0,0 +1,3 @@ +# +LABEL=EFI /boot/efi vfat umask=0077 type=uefi,size=1G +LABEL=ROOT / ext4 rw,prjquota,discard diff --git a/features/ostreeRepo/image.ostreeRepo.tar.gz b/features/ostreeRepo/image.ostreeRepo.tar.gz new file mode 100755 index 0000000..79bb4bc --- /dev/null +++ b/features/ostreeRepo/image.ostreeRepo.tar.gz @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +export PATH="/builder/image.d:$PATH" + +rootfs_work="$(mktemp -d)" +mount -t tmpfs tmpfs "$rootfs_work" + +MYROOT="$(mktemp -d)" +mount -t tmpfs tmpfs "$MYROOT" +mkdir -p "$MYROOT"/sysroot +OSTREE_SYSROOT="$MYROOT/sysroot" +OSTREE_REPO=$OSTREE_SYSROOT/ostree/repo +OSTREE_REF="debian/testing/$BUILDER_ARCH" + +rootfs="$1" +output="$2" + +tar xf "$rootfs" -C "$rootfs_work" + +mv "$rootfs_work"/etc "$rootfs_work"/usr/etc + +mkdir -p $OSTREE_REPO + +if curl --head --silent --fail http://ostree.gardenlinux.io/debian-testing-$BUILDER_ARCH.tar.gz 2> /dev/null; + then + echo "Using http://ostree.gardenlinux.io/debian-testing-$BUILDER_ARCH.tar.gz" + mkdir -p $OSTREE_REPO + download="$(mktemp -d)" + pushd $download + curl --remote-name http://ostree.gardenlinux.io/debian-testing-$BUILDER_ARCH.tar.gz + tar xf debian-testing-$BUILDER_ARCH.tar.gz --directory $OSTREE_REPO + popd + rm -rf $download + else + echo "Coud not download http://ostree.gardenlinux.io/debian-testing-$BUILDER_ARCH.tar.gz, building new repo" + ostree init --mode=archive --repo=$OSTREE_REPO + ostree admin init-fs --modern $OSTREE_SYSROOT + ostree admin os-init --sysroot=$OSTREE_SYSROOT debian + ostree config --repo=$OSTREE_REPO set sysroot.bootloader none + ostree remote --repo=$OSTREE_REPO add --no-gpg-verify --no-sign-verify origin http://ostree.gardenlinux.io/debian-testing-$BUILDER_ARCH $OSTREE_REF +fi + +ostree commit --repo=$OSTREE_REPO --branch $OSTREE_REF --skip-if-unchanged -s "Debian testing build $(date --utc +%Y-%m-%dT%H:%M%Z)" "$rootfs_work" + +tar --directory $OSTREE_REPO --create --mtime="@$BUILDER_TIMESTAMP" --sort name --numeric-owner --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime . | gzip > "$output" diff --git a/features/ostreeRepo/info.yaml b/features/ostreeRepo/info.yaml new file mode 100644 index 0000000..6bc5f79 --- /dev/null +++ b/features/ostreeRepo/info.yaml @@ -0,0 +1,2 @@ +description: 'image-based system using OSTree' +type: platform diff --git a/features/ostree/pkg.include b/features/ostreeRepo/pkg.include similarity index 100% rename from features/ostree/pkg.include rename to features/ostreeRepo/pkg.include