]>
Commit | Line | Data |
---|---|---|
841e1049 | 1 | #!/bin/bash |
841e1049 EV |
2 | set -ex |
3 | ||
59273a0c MP |
4 | # default to Debian testing |
5 | DISTRO=${DISTRO:-debian} | |
6 | RELEASE=${RELEASE:-buster} | |
7 | ARCH=${ARCH:-amd64} | |
8 | CONTAINER=${RELEASE}-${ARCH} | |
0d427d37 MP |
9 | MAX_CACHE_AGE=604800 # one week |
10 | CACHE=${SEMAPHORE_CACHE_DIR:=/tmp}/${CONTAINER}.img.tar.gz | |
11 | ||
12 | create_container() { | |
13 | # create autopkgtest LXC image; this sometimes fails with "Unable to fetch | |
14 | # GPG key from keyserver", so retry a few times | |
15 | for retry in $(seq 5); do | |
16 | sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH && break | |
17 | sleep $((retry*retry)) | |
18 | done | |
19 | ||
20 | # unconfine the container, otherwise some tests fail | |
21 | echo 'lxc.apparmor.profile = unconfined' | sudo tee -a /var/lib/lxc/$CONTAINER/config | |
22 | ||
23 | sudo lxc-start -n $CONTAINER | |
24 | ||
25 | # enable source repositories so that apt-get build-dep works | |
26 | sudo lxc-attach -n $CONTAINER -- sh -ex <<EOF | |
27 | sed 's/^deb/deb-src/' /etc/apt/sources.list >> /etc/apt/sources.list.d/sources.list | |
28 | # wait until online | |
29 | while [ -z "\$(ip route list 0/0)" ]; do sleep 1; done | |
30 | apt-get -q update | |
31 | apt-get -y dist-upgrade | |
32 | apt-get install -y eatmydata | |
33 | EOF | |
34 | sudo lxc-stop -n $CONTAINER | |
35 | ||
36 | # cache it | |
37 | sudo tar cpzf "$CACHE" /var/lib/lxc/$CONTAINER | |
38 | } | |
59273a0c MP |
39 | |
40 | # remove semaphore repos, some of them don't work and cause error messages | |
41 | sudo rm -f /etc/apt/sources.list.d/* | |
42 | ||
43 | # enable backports for latest LXC | |
44 | echo 'deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse' | sudo tee -a /etc/apt/sources.list.d/backports.list | |
45 | sudo apt-get -q update | |
46 | sudo apt-get install -y -t xenial-backports lxc | |
47 | sudo apt-get install -y python3-debian git dpkg-dev fakeroot | |
48 | ||
0d427d37 | 49 | AUTOPKGTESTDIR=$SEMAPHORE_CACHE_DIR/autopkgtest |
59273a0c MP |
50 | [ -d $AUTOPKGTESTDIR ] || git clone --quiet --depth=1 https://salsa.debian.org/ci-team/autopkgtest.git "$AUTOPKGTESTDIR" |
51 | ||
0d427d37 MP |
52 | # use cached container image, unless older than a week |
53 | if [ -e "$CACHE" ] && [ $(( $(date +%s) - $(stat -c %Y "$CACHE") )) -le $MAX_CACHE_AGE ]; then | |
54 | sudo tar -C / -xpzf "$CACHE" | |
55 | else | |
56 | create_container | |
57 | fi |