summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfiles/alpine/amd64.sh50
-rw-r--r--job.common26
l---------[-rw-r--r--]jobs/alpine-amd64.conf3
-rw-r--r--jobs/alpine-amd64.env1
l---------[-rwxr-xr-x]jobs/alpine-amd64.run12
-rwxr-xr-xscripts/uchroot35
-rw-r--r--templates/alpine.conf2
-rwxr-xr-xtemplates/alpine.run77
8 files changed, 125 insertions, 81 deletions
diff --git a/files/alpine/amd64.sh b/files/alpine/amd64.sh
deleted file mode 100755
index e80cc5c..0000000
--- a/files/alpine/amd64.sh
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/sh
-. utils
-
-# TODO mount global distfiles cache
-
-# TODO get latest uri from latest-releases.yml file
-if [ ! -d "$ROOT" ]; then
- echo_stage "Setting up new root"
- wget "http://dl-cdn.alpinelinux.org/alpine/edge/releases/x86_64/alpine-minirootfs-3.8.0-x86_64.tar.gz" -O alpine.tar.gz
- # TODO verify signature
- gunzip alpine.tar.gz
- tar -f alpine.tar --delete ./dev/null
- mkdir "$ROOT"
- uroot tar -xf alpine.tar -C "$ROOT"
- chmod 755 "$ROOT" # This is intentional, tar changes access rights
- uchroot "$ROOT" root /bin/sh <<EOF
- set -ex
- apk update
- apk add alpine-sdk lua-aports
- adduser -s /bin/sh -D -h /build build
- addgroup build abuild
- mkdir -p /var/cache/distfiles
- chgrp abuild /var/cache/distfiles
- chmod g+w /var/cache/distfiles
-EOF
- uchroot "$ROOT" build 'mkdir .abuild aports && echo "PACKAGER_PRIVKEY=\"/build/.abuild/cynerd@email.cz-5b8aeb6d.rsa\"" > .abuild/abuild.conf'
- uroot cp ~/alpinelinux.rsa.key "$ROOT/build/.abuild/cynerd@email.cz-5b8aeb6d.rsa"
- uchroot "$ROOT" root 'chown build:build "/build/.abuild/cynerd@email.cz-5b8aeb6d.rsa"'
- uroot cp ~/alpinelinux.rsa.key.pub "$ROOT/etc/apk/keys/cynerd@email.cz-5b8aeb6d.rsa.pub"
- uroot cp "$JOB_FILES/abuild.conf" "$ROOT/etc/abuild.conf"
-fi
-
-echo_stage "Update system"
-uchroot "$ROOT" root 'apk update && apk upgrade'
-
-echo_stage "Get packages source"
-git_clone "git@cynerd.cz:alpine-personal-pkgs" "$ROOT/pkgs"
-uchroot "$ROOT" root "rm -rf /build/aports/personal && chown -R build:build /pkgs && mv /pkgs /build/aports/personal"
-
-echo_stage "Build packages"
-uchroot "$ROOT" build buildrepo --purge personal
-
-echo_stage "Deploy"
-ssh upload rm -rf "deploy-alpine-amd64"
-scp -r "$ROOT/build/packages/personal" upload:deploy-alpine
-ssh upload /bin/sh -e <<EOF
- rm -rf /var/www/repo/alpine
- mv deploy-alpine /var/www/repo/alpine
-EOF
-scp "$FILES"/alpine/setup.sh{,.gpg} upload:/var/www/repo/alpine/
diff --git a/job.common b/job.common
index 92941dc..165f61c 100644
--- a/job.common
+++ b/job.common
@@ -5,21 +5,23 @@ if [ -z "$WORKSPACE" ]; then
fi
# Subprocess inclusion guard
-[ -z "$LAMINAR_COMMON" ]
-export LAMINAR_COMMON=y
+if [ -z "$LAMINAR_COMMON" ]; then
+ export LAMINAR_COMMON=y
-# Job and template id
-export JOBID="$(basename "$0" | sed 's/\.run$//')"
-export TEMPLATEID="$(basename "$(readlink -f "$0")" | sed 's/\.run$//')"
+ # Job and template id
+ export JOBID="$(basename "$0" | sed 's/\.run$//')"
+ export TEMPLATEID="$(basename "$(readlink -f "$0")" | sed 's/\.run$//')"
-# Template workspace
-export TWORKSPACE="$HOME/workspace/$TEMPLATEID"
-if [ "$JOBID" = "$TEMPLATEID" ]; then
- TWORKSPACE="$HOME/workspace/notemplate"
-fi
+ # Template workspace
+ export TWORKSPACE="$HOME/workspace/$TEMPLATEID"
+ if [ "$JOBID" = "$TEMPLATEID" ]; then
+ TWORKSPACE="$HOME/workspace/notemplate"
+ fi
+
+ # Files directory
+ export FILES="$(readlink -f "$(dirname "$(readlink -f "$0")")/../files")"
-# Files directory
-export FILES="$(readlink -f "$(dirname "$(readlink -f "$0")")/../files")"
+fi
# Include utils
. utils
diff --git a/jobs/alpine-amd64.conf b/jobs/alpine-amd64.conf
index 04e6713..6b2fe0b 100644..120000
--- a/jobs/alpine-amd64.conf
+++ b/jobs/alpine-amd64.conf
@@ -1,2 +1 @@
-TAGS=heavy
-TIMEOUT=14400
+../templates/alpine.conf \ No newline at end of file
diff --git a/jobs/alpine-amd64.env b/jobs/alpine-amd64.env
new file mode 100644
index 0000000..7315763
--- /dev/null
+++ b/jobs/alpine-amd64.env
@@ -0,0 +1 @@
+ARCH=x86_64
diff --git a/jobs/alpine-amd64.run b/jobs/alpine-amd64.run
index fbb2961..7fcd92b 100755..120000
--- a/jobs/alpine-amd64.run
+++ b/jobs/alpine-amd64.run
@@ -1,11 +1 @@
-#!/bin/sh
-# vim: ft=sh
-. "$(dirname "$(readlink -f "$0")")/../job.common"
-
-if [ -n "$CLEAN" ]; then
- echo_stage "Remove root"
- flock --exclusive "$WORKSPACE/root.lock" uroot rm -rf "$WORKSPACE/root"
-fi
-
-export ROOT="$WORKSPACE/root"
-flock --exclusive "$WORKSPACE/root.lock" "$FILES/alpine/amd64.sh"
+../templates/alpine.run \ No newline at end of file
diff --git a/scripts/uchroot b/scripts/uchroot
index b11981a..b94e14f 100755
--- a/scripts/uchroot
+++ b/scripts/uchroot
@@ -1,7 +1,11 @@
#!/bin/sh
set -e
[ $# -ge 1 ] || {
- echo "Usage: uchroot ROOT [USER] [CMD]" >&2
+ echo "Usage: uchroot USER [CMD] [ARG].." >&2
+ echo "Configuration has to be passed trough envrionment."
+ echo " ROOT: path to directory to chroot in"
+ echo " ARCH: optional target architecture (if qemu should be used)"
+ echo " MOUNT: pairs of two paths separated by colon (LOCAL:INROOT)"
exit 1
}
@@ -10,10 +14,17 @@ if [ "$(id -u)" != "0" ]; then
fi
###############################################################
-ROOT="$1"
-USR="${2:-root}"
-shift 2
-[ $# -lt 1 ] && CMD="" || CMD="-c '$@'"
+[ -n "$ROOT" ] || {
+ echo "Variable ROOT has to be defined in environment."
+ exit 1
+}
+
+USR="${1:-root}"
+shift
+[ $# -lt 1 ] && CMD="" || {
+ CMD="-c \"$1\""
+ shift
+}
[ -d "$ROOT" ] || {
echo "There is no such directory: $ROOT" >&2
@@ -24,11 +35,23 @@ shift 2
exit 1
}
+EXECUTOR=
+
mount --rbind "$ROOT" "$ROOT"
mount -t proc none "$ROOT/proc"
mount --rbind /dev "$ROOT/dev"
mount --rbind /sys "$ROOT/sys"
+while IFS=: read src target; do
+ [ -n "$src" -a -n "$target" ] || continue
+ mount --rbind "$src" "$ROOT/$target"
+done <<<"$MOUNT"
+
cp -f /etc/resolv.conf "$ROOT/etc/resolv.conf"
cp -f /etc/hosts "$ROOT/etc/hosts"
+if [ -n "$ARCH" -a "$ARCH" != "$(arch)" ]; then
+ cp -f "$(which "qemu-$ARCH")" "$ROOT/qemu"
+ EXECUTOR=/qemu
+fi
-exec chroot "$ROOT" /bin/sh -c ". /etc/profile && exec su $CMD -l $USR" "$0"
+exec chroot "$ROOT" $EXECUTOR /bin/sh -c \
+ ". /etc/profile && exec su -l $USR $CMD \"\$@\"" -- "$@"
diff --git a/templates/alpine.conf b/templates/alpine.conf
new file mode 100644
index 0000000..4c3a13f
--- /dev/null
+++ b/templates/alpine.conf
@@ -0,0 +1,2 @@
+TAGS=heavy
+TIMEOUT=3600
diff --git a/templates/alpine.run b/templates/alpine.run
new file mode 100755
index 0000000..0e11b12
--- /dev/null
+++ b/templates/alpine.run
@@ -0,0 +1,77 @@
+#!/bin/sh
+# vim: ft=sh
+. "$(dirname "$(readlink -f "$0")")/../job.common"
+
+# Lock for execution
+if [ "$1" != "--locked" ]; then
+ flock --exclusive "$WORKSPACE/root.lock" "$0" "$@" --locked
+ exit
+fi
+
+if [ -n "$CLEAN_ROOT" ]; then
+ echo_stage "Remove root"
+ uroot rm -rf "$WORKSPACE/root"
+fi
+if [ -n "$CLEAN" ]; then
+ echo_stage "Remove packages"
+ uroot rm -rf "$WORKSPACE/packages"
+ echo_stage "Remove distfiles"
+ uroot rm -rf "$WORKSPACE/distfiles"
+fi
+
+[ -n "$ARCH" ] || echo_fail "Variable ARCH has to be defined in configuration for job."
+export ROOT="$WORKSPACE/root"
+export MOUNT="$TWORKSPACE/distfiles:/var/cache/distfiles
+$WORKSPACE/packages:/build/packages"
+mkdir -p "$TWORKSPACE/distfiles" "$WORKSPACE/packages"
+
+if [ ! -d "$ROOT" ]; then
+ # Prepare new root if there is none
+ # TODO get latest uri from latest-releases.yml file
+ echo_stage "Setting up new root"
+ wget "http://dl-cdn.alpinelinux.org/alpine/edge/releases/$ARCH/alpine-minirootfs-3.8.0-$ARCH.tar.gz" -O alpine.tar.gz
+ # TODO verify signature
+ gunzip alpine.tar.gz # tar is not able to change compressed files
+ tar -f alpine.tar --delete ./dev/null
+ mkdir "$ROOT"
+ uroot tar -xf alpine.tar -C "$ROOT"
+ chmod 755 "$ROOT" # This is intentional, tar changes access rights
+ MOUNT="" uchroot root <<EOF
+ set -e
+ apk update
+ apk add alpine-sdk lua-aports
+ adduser -s /bin/sh -D -h /build build
+ addgroup build abuild
+ su -l build -c 'mkdir .abuild aports packages'
+ su -l build -c 'echo "PACKAGER_PRIVKEY=\"/build/.abuild/cynerd@email.cz-5b8aeb6d.rsa\"" > .abuild/abuild.conf'
+EOF
+ uroot cp ~/alpinelinux.rsa.key "$ROOT/build/.abuild/cynerd@email.cz-5b8aeb6d.rsa"
+ uroot cp ~/alpinelinux.rsa.key.pub "$ROOT/etc/apk/keys/cynerd@email.cz-5b8aeb6d.rsa.pub"
+ uchroot root <<EOF
+ set -e
+ chgrp abuild /var/cache/distfiles
+ chmod g+w /var/cache/distfiles
+ chown build:build /build/packages
+ chown build:build "/build/.abuild/cynerd@email.cz-5b8aeb6d.rsa"
+EOF
+fi
+
+echo_stage "Update system"
+uchroot root 'apk update && apk upgrade'
+
+echo_stage "Get packages source"
+git_clone "git@cynerd.cz:alpine-personal-pkgs" "$ROOT/pkgs"
+uchroot root "rm -rf /build/aports/personal && chown -R build:build /pkgs && mv /pkgs /build/aports/personal"
+
+echo_stage "Build packages"
+uroot cp "$FILES/alpine/abuild.conf" "$ROOT/etc/abuild.conf"
+uchroot build 'buildrepo --purge personal'
+
+echo_stage "Deploy"
+ssh upload rm -rf "deploy-alpine"
+scp -r "$WORKSPACE/packages/personal" upload:deploy-alpine
+ssh upload /bin/sh -e <<EOF
+ rm -rf /var/www/repo/alpine
+ mv deploy-alpine /var/www/repo/alpine
+EOF
+scp "$FILES"/alpine/setup.sh{,.gpg} upload:/var/www/repo/alpine/