@@ -23,6 +23,55 @@ function build_tests {
2323 go build -o ./test_bins/journal ./examples/journal/
2424}
2525
26+ function run_in_ct {
27+ local image=$1
28+ local gover=$2
29+ local name=" go-systemd/container-tests"
30+ local cidfile=/tmp/cidfile.$$
31+ local cid
32+
33+ # Figure out Go URL, based on $gover.
34+ local prefix=" https://go.dev/dl/" filename
35+ filename=$( curl -fsSL " ${prefix} ?mode=json&include=all" |
36+ jq -r --arg Ver " go$gover " ' . | map(select(.version | contains($Ver))) | first | .files[] | select(.os == "linux" and .arch == "amd64" and .kind == "archive") | .filename' )
37+ gourl=" ${prefix}${filename} "
38+
39+ set -x
40+ docker pull " $image "
41+ docker run -i --privileged --cidfile=" $cidfile " " $image " /bin/bash -e -x << EOF
42+ if dpkg --version; then
43+ export DEBIAN_FRONTEND=noninteractive
44+ apt-get -qq update
45+ apt-get -qq install -y -o Dpkg::Use-Pty=0 \
46+ sudo build-essential curl git dbus libsystemd-dev libpam-systemd systemd-container
47+ else # Assuming Fedora
48+ dnf install -qy sudo curl gcc git dbus systemd-devel systemd-container
49+ fi
50+ # Fixup git.
51+ git config --global --add safe.directory /src
52+ # Install Go.
53+ curl -fsSL "$gourl " | tar Cxz /usr/local
54+ ln -s /usr/local/go/bin/go /usr/local/bin/go
55+ go version
56+ go env
57+ EOF
58+ cid=$( cat " $cidfile " )
59+ rm -f " $cidfile "
60+ docker commit " $cid " " $name "
61+ docker rm -f " $cid "
62+
63+ echo " Starting a container with systemd..."
64+ docker run --shm-size=2gb -d --cidfile=" $cidfile " --privileged -v " ${PWD} :/src" " $name " /sbin/init --system
65+ cid=$( cat " $cidfile " )
66+ rm -f " $cidfile "
67+ docker exec --privileged " $cid " /bin/bash -e -c ' cd /src; ./scripts/ci-runner.sh build_tests'
68+ # Wait a bit for the whole system to settle.
69+ sleep 10s
70+ docker exec --privileged " $cid " /bin/bash -e -c ' cd /src; ./scripts/ci-runner.sh run_tests'
71+ # Cleanup.
72+ docker kill " $cid "
73+ }
74+
2675function run_tests {
2776 pushd test_bins
2877 sudo -v
@@ -80,6 +129,11 @@ case "$subcommand" in
80129 build_tests
81130 ;;
82131
132+ " run_in_ct" )
133+ shift
134+ run_in_ct " $@ "
135+ ;;
136+
83137 " run_tests" )
84138 echo " Running tests..."
85139 run_tests
0 commit comments