summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2014-04-16 17:00:14 +0200
committerHolger Levsen <holger@layer-acht.org>2014-04-16 18:03:55 +0200
commitef21849e646c1a0712735583409c4490935f8145 (patch)
tree87c05c4f56f4bcae75dd3e28f3c0a1d10fee666a
parent518c78099815bff8b95dabad7408735ff0c67687 (diff)
downloadjenkins.debian.net-ef21849e646c1a0712735583409c4490935f8145.tar.xz
First shot at a schroot creating script
It currently uses sudo freely -- I wonder if it is worth updating sudoers appropriately. Maybe the whole script can be added to sudoers? The jenkins job definition itself is not tested.
-rwxr-xr-xbin/schroot-install.sh115
-rw-r--r--job-cfg/schroot.yaml50
-rwxr-xr-xupdate_jdn.sh4
3 files changed, 167 insertions, 2 deletions
diff --git a/bin/schroot-install.sh b/bin/schroot-install.sh
new file mode 100755
index 00000000..22f7eddc
--- /dev/null
+++ b/bin/schroot-install.sh
@@ -0,0 +1,115 @@
+#!/bin/bash
+
+# Copyright 2012-2014 Holger Levsen <holger@layer-acht.org>
+# Copyright 2013 Antonio Terceiro <terceiro@debian.org>
+# released under the GPLv=2
+
+# $2 = schroot name
+# $1 = base distro
+# $2 $3 ... = extra packages to install
+
+# bootstraps a new chroot for schroot, and then moves it into the right location
+
+set -e
+export LC_ALL=C
+
+# Defaults for the jenkins.debian.net environment
+if [ -z "$MIRROR" ]; then
+ export MIRROR=http://ftp.de.debian.org/debian
+fi
+if [ -z "$http_proxy" ]; then
+ # export http_proxy="http://localhost:3128"
+ :
+fi
+if [ -z "$CHROOT_BASE" ]; then
+ export CHROOT_BASE=/chroots
+fi
+if [ -z "$SCHROOT_BASE" ]; then
+ export SCHROOT_BASE=$CHROOT_BASE/schroot
+fi
+
+if [ $# -lt 2 ]; then
+ echo "usage: $0 DISTRO [backports] CMD [ARG1 ARG2 ...]"
+ exit 1
+fi
+
+TARGET="$1"
+shift
+DISTRO="$1"
+shift
+
+if [ "$1" == "backports" ] ; then
+ BACKPORTS="deb $MIRROR ${DISTRO}-backports main"
+ BACKPORTSSRC="deb-src $MIRROR ${DISTRO}-backports main"
+ shift
+fi
+
+if [ ! -d "$CHROOT_BASE" ]; then
+ echo "Directory $CHROOT_BASE does not exist, aborting."
+ exit 1
+fi
+
+export CHROOT_TARGET=$(mktemp -d -p $CHROOT_BASE/ schroot-install-$TARGET-XXXX)
+if [ -z "$CHROOT_TARGET" ]; then
+ echo "Could not create a directory to create the chroot in, aborting."
+ exit 1
+fi
+
+export CURDIR=$(pwd)
+
+bootstrap() {
+ sudo debootstrap $DISTRO $CHROOT_TARGET $MIRROR
+
+ sudo -s <<-EOF
+ set -e
+ set -x
+ echo -e '#!/bin/sh\nexit 101' > $CHROOT_TARGET/usr/sbin/policy-rc.d
+ chmod +x $CHROOT_TARGET/usr/sbin/policy-rc.d
+ echo 'Acquire::http::Proxy "$http_proxy";' > $CHROOT_TARGET/etc/apt/apt.conf.d/80proxy
+ echo "deb-src $MIRROR $DISTRO main" >> $CHROOT_TARGET/etc/apt/sources.list
+ echo "${BACKPORTS}" >> $CHROOT_TARGET/etc/apt/sources.list
+ echo "${BACKPORTSSRC}" >> $CHROOT_TARGET/etc/apt/sources.list
+ EOF
+}
+
+cleanup() {
+ if [ -d $CHROOT_TARGET ]; then
+ sudo rm -rf --one-file-system $CHROOT_TARGET || fuser -mv $CHROOT_TARGET
+ fi
+}
+trap cleanup INT TERM EXIT
+bootstrap
+
+trap - INT TERM EXIT
+
+# pivot the new schroot in place
+rand=$RANDOM
+if [ -d $SCHROOT_BASE/"$TARGET" ]
+then
+ sudo mv $SCHROOT_BASE/"$TARGET" $SCHROOT_BASE/"$TARGET"-"$rand"
+fi
+
+sudo mv $CHROOT_TARGET $SCHROOT_BASE/"$TARGET"
+
+if [ -d $SCHROOT_BASE/"$TARGET"-"$rand" ]
+then
+ sudo rm -rf --one-file-system $SCHROOT_BASE/"$TARGET"-"$rand"
+fi
+
+# write the schroot config
+echo "Writing configuration"
+sudo tee /etc/schroot/chroot.d/jenkins-"$TARGET" <<-__END__
+ [jenkins-$TARGET]
+ description=Jenkins schroot $TARGET
+ directory=$SCHROOT_BASE/$TARGET
+ type=directory
+ root-users=jenkins
+ source-root-users=jenkins
+ union-type=aufs
+ __END__
+
+schroot -c "source:jenkins-$TARGET" -u root -- apt-get update
+if [ -n "$1" ]
+then
+ schroot -c "source:jenkins-$TARGET" -u root -- apt-get install -y --no-install-recommends "$@"
+fi
diff --git a/job-cfg/schroot.yaml b/job-cfg/schroot.yaml
new file mode 100644
index 00000000..92306b39
--- /dev/null
+++ b/job-cfg/schroot.yaml
@@ -0,0 +1,50 @@
+defaults:
+ name: schroot
+ do_not_edit: '<br><br>Job configuration source is <a href="http://anonscm.debian.org/gitweb/?p=qa/jenkins.debian.net.git;a=blob;f=job-cfg/schroot.yaml">schroot.yaml</a>.'
+ publishers:
+ - email:
+ recipients: jenkins+debian-qa holger@layer-acht.org
+ triggers:
+ - timed: '{my_time}'
+
+
+job-template:
+ defaults: schroot
+ name: '{schroot}-install'
+ description: 'schroot "{schroot}" -- installation {do_not_edit}'
+ distro: 'sid'
+ extra-pkgs: ''
+ block-downstream: yes
+ builders:
+ - shell: '/srv/jenkins/bin/schroot-install.sh {schroot} {distro} {extra_pkgs}'
+
+job-template:
+ defaults: schroot
+ name: '{schroot}-upgrade'
+ description: 'schroot "{schroot}" -- installation {do_not_edit}'
+ distro: 'sid'
+ extra-pkgs: ''
+ block-downstream: yes
+ builders:
+ - shell: 'schroot -u root -c source:jenkins-{schroot} -- apt-get update'
+ - shell: 'schroot -u root -c source:jenkins-{schroot} -- apt-get -y -u dist-upgrade'
+ - shell: 'schroot -u root -c source:jenkins-{schroot} -- apt-get --purge autoremove'
+
+project:
+ name: haskell-schroot
+ schroot: haskell
+ jobs:
+ - '{schroot}-install':
+ extra_pkgs: 'ghc'
+ my_time: '0 10 * * 1'
+ - '{schroot}-upgrade':
+ my_time: '0 11 * * *'
+
+project:
+ name: sid-schroot
+ schroot: sid
+ jobs:
+ - '{schroot}-install':
+ my_time: '0 10 * * 2'
+ - '{schroot}-upgrade':
+ my_time: '0 11 * * *'
diff --git a/update_jdn.sh b/update_jdn.sh
index c0c35d71..7a910f5f 100755
--- a/update_jdn.sh
+++ b/update_jdn.sh
@@ -12,7 +12,7 @@ explain() {
}
# make sure needed directories exists
-for directory in /srv/jenkins /chroots ; do
+for directory in /srv/jenkins /chroots /chroots/schroots; do
if [ ! -d $directory ] ; then
sudo mkdir $directory
sudo chown jenkins.jenkins $directory
@@ -25,7 +25,7 @@ done
#
sudo apt-get install vim screen less etckeeper moreutils curl mtr-tiny dstat devscripts bash-completion shorewall shorewall6 cron-apt apt-listchanges munin calamaris visitors procmail libjson-rpc-perl libfile-touch-perl zutils ip2host \
build-essential python-setuptools \
- debootstrap sudo figlet graphviz apache2 python-yaml python-pip mr subversion subversion-tools vnstat webcheck poxml qemu vncsnapshot imagemagick ffmpeg2theora python-twisted python-imaging gocr guestmount
+ debootstrap sudo figlet graphviz apache2 python-yaml python-pip mr subversion subversion-tools vnstat webcheck poxml qemu vncsnapshot imagemagick ffmpeg2theora python-twisted python-imaging gocr guestmount schroot
explain "Packages installed."
#