From d562390407eec6ecc83a9f19635258fbe83b6695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 14 Oct 2018 17:31:02 +0200 Subject: alpine: move it to templates and try to add qemu support --- files/alpine/amd64.sh | 50 -------------------------------- job.common | 26 +++++++++-------- jobs/alpine-amd64.conf | 3 +- jobs/alpine-amd64.env | 1 + jobs/alpine-amd64.run | 12 +------- scripts/uchroot | 35 +++++++++++++++++++---- templates/alpine.conf | 2 ++ templates/alpine.run | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 125 insertions(+), 81 deletions(-) delete mode 100755 files/alpine/amd64.sh mode change 100644 => 120000 jobs/alpine-amd64.conf create mode 100644 jobs/alpine-amd64.env mode change 100755 => 120000 jobs/alpine-amd64.run create mode 100644 templates/alpine.conf create mode 100755 templates/alpine.run 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 < .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 <&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 < .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 <