reproducible_build_service.sh 12.7 KB
Newer Older
1
#!/bin/bash
2
# vim: set noexpandtab:
3

4
# Copyright © 2017-2018 Holger Levsen (holger@layer-acht.org)
5
# released under the GPLv=2
6

7
set -e
8

9 10 11 12
# those should be global variables
NODE1=""
NODE2=""

13 14 15 16
#
# this function defines which builds take place on which nodes
#
choose_nodes() {
17
	case $1 in
18 19 20 21 22
		#
		# amd64, i386 and arm64 nodes are chosen in a way that one build always runs
		# on a node running in the future, the other on a node with correct date.
		# armhf builds are distributed by the build capacity of the nodes, see below.
		#
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
		amd64_1)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build5-amd64 ;;
		amd64_2)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build1-amd64 ;;
		amd64_3)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build15-amd64 ;;
		amd64_4)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build1-amd64 ;;
		amd64_5)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build5-amd64 ;;
		amd64_6)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build11-amd64 ;;
		amd64_7)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build15-amd64 ;;
		amd64_8)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build11-amd64 ;;
		amd64_9)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build5-amd64 ;;
		amd64_10)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build1-amd64 ;;
		amd64_11)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build15-amd64 ;;
		amd64_12)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build1-amd64 ;;
		amd64_13)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build5-amd64 ;;
		amd64_14)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build11-amd64 ;;
		amd64_15)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build15-amd64 ;;
		amd64_16)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build11-amd64 ;;
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
		amd64_17)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build5-amd64 ;;
		amd64_18)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build1-amd64 ;;
		amd64_19)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build15-amd64 ;;
		amd64_20)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build1-amd64 ;;
		amd64_21)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build5-amd64 ;;
		amd64_22)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build11-amd64 ;;
		amd64_23)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build15-amd64 ;;
		amd64_24)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build11-amd64 ;;
		amd64_25)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build5-amd64 ;;
		amd64_26)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build1-amd64 ;;
		amd64_27)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build15-amd64 ;;
		amd64_28)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build1-amd64 ;;
		amd64_29)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build5-amd64 ;;
		amd64_30)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build11-amd64 ;;
		amd64_31)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build15-amd64 ;;
		amd64_32)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build11-amd64 ;;
55 56 57 58 59 60 61 62
		#amd64_33)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build5-amd64 ;;
		#amd64_34)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build1-amd64 ;;
		#amd64_35)	NODE1=profitbricks-build1-amd64		NODE2=profitbricks-build15-amd64 ;;
		#amd64_36)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build1-amd64 ;;
		#amd64_37)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build5-amd64 ;;
		#amd64_38)	NODE1=profitbricks-build5-amd64		NODE2=profitbricks-build11-amd64 ;;
		#amd64_39)	NODE1=profitbricks-build11-amd64	NODE2=profitbricks-build15-amd64 ;;
		#amd64_40)	NODE1=profitbricks-build15-amd64	NODE2=profitbricks-build11-amd64 ;;
63 64 65 66 67 68 69 70 71 72 73 74
		i386_1)		NODE1=profitbricks-build2-i386	NODE2=profitbricks-build6-i386 ;;
		i386_2)		NODE1=profitbricks-build6-i386	NODE2=profitbricks-build2-i386 ;;
		i386_3)		NODE1=profitbricks-build2-i386	NODE2=profitbricks-build16-i386 ;;
		i386_4)		NODE1=profitbricks-build16-i386	NODE2=profitbricks-build2-i386 ;;
		i386_5)		NODE1=profitbricks-build12-i386	NODE2=profitbricks-build6-i386 ;;
		i386_6)		NODE1=profitbricks-build6-i386	NODE2=profitbricks-build12-i386 ;;
		i386_7)		NODE1=profitbricks-build12-i386	NODE2=profitbricks-build16-i386 ;;
		i386_8)		NODE1=profitbricks-build16-i386	NODE2=profitbricks-build12-i386 ;;
		i386_9)		NODE1=profitbricks-build2-i386	NODE2=profitbricks-build6-i386 ;;
		i386_10)	NODE1=profitbricks-build6-i386	NODE2=profitbricks-build2-i386 ;;
		i386_11)	NODE1=profitbricks-build2-i386	NODE2=profitbricks-build16-i386 ;;
		i386_12)	NODE1=profitbricks-build16-i386	NODE2=profitbricks-build2-i386 ;;
