summaryrefslogtreecommitdiff
path: root/tests/integration/base/generate-base.sh
blob: 433f36ea545dae19e8daa63797fcc750c46b953d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh

# Generate a base sysroot for running the BuildStream integration tests.
#
# The sysroot is based off the Alpine Linux distribution. The script downloads
# a release of Alpine, sets up a cheap consider using `bwrap` and installs the
# packages that are needed by the integration tests, then outputs a .tar.xz
# file.

set -eux

ALPINE_ARCH=${ARCH:-x86_64}
ALPINE_BASE=http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/${ALPINE_ARCH}/alpine-minirootfs-3.7.0-${ALPINE_ARCH}.tar.gz

mkdir root

wget ${ALPINE_BASE} -O alpine-base.tar.gz

tar -x -f ./alpine-base.tar.gz -C ./root --exclude dev/\*

run() {
    # This turns the unpacked rootfs into a container using Bubblewrap.
    # The Alpine package manager (apk) calls `chroot` when running package
    # triggers so we need to enable CAP_SYS_CHROOT. We also have to fake
    # UID 0 (root) inside the container to avoid permissions errors.
    bwrap --bind ./root / --dev /dev --proc /proc --tmpfs /tmp \
          --ro-bind /etc/resolv.conf /etc/resolv.conf \
          --setenv PATH "/usr/bin:/usr/sbin:/bin:/sbin" \
          --unshare-user --uid 0 --gid 0 \
          --cap-add CAP_SYS_CHROOT \
          /bin/sh -c "$@"
}

# Enable testing repo for Tiny C Compiler package
run "echo http://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories"

# Fetch the list of Alpine packages.
run "apk update"

# There are various random errors from `apk add` to do with ownership, probably
# because of our hacked up `bwrap` container. The errors seem harmless so I am
# just ignoring them.
set +e

# Install stuff needed by all integration tests that compile C code.
#
# Note that we use Tiny C Compiler in preference to GCC. There is a huge
# size difference -- 600KB for TinyCC vs. 50MB to 100MB for GCC. TinyCC
# supports most of the ISO C99 standard, but has no C++ support at all.
run "apk add binutils libc-dev make tcc"
run "ln -s /usr/bin/tcc /usr/bin/cc"

# Install stuff for tests/integration/autotools
run "apk add autoconf automake"

# Install stuff for tests/integration/cmake
run "apk add cmake"

# Install stuff for tests/integration/pip
run "apk add python3"

set -e

# Cleanup the package cache
run "rm -R /var/cache/apk"

tar -c -v -J -f integration-tests-base.tar.xz -C root .