aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/repo-install-test.sh
blob: a93fb2307ac60418114c0a150f3bfbf41a383825 (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
#!/bin/sh
. "$(dirname "$0")/common.sh"
docker_images_require "debian-repo-install-test"

[ -z "$FEED" ] && FEED="nightly"
CONTAINER="repo-install-test-$FEED"

# Try to run "systemctl status" 10 times, kill the container on failure
check_if_systemd_is_running() {
	for i in $(seq 1 10); do
		sleep 1
		if docker exec "$CONTAINER" systemctl status; then
			return
		fi
	done

	echo "ERROR: systemd is not running properly."
	docker container kill "$CONTAINER"
	exit 1
}

# Kill already running container
if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER" 2> /dev/null)" = "true" ]; then
	docker container kill "$CONTAINER"
	sleep 1
fi

# Run the container
# * This does not output anything, for debugging add -it and remove &.
# * /run, /tmp, cgroups, SYS_ADMIN: needed for systemd
# * SYS_NICE: needed for changing CPUScheduling{Policy,Priority} (osmo-bts systemd service files)
docker run	--rm \
		-v "$OSMO_CI_DIR/scripts/repo-install-test:/repo-install-test:ro" \
		-v "$OSMO_CI_DIR/_repo_install_test_data:/data" \
		--name "$CONTAINER" \
		-e FEED="$FEED" \
		-e container=docker \
		--tmpfs /run \
		--tmpfs /tmp \
		-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
		--cap-add SYS_ADMIN \
		--cap-add SYS_NICE \
		"$USER/debian-repo-install-test" \
		/lib/systemd/systemd &
check_if_systemd_is_running

# Run the test script
docker exec "$CONTAINER" /repo-install-test/run-inside-docker.sh
ret="$?"

# Interactive shell
if [ -n "$INTERACTIVE" ]; then
	docker exec -it "$CONTAINER" bash
fi

docker container kill "$CONTAINER"

exit $ret