aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2013-11-28 16:02:41 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2013-11-28 16:05:55 +0000
commit42f4fcce5da4b03b577c3328115ba8be9c4ef683 (patch)
treeacf1292cb144e96c0f30585107d8ae5954cde7e4 /testing
parent235e9d03d6dd79f28ba8365f88a4c048a4fe3f19 (diff)
downloadaports-42f4fcce5da4b03b577c3328115ba8be9c4ef683.tar.bz2
aports-42f4fcce5da4b03b577c3328115ba8be9c4ef683.tar.xz
testing/aports-build: new aports
MQTT based build-on-git-push scripts
Diffstat (limited to 'testing')
-rw-r--r--testing/aports-build/APKBUILD50
-rw-r--r--testing/aports-build/aports-build184
-rw-r--r--testing/aports-build/aports-build.confd10
-rw-r--r--testing/aports-build/aports-build.initd34
-rw-r--r--testing/aports-build/aports-build.pre-install4
5 files changed, 282 insertions, 0 deletions
diff --git a/testing/aports-build/APKBUILD b/testing/aports-build/APKBUILD
new file mode 100644
index 0000000000..a6a41706e3
--- /dev/null
+++ b/testing/aports-build/APKBUILD
@@ -0,0 +1,50 @@
+# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
+pkgname=aports-build
+pkgver=0.1
+pkgrel=0
+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="5d0a7c69d166c7012f2a5c2a24e402ce aports-build
+40ff7be2ad647d22c4c8ebfe1fec8b1b aports-build.initd
+cdc49e0ef145de72131972a575f20e7b aports-build.confd"
+sha256sums="547b150e7e07c2d64a5648bbc6944a6e7c9123dc72a2c3e3bb392662cb4af010 aports-build
+e6b228ccc0dcdf7f172ebd3777c5791b96f86a8c96a4df95df2dd3c9051b91fe aports-build.initd
+519744cdb4be83e5da1c22d4aa93c7ef97d66e03565e84b710bc21c94b82047e aports-build.confd"
+sha512sums="d71d392b46f1009b262c68af5b2d926bab25f1570690cce064a9e16d544de67eefb73a33799d2d65054c250da4eff786f7a7272af3f325ea1bfc776b7c92393e aports-build
+af5cd8e2647f3b9aa03020d5cea996a750b48b2b3a4d208f5ef683538aba3ecada677b9a0071385c85ec66803b8ed055b1d58853ccfe198c1c5beaad99d97d86 aports-build.initd
+fbe8ed4b1fbfc979de62302873e99c67bab751a7fcd921c3b23815f535cedb34c717e82b3c223f88e06498a573cbd147a73db7bf5adbb5e1947ac75fcb8edcb4 aports-build.confd"
diff --git a/testing/aports-build/aports-build b/testing/aports-build/aports-build
new file mode 100644
index 0000000000..fd2ede9a53
--- /dev/null
+++ b/testing/aports-build/aports-build
@@ -0,0 +1,184 @@
+#!/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?
+# log "building $repos ($_current) failed"
+# send_irc "failed to build $_current: $logurlprefix/$errlog"
+# log "idle"
+ 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/testing/aports-build/aports-build.confd b/testing/aports-build/aports-build.confd
new file mode 100644
index 0000000000..a43d1c39d4
--- /dev/null
+++ b/testing/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/testing/aports-build/aports-build.initd b/testing/aports-build/aports-build.initd
new file mode 100644
index 0000000000..bb849af54c
--- /dev/null
+++ b/testing/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/testing/aports-build/aports-build.pre-install b/testing/aports-build/aports-build.pre-install
new file mode 100644
index 0000000000..e9d9bfbf03
--- /dev/null
+++ b/testing/aports-build/aports-build.pre-install
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+adduser -D buildozer -s /bin/sh 2>/dev/null
+exit 0