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