75 76 77 78 79 80 81 82 83 84 85 86
		i386_13)	NODE1=profitbricks-build12-i386	NODE2=profitbricks-build6-i386 ;;
		i386_14)	NODE1=profitbricks-build6-i386	NODE2=profitbricks-build12-i386 ;;
		i386_15)	NODE1=profitbricks-build12-i386	NODE2=profitbricks-build16-i386 ;;
		i386_16)	NODE1=profitbricks-build16-i386	NODE2=profitbricks-build12-i386 ;;
		i386_17)	NODE1=profitbricks-build2-i386	NODE2=profitbricks-build6-i386 ;;
		i386_18)	NODE1=profitbricks-build6-i386	NODE2=profitbricks-build2-i386 ;;
		i386_19)	NODE1=profitbricks-build2-i386	NODE2=profitbricks-build16-i386 ;;
		i386_20)	NODE1=profitbricks-build16-i386	NODE2=profitbricks-build2-i386 ;;
		i386_21)	NODE1=profitbricks-build12-i386	NODE2=profitbricks-build6-i386 ;;
		i386_22)	NODE1=profitbricks-build6-i386	NODE2=profitbricks-build12-i386 ;;
		i386_23)	NODE1=profitbricks-build12-i386	NODE2=profitbricks-build16-i386 ;;
		i386_24)	NODE1=profitbricks-build16-i386	NODE2=profitbricks-build12-i386 ;;
87
		arm64_1)	NODE1=codethink-sled9-arm64		NODE2=codethink-sled10-arm64 ;;
88 89
		arm64_2)	NODE1=codethink-sled9-arm64		NODE2=codethink-sled12-arm64 ;;
		arm64_3)	NODE1=codethink-sled9-arm64		NODE2=codethink-sled14-arm64 ;;
90 91
		arm64_4)	NODE1=codethink-sled9-arm64		NODE2=codethink-sled16-arm64 ;;
		arm64_5)	NODE1=codethink-sled10-arm64	NODE2=codethink-sled9-arm64 ;;
92
		arm64_6)	NODE1=codethink-sled10-arm64	NODE2=codethink-sled11-arm64 ;;
93 94 95
		arm64_7)	NODE1=codethink-sled10-arm64	NODE2=codethink-sled13-arm64 ;;
		arm64_8)	NODE1=codethink-sled10-arm64	NODE2=codethink-sled15-arm64 ;;
		arm64_9)	NODE1=codethink-sled11-arm64	NODE2=codethink-sled10-arm64 ;;
96
		arm64_10)	NODE1=codethink-sled11-arm64	NODE2=codethink-sled12-arm64 ;;
97 98 99 100
		arm64_11)	NODE1=codethink-sled11-arm64	NODE2=codethink-sled14-arm64 ;;
		arm64_12)	NODE1=codethink-sled11-arm64	NODE2=codethink-sled16-arm64 ;;
		arm64_13)	NODE1=codethink-sled12-arm64	NODE2=codethink-sled9-arm64 ;;
		arm64_14)	NODE1=codethink-sled12-arm64	NODE2=codethink-sled11-arm64 ;;
101
		arm64_15)	NODE1=codethink-sled12-arm64	NODE2=codethink-sled13-arm64 ;;
102
		arm64_16)	NODE1=codethink-sled12-arm64	NODE2=codethink-sled15-arm64 ;;
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
		arm64_17)	NODE1=codethink-sled13-arm64	NODE2=codethink-sled10-arm64 ;;
		arm64_18)	NODE1=codethink-sled13-arm64	NODE2=codethink-sled12-arm64 ;;
		arm64_19)	NODE1=codethink-sled13-arm64	NODE2=codethink-sled14-arm64 ;;
		arm64_20)	NODE1=codethink-sled13-arm64	NODE2=codethink-sled16-arm64 ;;
		arm64_21)	NODE1=codethink-sled14-arm64	NODE2=codethink-sled9-arm64 ;;
		arm64_22)	NODE1=codethink-sled14-arm64	NODE2=codethink-sled11-arm64 ;;
		arm64_23)	NODE1=codethink-sled14-arm64	NODE2=codethink-sled13-arm64 ;;
		arm64_24)	NODE1=codethink-sled14-arm64	NODE2=codethink-sled15-arm64 ;;
		arm64_25)	NODE1=codethink-sled15-arm64	NODE2=codethink-sled10-arm64 ;;
		arm64_26)	NODE1=codethink-sled15-arm64	NODE2=codethink-sled12-arm64 ;;
		arm64_27)	NODE1=codethink-sled15-arm64	NODE2=codethink-sled14-arm64 ;;
		arm64_28)	NODE1=codethink-sled15-arm64	NODE2=codethink-sled16-arm64 ;;
		arm64_29)	NODE1=codethink-sled16-arm64	NODE2=codethink-sled9-arm64 ;;
		arm64_30)	NODE1=codethink-sled16-arm64	NODE2=codethink-sled11-arm64 ;;
		arm64_31)	NODE1=codethink-sled16-arm64	NODE2=codethink-sled13-arm64 ;;
		arm64_32)	NODE1=codethink-sled16-arm64	NODE2=codethink-sled15-arm64 ;;
