aboutsummaryrefslogtreecommitdiff
path: root/tcwg-base/tcwg-llvmbot/start.sh
blob: 18e5fa507d5c0b04668e5df6cf307f22b7378a10 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash

set -ex

image="$1"
buildmaster="$2"
slavename="$3"
password="$4"

usage ()
{
    echo "$@"
    cat <<EOF
Usage: $0 <buildmaster> <buildslave> <password>
	E.g., $0 lab.llvm.org:9994 linaro-apm-05 PASSWORD
EOF
    exit 1
}

if groups 2>/dev/null | grep -q docker; then
    # Run docker straight up if $USER is in "docker" group.
    DOCKER="docker"
else
    # Fallback to sudo otherwise.
    DOCKER="sudo docker"
fi

case "$buildmaster" in
    "normal")
	mastername="normal"
	masterurl="lab.llvm.org:9990"
	;;
    "silent")
	mastername="silent"
	masterurl="lab.llvm.org:9994"
	;;
    *)
	mastername="custom"
	masterurl="$buildmaster"
esac

case "$mastername:$slavename:$(hostname):$image" in
    # No restrictions for custom masters:
    custom:*:*:*) ;;
    # Almost no restrictions for the silent master:
    silent:*:linaro-armv8-*:*) ;;
    silent:*:r*-a*:*) ;;
    # Restrictions for the normal master:
    normal:linaro-armv8-*-arm-*:linaro-armv8-*:*-armhf-*) ;;
    normal:linaro-armv8-*-aarch64-*:linaro-armv8-*:*-arm64-*) ;;
    normal:*:r*-a*:*-arm64-*) ;;
    *)
	usage "ERROR: Wrong mastername:slavename:hostname:image combination: $mastername:$slavename:$(hostname):$image"
	;;
esac

# Set relative CPU weight of containers running silent bots to 1/20th of
# normal containers.  We want to run a full set of silent bots for
# troubleshooting purposes, but don't want to waste a lot of CPU cycles.
case "$mastername" in
    "silent") cpu_shares=50 ;;
    *) cpu_shares=1000 ;;
esac

case "$slavename" in
    linaro-armv8-*)
	# Use 64G out of 128G.
	memlimit="64"
	;;
    *)
	# Use at most 30G or 90% of all RAM.
	memlimit=$(($(free -g | awk '/^Mem/ { print $2 }') * 9 / 10))
	if [ "$memlimit" -gt "30" ]; then
	    memlimit="30"
	fi
	;;
esac

case "$slavename" in
    *-lld) pids_limit="15000" ;;
    *) pids_limit="5000" ;;
esac

# IPC_LOCK is required for some implementations of ssh-agent (e.g., MATE's).
# SYS_PTRACE is required for debugger work.
# seccomp:unconfined is required to disable ASLR for sanitizer tests.
caps="--cap-add=IPC_LOCK --cap-add=SYS_PTRACE --security-opt seccomp:unconfined"

$DOCKER run --name=$mastername-$slavename --hostname=$mastername-$slavename --restart=unless-stopped -dt -p 22 --cpu-shares=$cpu_shares --memory=${memlimit}G --pids-limit=$pids_limit $caps "$image" "$masterurl" "$slavename" "$password"