summaryrefslogtreecommitdiff
path: root/semaphoreci
diff options
context:
space:
mode:
authorMartin Pitt <martin@piware.de>2019-03-03 22:19:16 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-03-04 15:05:14 +0100
commit0d427d377a09b316fe9f291de08c18d3ef51d70d (patch)
treedda1d7531bd613c74ba09238ccc403b8628221b1 /semaphoreci
parent4d97f5a09e874e356bf795c238f96f8458c50ae5 (diff)
downloadsystemd-0d427d377a09b316fe9f291de08c18d3ef51d70d.tar.gz
semaphoreci: caching and more robust creation of container image
lxc-create in semaphore sometimes fails with ERROR: Unable to fetch GPG key from keyserver Which often happens behind proxies. As the default key server is a load balancer, retry a few times. Also, cache the container image between runs, and only recreate it when it is older than a week.
Diffstat (limited to 'semaphoreci')
-rwxr-xr-xsemaphoreci/setup.sh57
1 files changed, 37 insertions, 20 deletions
diff --git a/semaphoreci/setup.sh b/semaphoreci/setup.sh
index b8cdba8033..c904a300a1 100755
--- a/semaphoreci/setup.sh
+++ b/semaphoreci/setup.sh
@@ -7,6 +7,36 @@ DISTRO=${DISTRO:-debian}
RELEASE=${RELEASE:-buster}
ARCH=${ARCH:-amd64}
CONTAINER=${RELEASE}-${ARCH}
+MAX_CACHE_AGE=604800 # one week
+CACHE=${SEMAPHORE_CACHE_DIR:=/tmp}/${CONTAINER}.img.tar.gz
+
+create_container() {
+ # create autopkgtest LXC image; this sometimes fails with "Unable to fetch
+ # GPG key from keyserver", so retry a few times
+ for retry in $(seq 5); do
+ sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH && break
+ sleep $((retry*retry))
+ done
+
+ # unconfine the container, otherwise some tests fail
+ echo 'lxc.apparmor.profile = unconfined' | sudo tee -a /var/lib/lxc/$CONTAINER/config
+
+ sudo lxc-start -n $CONTAINER
+
+ # enable source repositories so that apt-get build-dep works
+ sudo lxc-attach -n $CONTAINER -- sh -ex <<EOF
+sed 's/^deb/deb-src/' /etc/apt/sources.list >> /etc/apt/sources.list.d/sources.list
+# wait until online
+while [ -z "\$(ip route list 0/0)" ]; do sleep 1; done
+apt-get -q update
+apt-get -y dist-upgrade
+apt-get install -y eatmydata
+EOF
+ sudo lxc-stop -n $CONTAINER
+
+ # cache it
+ sudo tar cpzf "$CACHE" /var/lib/lxc/$CONTAINER
+}
# remove semaphore repos, some of them don't work and cause error messages
sudo rm -f /etc/apt/sources.list.d/*
@@ -17,25 +47,12 @@ sudo apt-get -q update
sudo apt-get install -y -t xenial-backports lxc
sudo apt-get install -y python3-debian git dpkg-dev fakeroot
-AUTOPKGTESTDIR=${SEMAPHORE_CACHE_DIR:-/tmp}/autopkgtest
+AUTOPKGTESTDIR=$SEMAPHORE_CACHE_DIR/autopkgtest
[ -d $AUTOPKGTESTDIR ] || git clone --quiet --depth=1 https://salsa.debian.org/ci-team/autopkgtest.git "$AUTOPKGTESTDIR"
-# TODO: cache container image (though downloading/building it takes < 1 min)
-# create autopkgtest LXC image
-sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH
-
-# unconfine the container, otherwise some tests fail
-echo 'lxc.apparmor.profile = unconfined' | sudo tee -a /var/lib/lxc/$CONTAINER/config
-
-sudo lxc-start -n $CONTAINER
-
-# enable source repositories so that apt-get build-dep works
-sudo lxc-attach -n $CONTAINER -- sh -ex <<EOF
-sed 's/^deb/deb-src/' /etc/apt/sources.list >> /etc/apt/sources.list.d/sources.list
-# wait until online
-while [ -z "\$(ip route list 0/0)" ]; do sleep 1; done
-apt-get -q update
-apt-get -y dist-upgrade
-apt-get install -y eatmydata
-EOF
-sudo lxc-stop -n $CONTAINER
+# use cached container image, unless older than a week
+if [ -e "$CACHE" ] && [ $(( $(date +%s) - $(stat -c %Y "$CACHE") )) -le $MAX_CACHE_AGE ]; then
+ sudo tar -C / -xpzf "$CACHE"
+else
+ create_container
+fi