119
		# to choose new armhf jobs:
120
            #   for i in cb3a bbx15 cbxi4pro0 ff2a ff2b ff64a jtk1a jtk1b odxu4a odxu4b odxu4c odu3a opi2a opi2b opi2c p64b p64c wbq0 cbxi4a cbxi4b ff4a jtx1a jtx1b jtx1c; do echo "$i: " ; grep NODE1 bin/reproducible_build_service.sh|grep armhf|grep $i-armhf ; done
121 122 123 124 125
	        #       6 jobs for quad-cores with 4 gb ram
	        #       4 jobs for octo-cores with 2 gb ram
	        #       4 jobs for hexa-cores with 2 gb ram
	        #       4 jobs for quad-cores with 2 gb ram
	        #       4 jobs for dual-cores with 2 gb ram
126 127 128
		#
		# Don't forget to update README with the number of builders…!
		#
129 130 131 132
		armhf_1)	NODE1=bbx15-armhf-rb		NODE2=jtx1a-armhf-rb ;;
		armhf_2)	NODE1=bbx15-armhf-rb		NODE2=ff4a-armhf-rb ;;
		armhf_3)	NODE1=cb3a-armhf-rb			NODE2=jtx1a-armhf-rb ;;
		armhf_4)	NODE1=cb3a-armhf-rb			NODE2=jtx1c-armhf-rb ;;
133 134 135
		armhf_5)	NODE1=cbxi4a-armhf-rb		NODE2=p64c-armhf-rb ;;
		armhf_6)	NODE1=jtx1a-armhf-rb		NODE2=ff4a-armhf-rb ;;
		armhf_7)	NODE1=ff4a-armhf-rb			NODE2=cbxi4b-armhf-rb ;;
136 137 138 139 140 141 142 143 144
		armhf_8)	NODE1=ff64a-armhf-rb		NODE2=cbxi4a-armhf-rb ;;
		armhf_9)	NODE1=ff64a-armhf-rb		NODE2=cbxi4pro0-armhf-rb ;;
		armhf_10)	NODE1=cbxi4pro0-armhf-rb	NODE2=ff4a-armhf-rb ;;
		armhf_11)	NODE1=cbxi4pro0-armhf-rb	NODE2=jtx1a-armhf-rb ;;
		armhf_12)	NODE1=ff2a-armhf-rb			NODE2=wbq0-armhf-rb ;;
		armhf_13)	NODE1=ff2a-armhf-rb			NODE2=p64c-armhf-rb ;;
		armhf_14)	NODE1=ff2b-armhf-rb			NODE2=p64b-armhf-rb ;;
		armhf_15)	NODE1=ff2b-armhf-rb			NODE2=opi2c-armhf-rb ;;
		armhf_16)	NODE1=jtx1b-armhf-rb		NODE2=p64b-armhf-rb ;;
