From 3e2d71d7b135cc6980cc10a4108130236734551e Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Fri, 30 Oct 2020 16:04:16 -0700 Subject: Initial version. --- .gitignore | 8 ++++ Makefile | 8 ++++ debian/changelog | 5 +++ debian/compat | 1 + debian/control | 15 +++++++ debian/copyright | 7 +++ debian/gbp.conf | 3 ++ debian/manpages | 2 + debian/olamic.install | 4 ++ debian/olamic.service | 11 +++++ debian/rules | 4 ++ debian/source/format | 1 + examples/olamic-githook-post-receive | 23 ++++++++++ examples/olamic-run | 25 +++++++++++ man/olamic-enqueue.1.md | 24 +++++++++++ man/olamic-worker.1.md | 36 ++++++++++++++++ olamic-enqueue | 50 ++++++++++++++++++++++ olamic-run | 14 ++++++ olamic-worker | 83 ++++++++++++++++++++++++++++++++++++ pick-task | 25 +++++++++++ 20 files changed, 349 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/gbp.conf create mode 100644 debian/manpages create mode 100644 debian/olamic.install create mode 100644 debian/olamic.service create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100755 examples/olamic-githook-post-receive create mode 100644 examples/olamic-run create mode 100644 man/olamic-enqueue.1.md create mode 100644 man/olamic-worker.1.md create mode 100755 olamic-enqueue create mode 100644 olamic-run create mode 100755 olamic-worker create mode 100755 pick-task diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a01d365 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/debian/.debhelper/ +/debian/debhelper-build-stamp +/debian/files +/debian/olamic.postrm.debhelper +/debian/olamic.substvars +/debian/olamic/ +/man/olamic-enqueue.1 +/man/olamic-worker.1 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fc29c78 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +MANPAGES := $(basename $(wildcard man/*.md)) + +build: ${MANPAGES} + +.PHONY: build + +%: %.md + pandoc -s -t man -o $@ $< diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..695c208 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +olamic (1) unstable; urgency=medium + + * Initial version. + + -- Julian Blake Kongslie Fri, 30 Oct 2020 16:18:52 -0700 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..b4de394 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +11 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..37a7e6b --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: olamic +Section: devel +Priority: optional +Maintainer: Julian Blake Kongslie +Build-Depends: debhelper (>= 11), pandoc +Standards-Version: 4.1.3 + +Package: olamic +Architecture: all +Depends: ${misc:Depends}, ${shlibs:Depends}, git, default-mta | mail-transport-agent +Description: Very simple continuous integration for git + Olamic is a continuous integration system written in bash designed to support + the needs of basic projects without involving a web server or anything like + that. It supports multiple worker nodes, but does not support dependencies or + ordering between tasks. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..c2d763c --- /dev/null +++ b/debian/copyright @@ -0,0 +1,7 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: olamic + +Files: * +Copyright: 2020 Julian Blake Kongslie +License: GPL-2 + See /usr/share/common-licenses/GPL-2 diff --git a/debian/gbp.conf b/debian/gbp.conf new file mode 100644 index 0000000..1b36eba --- /dev/null +++ b/debian/gbp.conf @@ -0,0 +1,3 @@ +[dch] +debian-branch = main +debian-tag = release/%(version)s diff --git a/debian/manpages b/debian/manpages new file mode 100644 index 0000000..d87b5e9 --- /dev/null +++ b/debian/manpages @@ -0,0 +1,2 @@ +man/olamic-enqueue.1 +man/olamic-worker.1 diff --git a/debian/olamic.install b/debian/olamic.install new file mode 100644 index 0000000..6becfd7 --- /dev/null +++ b/debian/olamic.install @@ -0,0 +1,4 @@ +examples /usr/share/doc/olamic +olamic-enqueue /usr/bin +olamic-worker /usr/bin +pick-task /usr/share/olamic diff --git a/debian/olamic.service b/debian/olamic.service new file mode 100644 index 0000000..0c36feb --- /dev/null +++ b/debian/olamic.service @@ -0,0 +1,11 @@ +[Unit] +Description=Olamic worker + +[Service] +Type=simple +User=olamic +WorkingDirectory=/srv/olamic +ExecStart=/usr/bin/olamic-worker + +[Install] +WantedBy=multi-user.target diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..2d33f6a --- /dev/null +++ b/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/examples/olamic-githook-post-receive b/examples/olamic-githook-post-receive new file mode 100755 index 0000000..3135d0d --- /dev/null +++ b/examples/olamic-githook-post-receive @@ -0,0 +1,23 @@ +#!/bin/bash + +set -eu + +OLAMIC_QUEUE_HOST="${OLAMIC_QUEUE_HOST:-}" +OLAMIC_QUEUE_DIR="${OLAMIC_QUEUE_DIR:-/srv/olamic/queue}" +OLAMIC_GIT_REPO="${OLAMIC_GIT_REPO:-"$(git rev-parse --absolute-git-dir)"}" + +while read OLD NEW REF; do + if git rev-parse --quiet --verify "$NEW":olamic-run > /dev/null; then + OLAMIC_EMAIL="$(git show --no-patch --format=%ae "$NEW")" + echo -n "Enqueuing olamic run for $REF: " + if [[ "$OLAMIC_QUEUE_HOST" == "" ]]; then + olamic-enqueue "$OLAMIC_QUEUE_DIR" "$OLAMIC_GIT_REPO" "$NEW" GIT_REF="$REF" OLAMIC_EMAIL="$OLAMIC_EMAIL" <&2 + exit 1 + fi +done + +TASK_SCRIPT="$(cat)" + +mkdir -p "$QUEUE_DIR" + +cd "$QUEUE_DIR" + +mkdir -p candidates tmp + +TEMP_TASK="$(mktemp tmp/XXXXXXXX)" + +chmod 644 "$TEMP_TASK" + +for i in $(seq 0 $((${#VARS[@]}-1))); do + VAR="${VARS[$i]}" + VAL="${VALS[$i]}" + printf "export %q=%q\n" "$VAR" "$VAL" >> "$TEMP_TASK" +done + +printf "export GIT_REPO=%q\n" "$GIT_REPO" >> "$TEMP_TASK" +printf "export GIT_OBJECT=%q\n" "$GIT_OBJECT" >> "$TEMP_TASK" +printf "export TASK_SCRIPT=%q\n" "$TASK_SCRIPT" >> "$TEMP_TASK" + +UUID="$(uuidgen -r)" + +until mv -n "$TEMP_TASK" candidates/"$UUID"; do + UUID="$(uuidgen -r)" +done + +echo "$UUID" diff --git a/olamic-run b/olamic-run new file mode 100644 index 0000000..46fdabc --- /dev/null +++ b/olamic-run @@ -0,0 +1,14 @@ +# vim: set ft=bash : + +dpkg-buildpackage +lintian --fail-on error,warning + +if [[ $GIT_REF =~ ^refs/tags/(.+)$ ]]; then + INSTALL_DIR=/srv/olamic/artifacts/olamic/"${BASH_REMATCH[1]}" +fi + +if [[ "${INSTALL_DIR:-}" != "" ]]; then + rm -rf "$INSTALL_DIR" + mkdir -p "$INSTALL_DIR" + cp -t "$INSTALL_DIR" ../olamic_* +fi diff --git a/olamic-worker b/olamic-worker new file mode 100755 index 0000000..942151a --- /dev/null +++ b/olamic-worker @@ -0,0 +1,83 @@ +#!/bin/bash + +set -eu -o pipefail + +OLAMIC_EMAIL="${OLAMIC_EMAIL:-}" +OLAMIC_QUEUE_HOST="${OLAMIC_QUEUE_HOST:-}" +OLAMIC_QUEUE_DIR="${OLAMIC_QUEUE_DIR:-/srv/olamic/queue}" +OLAMIC_WORKER_PERIOD="${OLAMIC_WORKER_PERIOD:-1m}" + +OLAMIC_WORKER_DIR="$(pwd -P)" + +while true; do + if [[ "$OLAMIC_QUEUE_HOST" == "" ]]; then + TASK_INFO="$(/usr/share/olamic/pick-task "$OLAMIC_QUEUE_DIR")" + else + TASK_INFO="$(ssh "$OLAMIC_QUEUE_HOST" /usr/share/olamic/pick-task "$OLAMIC_QUEUE_DIR")" + fi + + if [[ "$TASK_INFO" == "" ]]; then + sleep "$OLAMIC_WORKER_PERIOD" + continue + fi + + ( + eval "$TASK_INFO" + printf "Running task %q\n" "$TASK_ID" + + if [[ ! -e cache.git ]]; then + git init --bare cache.git + fi + + set +e + ( + set -ex + + GIT_DIR=cache.git git fetch "$GIT_REPO" "$GIT_OBJECT" + + rm -rf work + mkdir work + cd work + + git clone --shared "$OLAMIC_WORKER_DIR"/cache.git checkout + cd checkout + git config advice.detachedHead false + git checkout -f "$GIT_OBJECT" + + ( + eval "$TASK_SCRIPT" + ) + ) 2>&1 | tee log + STATUS="$?" + + set -e + + if [[ "$STATUS" != "0" ]]; then + echo "Task failed with exit code $STATUS" + if [[ "$OLAMIC_EMAIL" != "" ]]; then + echo "Sending email to $OLAMIC_EMAIL" + sendmail -t </dev/null; then + cat in-progress/"$CANDIDATE" + printf "export TASK_ID=%q\n" "$CANDIDATE" + break + fi +done -- cgit v1.2.3