From 878411ddb5b1951e019c0277e207852bc0302d1c Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 29 Nov 2013 13:12:03 +0000 Subject: main/aports-build: moved from testing --- main/aports-build/APKBUILD | 50 ++++++++ main/aports-build/aports-build | 182 +++++++++++++++++++++++++++++ main/aports-build/aports-build.confd | 10 ++ main/aports-build/aports-build.initd | 34 ++++++ main/aports-build/aports-build.pre-install | 4 + 5 files changed, 280 insertions(+) create mode 100644 main/aports-build/APKBUILD create mode 100644 main/aports-build/aports-build create mode 100644 main/aports-build/aports-build.confd create mode 100644 main/aports-build/aports-build.initd create mode 100644 main/aports-build/aports-build.pre-install (limited to 'main/aports-build') diff --git a/main/aports-build/APKBUILD b/main/aports-build/APKBUILD new file mode 100644 index 000000000..06b441eae --- /dev/null +++ b/main/aports-build/APKBUILD @@ -0,0 +1,50 @@ +# Maintainer: Natanael Copa +pkgname=aports-build +pkgver=0.1 +pkgrel=1 +pkgdesc="MQTT based build-on-git-push scripts for Alpine Linux" +url="http://alpinelinux.org" +arch="noarch" +license="GPL2" +depends="mosquitto-utils alpine-sdk mqtt-exec" +depends_dev="" +makedepends="$depends_dev mosquitto-dev" +install="$pkgname.pre-install" +subpackages="" + +source="aports-build aports-build.initd aports-build.confd" + +_builddir= +prepare() { + local i + cd "$_builddir" + for i in $source; do + case $i in + *.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;; + esac + done +} + +build() { + cd "$_builddir" +} + +package() { + cd "$_builddir" + install -Dm755 "$srcdir"/aports-build \ + "$pkgdir"/usr/bin/aports-build || return 1 + install -Dm755 "$srcdir"/aports-build.initd \ + "$pkgdir"/etc/init.d/aports-build || return 1 + install -Dm644 "$srcdir"/aports-build.confd \ + "$pkgdir"/etc/conf.d/aports-build || return 1 +} + +md5sums="bfc281f6af37994137b753eb3406b543 aports-build +40ff7be2ad647d22c4c8ebfe1fec8b1b aports-build.initd +cdc49e0ef145de72131972a575f20e7b aports-build.confd" +sha256sums="588dfd07c44c0cd2eef8a47a4b29d370bce6232de7930834a71420cf34f406bb aports-build +e6b228ccc0dcdf7f172ebd3777c5791b96f86a8c96a4df95df2dd3c9051b91fe aports-build.initd +519744cdb4be83e5da1c22d4aa93c7ef97d66e03565e84b710bc21c94b82047e aports-build.confd" +sha512sums="1a632c2c98cedcde47810d743925b99540230ff136d982753818befeddb8260117df2bcfc47fcc34cafa050122cd638c1820e32fa32f9c93871e40dd05a198e3 aports-build +af5cd8e2647f3b9aa03020d5cea996a750b48b2b3a4d208f5ef683538aba3ecada677b9a0071385c85ec66803b8ed055b1d58853ccfe198c1c5beaad99d97d86 aports-build.initd +fbe8ed4b1fbfc979de62302873e99c67bab751a7fcd921c3b23815f535cedb34c717e82b3c223f88e06498a573cbd147a73db7bf5adbb5e1947ac75fcb8edcb4 aports-build.confd" diff --git a/main/aports-build/aports-build b/main/aports-build/aports-build new file mode 100644 index 000000000..187a9a1a3 --- /dev/null +++ b/main/aports-build/aports-build @@ -0,0 +1,182 @@ +#!/bin/sh + +lockfile=/var/run/aports-build/aports-build.pid +pid=$(cat $lockfile 2>/dev/null) + +if [ -n "$pid" ]; then + if [ -d /proc/"$pid" ]; then + # already running + exit 0 + fi +fi +echo $$ > $lockfile || exit 1 + +logurl= +conf=/etc/conf.d/aports-build +. $conf || exit 1 + +if [ -z "$git_branch" ]; then + echo "Please set 'git_branch' in $conf" >&2 + exit 1 +fi + +rel=$upload_release + +if [ -z "$rel" ]; then + case "$git_branch" in + master) rel="edge";; + [0-9]*-stable) rel=v${git_branch%-stable} ;; + esac +fi + +arch=x86 +case "$(uname -m)" in + x86_64) arch=x86_64;; +esac + +aports=${APORTS:-$HOME/aports} +isodir=$HOME/alpine-iso +packages=${REPOSDIR:-$HOME/packages} +repos=${REPOS:-"main testing"} + +: ${upload_prefix:="nl.alpinelinux.org:alpine"} +upload_pkg="$upload_prefix/$rel/" +upload_iso="$upload_prefix/$rel/releases/$arch/" + +: ${ircchannel:="#alpine-devel"} +: ${hostname:=$(hostname)} +: ${mqtt_broker:="msg.alpinelinux.org"} +: ${status_msg:="mosquitto_pub -h $mqtt_broker -t build/$hostname -r -m"} +: ${irc_msg:="mosquitto_pub -h $mqtt_broker -t irc/${ircchannel//#/%} -m"} +: ${logdir:="/var/cache/distfiles/buildlogs"} +: ${logurlprefix:="http://bld1.alpinelinux.org/buildlogs"} + +export ABUILD_LOG_CMD="$status_msg" +log() { + echo "$hostname: $@" + $status_msg "$1" +} + +send_irc() { + #echo "$1" | sircbot-send "$ircchannel" + $irc_msg "$hostname: $1" +} + +# create new_release +new_release() { + local new=$1 + local target="all-release" + if [ "$rel" = "edge" ]; then + target="edge" + fi + cd "$isodir" + echo "$new" > current + rm -rf isotmp.* + sudo apk add --virtual .alpine-release xdelta3 lua + if ! make $target; then + rm current + return 1 + fi + sh mklatest.sh || return 1 + mkdir -p "$upload_iso" + rsync -ruv .latest.txt *"$new"* "$upload_iso" || return 1 + sudo apk del .alpine-release + mv current previous + return 0 +} + +cd $aports || return 1 +[ -z "$repos" ] && return 1 + +# parse opts +while getopts "fu:" opt; do + case $opt in + 'f') force=true;; + 'u') logurl=" $OPTARG";; + esac +done +shift $(( $OPTIND - 1 )) + +while true; do + cd $aports || return 1 + # check if we need to rebuild + log "pulling git" + _old=$(git describe) + _old_tag=$(git describe --abbrev=0) + git checkout $git_branch + git pull || return 1 + _current=$(git describe) + _current_tag=$(git describe --abbrev=0) + if [ "$_old_tag" != "$_current_tag" ]; then + log "$_old_tag -> $_current_tag" + fi + if [ "$_old" = "$_current" ] && [ -f /tmp/uploaded ] && [ -z "$force" ] && [ "$_current_tag" = "$_old_tag" ]; then + break + fi + + force= + + # check if we need make new release + if [ "$_current_tag" != "$_old_tag" ]; then + _new_release=1 + # we want build the realease from this tag + git checkout "$_current_tag" + _current=$(git describe) + fi + + rm -f /tmp/uploaded + + # do the compile, send output to log + log "building $_current" +# # temp workaround - abuild does not resolve the linux kernel dep +# ( +# cd $HOME/aports/main +# for i in linux-*; do +# ( +# export REPODEST=$HOME/packages +# cd $i && abuild -Rk )||break +# done +# ) + if ! buildrepo -p $repos >"$logdir"/$hostname.log 2>&1 ; then + local errlog=$hostname.$_current.log + cp "$logdir"/$hostname.log "$logdir"/$errlog + # todo: revert last commit? + send_irc "failed to build $_current: $logurlprefix/$errlog" + exit 1 + fi + + # upgrade our running system + log "upgrading system" + sudo apk upgrade -U -a --quiet || log 'failed to apk upgrade' + + # copy for distribution + cd "$packages" || return 1 + if [ -z "$upload_pkg" ]; then + break + fi + log "uploading packages" + rc=0 + for i in $upload_pkg; do + local repo + for repo in $repos; do + rsync -ruv --delete-delay --delay-updates $repo/$arch $i/$repo/ + rc=$(( $rc + $? )) + done + done + [ $rc -eq 0 ] && touch /tmp/uploaded && sudo apk update + + # report to irc that we are done + send_irc "files from $_current uploaded" + + # if + if [ "$_current_tag" != "$_old_tag" ]; then + if new_release ${_current_tag#v}; then + send_irc "release $_current_tag uploaded" + fi + fi +done + +# cleanup +log "idle" +rm -f $lockfile + diff --git a/main/aports-build/aports-build.confd b/main/aports-build/aports-build.confd new file mode 100644 index 000000000..a43d1c39d --- /dev/null +++ b/main/aports-build/aports-build.confd @@ -0,0 +1,10 @@ +# what git branch to build +git_branch=master + +# what directory to upload to +# upload_release=edge + +# prefix for url where logs can be found +# logurlprefix=http://bld1.alpinelinux.org/buildlogs + + diff --git a/main/aports-build/aports-build.initd b/main/aports-build/aports-build.initd new file mode 100644 index 000000000..bb849af54 --- /dev/null +++ b/main/aports-build/aports-build.initd @@ -0,0 +1,34 @@ +#!/sbin/runscript + +: ${mqtt_broker:="msg.alpinelinux.org"} +: ${git_branch:=master} +: ${mqtt_topic:="git/aports/$git_branch"} + +command=/usr/bin/mqtt-exec +pidfile=/var/run/aports-build/mqtt-exec.pid +command_args="-h ${mqtt_broker:-msg.alpinelinux.org} -t $mqtt_topic -- /usr/bin/aports-build" +start_stop_daemon_args="--stdout /dev/null --stderr /dev/null --background --make-pid --user buildozer" + +start_pre() { + local h=$(getent passwd buildozer | cut -d: -f6) + checkpath --owner buildozer --directory ${pidfile%/*} + local i + for i in aports alpine-iso; do + if ! [ -d "$h"/$i ]; then + eerror "$h/$i is missing. Please git clone it" + return 1 + fi + done +} + +stop_post() { + # remove build status + if [ -f /etc/aports-build.conf ]; then + . /etc/aports-build.conf + fi + : ${hostname:=$(hostname)} + : ${mqtthost:="msg.alpinelinux.org"} + : ${status_clear:="mosquitto_pub -h $mqtthost -t build/$hostname -r -n"} + $status_clear + return 0 +} diff --git a/main/aports-build/aports-build.pre-install b/main/aports-build/aports-build.pre-install new file mode 100644 index 000000000..e9d9bfbf0 --- /dev/null +++ b/main/aports-build/aports-build.pre-install @@ -0,0 +1,4 @@ +#!/bin/sh + +adduser -D buildozer -s /bin/sh 2>/dev/null +exit 0 -- cgit v1.2.3