From 1a7016a930e04c31a0a91f0257ca5c19edc7e53e Mon Sep 17 00:00:00 2001 From: Tobias Manske Date: Mon, 27 Mar 2023 13:59:50 +0200 Subject: [PATCH] Build missing packages and -git packages Add locking Fix style Optionally disable git rebuild --- .drone.yml | 1 - entrypoint.sh | 95 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 35 deletions(-) diff --git a/.drone.yml b/.drone.yml index aef7f43..14c35be 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,7 +6,6 @@ name: Build ArchLinux packages! trigger: event: include: - - push - custom - cron - tag diff --git a/entrypoint.sh b/entrypoint.sh index 89de4ce..d81a36f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,9 @@ -#!/bin/sh -set -u -set -e +#!/bin/bash +set -eEu set -v +PIPELINE_ID=$RANDOM +echo ${PIPELINE_ID} sudo pacman-key --init @@ -10,77 +11,103 @@ sudo pacman-key --init ## Needed so pacman doesnt complain. repo-add "/repo/${AUR_REPO_NAME}.db.tar.xz" -sudo pacman -Syu --noconfirm minio-client pacman-contrib +sudo pacman -Syu --noconfirm minio-client pacman-contrib &>/dev/null # Setup tooling -mcli alias set s3 https://s3.tobiasmanske.de $REPO_ACCESS_KEY $REPO_SECRET_KEY -mcli cp s3/repo/x86_64/rad4day.db.tar.xz /repo/rad4day.db.tar.xz -mcli cp s3/repo/x86_64/rad4day.files.tar.xz /repo/rad4day.files.tar.xz +mcli alias set s3 https://s3.tobiasmanske.de "${REPO_ACCESS_KEY}" "${REPO_SECRET_KEY}" -mcli cp s3/repo/x86_64/rad4day.db.tar.xz.sig /repo/rad4day.db.tar.xz.sig -mcli cp s3/repo/x86_64/rad4day.files.tar.xz.sig /repo/rad4day.files.tar.xz.sig +# LOCK +LOCK="" -if ! (aur repo > /dev/null 2>&1); then - printf "Aur repo not initialized, initializing /repo...\n" - repo-add "/repo/${AUR_REPO_NAME}.db.tar.xz" +while [[ "${LOCK}" != "${PIPELINE_ID}" ]]; do + LOCK=$(mcli cat s3/repo/LOCK) + if [[ "${LOCK}" == "FREE" ]]; then + echo $PIPELINE_ID | mcli pipe s3/repo/LOCK + fi + echo "Waiting for lock with id $PIPELINE_ID..." + sleep $((RANDOM % 10)) + +done + +unlock() { + if [[ "${LOCK}" == "${PIPELINE_ID}" ]]; then + echo "FREE" | mcli pipe s3/repo/LOCK + fi + +} + +trap unlock EXIT INT TERM + +echo "Pulling Repository" +( + mcli mirror --overwrite s3/repo/x86_64 /repo &>/dev/null + rm "/repo/${AUR_REPO_NAME}.db" + rm "/repo/${AUR_REPO_NAME}.db.sig" + rm "/repo/${AUR_REPO_NAME}.files" + # rm "/repo/${AUR_REPO_NAME}.files.sig" + ln -sf "/repo/${AUR_REPO_NAME}.db.tar.xz" "/repo/${AUR_REPO_NAME}.db" + ln -sf "/repo/${AUR_REPO_NAME}.files.tar.xz" "/repo/${AUR_REPO_NAME}.files" + ln -sf "/repo/${AUR_REPO_NAME}.db.tar.xz.sig" "/repo/${AUR_REPO_NAME}.db.sig" + ln -sf "/repo/${AUR_REPO_NAME}.files.tar.xz.sig" "/repo/${AUR_REPO_NAME}.files.sig" +) &>/dev/null + +if ! (aur repo >/dev/null 2>&1); then + printf "Aur repo not initialized, initializing /repo...\n" + repo-add "/repo/${AUR_REPO_NAME}.db.tar.xz" fi - # Keyring Signing Key sudo pacman-key --add trustroot.asc gpg --import --batch trustroot.asc sudo pacman-key --lsign 10BE06BC275CE0E17373B368F67996C486D1B56B - -# repoctl conf new "$(readlink -f \"/repo/${AUR_REPO_NAME}.db.tar.xz\")" - # Setup signing -echo "$BUILD_GPG_KEY" | base64 -d | gpg --import --batch +echo "${BUILD_GPG_KEY:-}" | base64 -d | gpg --import --batch echo "C3FE87CFB8F8D503AE03EC1C033E7F3DC71FE89E:6:" | gpg --import-ownertrust --batch -sudo pacman --noconfirm -Sy archlinux-keyring -sudo pacman --noconfirm -Syu +sudo pacman --noconfirm -Syu archlinux-keyring &>/dev/null -git clone --recursive https://git.tobiasmanske.de/archlinux-repo/package_sources.git packages +git clone --recursive https://git.tobiasmanske.de/archlinux-repo/package_sources.git packages &>/dev/null cd packages touch buildqueue ## OBTAIN PACKAGES TO BUILD -git submodule update --remote --merge # Make sure we are up to date if something is linked as a submodule +git submodule update --remote --merge &>/dev/null # Make sure we are up to date if something is linked as a submodule # find . -name PKGBUILD -execdir sh -c 'makepkg --printsrcinfo > .SRCINFO' \; # Obtain version of downloaded packages -find . -iname PKGBUILD -exec dirname {} \; | aur srcver --no-prepare - > vcs +find . -iname PKGBUILD -exec dirname {} \; | aur srcver --no-prepare - >vcs # Rebuild all git packages -find . -iname "*-git$" -type d | tee -a buildqueue +if [ ! -z "$NO_GIT_REBUILD" ]; then + cut -f1 vcs | grep -e "-git$" | tee -a buildqueue +fi # add all outdated packages to the build queue aur repo --list | aur vercmp -q -p vcs | tee -a buildqueue +# Build missing packages +comm -23 <(cut -f1 vcs | sort) <(pacman -Slq "${AUR_REPO_NAME}" | sort) | tee -a buildqueue + # Build all packages defined in buildqueue while read -r i; do - cat "$i"/.SRCINFO -done < buildqueue | aur graph | tsort | tac > queue + cat "$i"/.SRCINFO +done queue echo echo QUEUE echo cat queue +if wc -l queue | grep -q "^0 "; then + echo "Nothing to build, exiting." + exit 0 +fi + ## BUILD aur build -S --noconfirm -a queue --no-sync --margs -s -# build all packages defined in our repo -#paclist custom | awk '{print $1}' | xargs -r aur sync --noconfirm -aur sync -u -S --noview --noconfirm - - ## Upload to repo mcli mirror --overwrite /repo s3/repo/x86_64 - - -exec "$@" -