145 146 147 148
		armhf_17)	NODE1=jtx1b-armhf-rb		NODE2=jtk1b-armhf-rb ;;
		armhf_18)	NODE1=jtk1b-armhf-rb		NODE2=opi2c-armhf-rb ;;
		armhf_19)	NODE1=jtk1b-armhf-rb		NODE2=opi2b-armhf-rb ;;
		armhf_20)	NODE1=odxu4a-armhf-rb		NODE2=jtk1b-armhf-rb ;;
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
		armhf_21)	NODE1=odxu4a-armhf-rb		NODE2=opi2a-armhf-rb ;;
		armhf_22)	NODE1=odxu4b-armhf-rb		NODE2=odu3a-armhf-rb ;;
		armhf_24)	NODE1=odxu4c-armhf-rb		NODE2=jtx1c-armhf-rb ;;
		armhf_26)	NODE1=odu3a-armhf-rb		NODE2=odxu4a-armhf-rb ;;
		armhf_27)	NODE1=odu3a-armhf-rb		NODE2=jtx1b-armhf-rb ;;
		armhf_28)	NODE1=opi2a-armhf-rb		NODE2=odxu4c-armhf-rb ;;
		armhf_29)	NODE1=opi2a-armhf-rb		NODE2=cbxi4b-armhf-rb ;;
		armhf_30)	NODE1=opi2b-armhf-rb		NODE2=odxu4c-armhf-rb ;;
		armhf_31)	NODE1=opi2b-armhf-rb		NODE2=jtx1b-armhf-rb ;;
		armhf_32)	NODE1=opi2c-armhf-rb		NODE2=odxu4b-armhf-rb ;;
		armhf_33)	NODE1=opi2c-armhf-rb		NODE2=ff2a-armhf-rb ;;
		armhf_34)	NODE1=p64b-armhf-rb			NODE2=odxu4b-armhf-rb ;;
		armhf_35)	NODE1=p64b-armhf-rb			NODE2=ff2a-armhf-rb ;;
		armhf_36)	NODE1=p64c-armhf-rb			NODE2=ff2b-armhf-rb ;;
		armhf_37)	NODE1=p64c-armhf-rb			NODE2=cbxi4pro0-armhf-rb ;;
		armhf_38)	NODE1=wbq0-armhf-rb			NODE2=ff2b-armhf-rb ;;
		armhf_39)	NODE1=wbq0-armhf-rb			NODE2=cbxi4a-armhf-rb ;;
		armhf_40)	NODE1=cbxi4a-armhf-rb		NODE2=jtx1b-armhf-rb ;;
		armhf_41)	NODE1=cbxi4a-armhf-rb		NODE2=cb3a-armhf-rb ;;
		armhf_42)	NODE1=cbxi4b-armhf-rb		NODE2=bbx15-armhf-rb ;;
		armhf_43)	NODE1=cbxi4b-armhf-rb		NODE2=cb3a-armhf-rb ;;
		armhf_44)	NODE1=cbxi4b-armhf-rb		NODE2=ff64a-armhf-rb ;;
		armhf_45)	NODE1=ff4a-armhf-rb			NODE2=jtk1a-armhf-rb ;;
		armhf_46)	NODE1=ff4a-armhf-rb			NODE2=jtx1c-armhf-rb ;;
		armhf_47)	NODE1=jtx1a-armhf-rb		NODE2=cbxi4b-armhf-rb ;;
		armhf_48)	NODE1=jtx1a-armhf-rb		NODE2=odxu4a-armhf-rb ;;
		armhf_49)	NODE1=jtx1b-armhf-rb		NODE2=bbx15-armhf-rb ;;
		armhf_50)	NODE1=jtx1c-armhf-rb		NODE2=jtk1a-armhf-rb ;;
		armhf_51)	NODE1=jtx1c-armhf-rb		NODE2=cbxi4a-armhf-rb ;;
		armhf_52)	NODE1=jtx1c-armhf-rb		NODE2=odu3a-armhf-rb ;;
		armhf_53)	NODE1=jtk1a-armhf-rb		NODE2=wbq0-armhf-rb ;;
		armhf_54)	NODE1=jtk1a-armhf-rb		NODE2=ff64a-armhf-rb ;;
181
		*)		NODE1=undefined
182 183 184
				;;
	esac
}
185

186
startup_workers() {
187 188 189
	#
	# loop through all archs
	#
190 191
	for ARCH in amd64 i386 arm64 armhf ; do
		case $ARCH in
192 193
			amd64)	MAX=32 ;;
			i386)	MAX=16 ;;
194
			arm64)	MAX=32 ;;
195
			armhf)	MAX=59 ;;
196 197
			*)	;;
		esac
198 199 200
		#
		# startup as many workers as defined above
		#
201
		for i in $(seq 1 $MAX) ; do
202
			#
203
		        # sleep up to 2.3 seconds (additionally to the random sleep reproducible_build.sh does anyway)
204
			#
205
		        /bin/sleep $(echo "scale=1 ; $(shuf -i 1-23 -n 1)/10" | bc )
206

207 208 209
			#
			# continue loop if the worker to be started is already running
			#
210
			WORKER_NAME=${ARCH}_$i
211
			WORKER_BIN=/srv/jenkins/bin/reproducible_worker.sh
212
			RUNNING=$(ps fax|grep -v grep|grep "$WORKER_BIN $WORKER_NAME" 2>/dev/null||true)
213
			if [ ! -z "$RUNNING" ] ; then
214 215 216 217
				echo "$(date --utc) - '$(basename $WORKER_BIN) $WORKER_NAME' already running, thus moving on to the next."
				continue
			fi

218 219 220 221
			#
			# actually start the worker
			#
			choose_nodes $WORKER_NAME
222 223 224 225 226 227
			if [ "$NODE1" != "undefined" ] ; then
				BUILD_BASE=/var/lib/jenkins/userContent/reproducible/debian/build_service/$WORKER_NAME
				mkdir -p $BUILD_BASE
				echo "$(date --utc) - Starting $WORKER_NAME"
				$WORKER_BIN $WORKER_NAME $NODE1 $NODE2 >$BUILD_BASE/worker.log 2>&1 &
			fi
228
		done
229
	done
230
}
231

232
#
233
# main, keep running forever…
234
#
235 236 237 238 239 240 241 242 243
while true ; do
	#
	# this is all we do
	#
	startup_workers
	#
	# now sleep, but allow wakeup calls
	#
	set +e
244
	sleep 133.7m
245 246
	set -e
done
247

248