1# Jenkins builder setup and configuration 2 3## How to set up a new jenkins builder 4 5### Contact a jenkins admin 6 7Let a jenkins admin know that you’re interested in setting up a jenkins 8build system. 9 10For a permanent build system, this should generally be a dedicated 11machine workstation or server class machine that is not generally being 12used for other purposes. The coreboot builds are very intensive. 13 14It's also best to be aware that although we don't know of any security 15issues, the jenkins-node image is run with the privileged flag which 16gives the container root access to the build machine. See 17[this article](https://blog.trendmicro.com/trendlabs-security-intelligence/why-running-a-privileged-container-in-docker-is-a-bad-idea/) 18about why this is discouraged. 19 20It's recommended that you give an admin root access on your machine so 21that they can reset it in case of a failure. This is not a requirement, 22as the system can just be disabled until someone is available to fix any 23issues. 24 25Currently active Jenkins admins: 26* Patrick Georgi: 27 * Email: [[email protected]](mailto:[email protected]) 28* Martin Roth: 29 * Email: [[email protected]](mailto:[email protected]) 30 * IRC: martinr 31 32### Build Machine requirements 33 34For a builder, we need a very fast system with lots of threads and 35plenty of RAM. The builder builds and stores the git repos and output 36in tmpfs along with the ccache save area, so if there isn't enough 37memory, the builds will slow down because of smaller ccache areas and 38can run into "out of storage space" errors. 39 40#### Current Build Machines 41 42To give an idea of what a suitable build machine might be, currently the 43coreboot project has 6 active jenkins build machines. 44 45These times are taken from the week of Feb 21 - Feb 28, 2022 46 47* Congenialbuilder - 128 threads, 256GiB RAM 48 * Coverity Builds, Toolchain builds, Scanbuild-builds 49 * Fastest Passing coreboot gerrit build: 6 min, 47 sec 50 * Slowest Passing coreboot gerrit build: 14 min 51 52* Gleefulbuilder - 64 threads, 64GiB RAM 53 * Fastest Passing coreboot gerrit build: 10 min 54 * Slowest Passing coreboot gerrit build: 46 min 55 56* Fabulousbuilder - 64 threads, 64GiB RAM 57 * Fastest Passing coreboot gerrit build: 7 min, 56 sec 58 * Slowest Passing coreboot gerrit build: 56 min (No ccache) 59 60* Ultron (9elements) - 48 threads, 128GiB RAM 61 * Fastest Passing coreboot gerrit build: 12 min 62 * Slowest Passing coreboot gerrit build: 58 min 63 64* Bob - 64 threads, 128GiB RAM 65 * Fastest Passing coreboot gerrit build: 7 min 66 * Slowest Passing coreboot gerrit build: 34 min 67 68* Pokeybuilder - 32 Threads, 96GiB RAM 69 * Runs coreboot-checkpatch and other lighter builds 70 71 72### Jenkins Builds 73 74There are a number of builds handled by the coreboot jenkins builders, 75for a number of different projects - coreboot, flashrom, memtest86+, 76em100, etc. Many of these have builders for their current main branch 77as well as Gerrit and [Coverity](coverity.md) builds. 78 79 80#### Long builds - over 90 minutes on congenialbuilder 81There are a few builds that take a long time even on the fastest 82machines. These tasks run overnight in the US timezones. 83* coreboot_coverity - 9 to 12 hours 84* coreboot_scanbuild - ~3 hours 85* coreboot_toolchain - ~1 hour 45 minutes 86 87 88#### All builds 89 90You can see all the builds in the main jenkins interface: 91[https://qa.coreboot.org/](https://qa.coreboot.org/) 92 93Most of the time on the builders is taken up by the coreboot main and 94coreboot gerrit builds. 95 96```{toctree} 97:maxdepth: 1 98 99coreboot gerrit build <https://qa.coreboot.org/job/coreboot-gerrit/> 100``` 101([Time trend](https://qa.coreboot.org/job/coreboot-gerrit/buildTimeTrend)) 102 103 104```{toctree} 105:maxdepth: 1 106 107coreboot main build <https://qa.coreboot.org/job/coreboot/> 108``` 109 ([Time trend](https://qa.coreboot.org/job/coreboot/buildTimeTrend)) 110 111 112### Stress test the machine 113 114Test the machine to make sure that building won't stress the hardware 115too much. Install stress-ng, then run the stress test for at least an 116hour. 117 118On a system with 32 cores, it was tested with this command: 119 120```sh 121stress-ng --cpu 20 --io 6 --vm 6 --vm-bytes 1G --verify --metrics-brief -t 60m 122``` 123 124You can watch the temperature with the sensors package or with ‘acpi -t’ 125if your machine supports that. 126 127You can check for thermal throttling by running this command and seeing 128if the values go down on any of the cores after it's been running for a 129while. 130 131```sh 132while [ true ]; do clear; cat /proc/cpuinfo | grep 'cpu MHz' ; sleep 1; done 133``` 134 135If the machine throttles or resets, you probably need to upgrade the 136cooling system. 137 138 139## jenkins-server docker installation 140 141 142### Manual Installation 143 144If you’ve met all the above requirements, and an admin has agreed to set 145up the builder in jenkins, you’re ready to go on to the next steps. 146 147 148### Set up your network so jenkins can talk to the container 149 150Expose a local port through any firewalls you might have on your router. 151This would generally be in the port forwarding section, and you'd just 152forward a port (typically 49151) from the internet directly to the 153builder’s IP address. 154 155You might also want to set up a port to forward to port 22 on your 156machine and set up openssh so you or the jenkins admins can manage 157the machine remotely (if you allow them). 158 159 160### Install and set up docker 161 162Install docker by following [the 163directions](https://docs.docker.com/engine/install/) on the docker site. 164These instructions keep changing, so just check the latest information. 165 166 167### Set up the system for the jenkins builder 168 169As a regular user - *Not root*, run: 170 171```sh 172sudo mkdir -p ${COREBOOT_JENKINS_CACHE_DIR} 173sudo mkdir -p ${COREBOOT_JENKINS_CCACHE_DIR} 174sudo chown $(whoami):$(whoami) ${COREBOOT_JENKINS_CCACHE_DIR} 175sudo chown $(whoami):$(whoami) ${COREBOOT_JENKINS_CACHE_DIR} 176wget http://www.dediprog.com/save/78.rar/to/EM100Pro.rar 177mv EM100Pro.rar ${COREBOOT_JENKINS_CACHE_DIR} 178``` 179 180 181#### Set up environment variables 182 183To make configuration and the later commands easier, these should go in 184your shell's .rc file. Note that you only need to set them if you're 185using something other than the default. 186 187```sh 188# Set the port used on your machine to connect to jenkins. 189export COREBOOT_JENKINS_PORT=49151 190 191# Set the revision of the container from [docker hub](https://hub.docker.com/repository/docker/coreboot/coreboot-sdk) 192export DOCKER_COMMIT=2021-09-23_b0d87f753c 193 194# Set the location of where the jenkins cache directory will be. 195export COREBOOT_JENKINS_CACHE_DIR="/srv/docker/coreboot-builder/cache" 196 197# Set the name of the container 198export COREBOOT_JENKINS_CONTAINER="coreboot_jenkins" 199``` 200 201Make sure any variables needed are set in your environment before 202continuing to the next step. 203 204 205### Using the Makefile for docker installation 206 207From the coreboot directory, run 208 209```sh 210make -C util/docker help 211``` 212 213This will show you the available targets and variables needed: 214 215```text 216Commands for working with docker images: 217 coreboot-sdk - Build coreboot-sdk container 218 upload-coreboot-sdk - Upload coreboot-sdk to hub.docker.com 219 coreboot-jenkins-node - Build coreboot-jenkins-node container 220 upload-coreboot-jenkins-node - Upload coreboot-jenkins-node to hub.docker.com 221 doc.coreboot.org - Build doc.coreboot.org container 222 clean-coreboot-containers - Remove all docker coreboot containers 223 clean-coreboot-images - Remove all docker coreboot images 224 docker-clean - Remove docker coreboot containers & images 225 226Commands for using docker images 227 docker-build-coreboot - Build coreboot under coreboot-sdk 228 <BUILD_CMD=target> 229 docker-abuild - Run abuild under coreboot-sdk 230 <ABUILD_ARGS='-a -B'> 231 docker-what-jenkins-does - Run 'what-jenkins-does' target 232 docker-shell - Bash prompt in coreboot-jenkins-node 233 <USER=root or USER=coreboot> 234 docker-jenkins-server - Run coreboot-jenkins-node image (for server) 235 docker-jenkins-attach - Open shell in running jenkins server 236 docker-build-docs - Build the documentation 237 docker-livehtml-docs - Run sphinx-autobuild 238 239Variables: 240 COREBOOT_JENKINS_PORT=49151 241 COREBOOT_JENKINS_CACHE_DIR=/srv/docker/coreboot-builder/cache 242 COREBOOT_JENKINS_CONTAINER=coreboot_jenkins 243 COREBOOT_IMAGE_TAG=f2741aa632f 244 DOCKER_COMMIT=65718760fa 245``` 246 247 248### Install the coreboot jenkins builder 249 250```sh 251make -C util/docker docker-jenkins-server 252``` 253 254Your installation is complete on your side. 255 256### Tell the Admins that the machine is set up 257Let the admins know that the builder is set up so they can set up the 258machine profile on qa.coreboot.org. 259 260They need to know: 261* Your external IP address or domain name. If you don’t have a static 262 IP, make sure you have a dynamic dns hostname configured. 263* The port on your machine and firewall that’s exposed for jenkins: 264 `$COREBOOT_JENKINS_PORT` 265* The core count of the machine. 266* How much memory is available on the machine. This helps determine 267 the amount of memory used for ccache. 268 269 270### First build 271On the first build after a machine is reset, it will frequently take 272an hour to do the entire what-jenkins-does build while the ccache 273is getting filled up and the entire coreboot repo gets downloaded. As 274the ccache gets populated, the build time will drop. 275 276 277## Additional Information 278 279 280### How to log in to the docker instance for debugging 281 282```sh 283make -C util/docker docker-jenkins-attach 284su coreboot 285cd ~/slave-root/workspace 286bash 287``` 288 289 290WARNING: This should not be used to make changes to the build system, 291but just to debug issues. Changes to the build system image are highly 292discouraged as it leads to situations where patches can pass the build 293testing on one builder and fail on another builder. Any changes that are 294made in the image will be lost on the next update, so if you 295accidentally change something, you can remove the containers and images, 296then update to get a fresh installation. 297 298 299### How to download containers/images for a fresh installation and remove old containers 300 301To delete the old containers & images: 302 303```sh 304docker stop $COREBOOT_JENKINS_CONTAINER 305docker rm $COREBOOT_JENKINS_CONTAINER 306docker images # lists all existing images 307docker rmi XXXX # Use the image ID found in the above command. 308``` 309 310To get and run the new coreboot-jenkins image, change the value in the 311`DOCKER_COMMIT` variable to the new image value. 312 313```sh 314make -C util/docker docker-jenkins-server 315``` 316 317#### Getting ready to push the docker images 318 319Set up an account on hub.docker.com 320 321Get an admin to add the account to the coreboot team on hub.docker.com 322 323[https://hub.docker.com/u/coreboot/dashboard/teams/?team=owners](https://hub.docker.com/u/coreboot/dashboard/teams/?team=owners) 324 325Make sure your credentials are configured on your host machine by 326running 327 328```sh 329docker login 330``` 331 332This will prompt you for your docker username, password, and your email 333address, and write out to ~/.docker/config.json. Without this file, you 334won’t be able to push the images. 335 336#### Updating the Dockerfiles 337 338The coreboot-sdk Dockerfile will need to be updated when any additional 339dependencies are added. Both the coreboot-sdk and the 340coreboot-jenkins-node Dockerfiles will need to be updated to the new 341version number and git commit id anytime the toolchain is updated. Both 342files are stored in the coreboot repo under coreboot/util/docker. 343 344Read the [dockerfile best practices](https://docs.docker.com/v1.8/articles/dockerfile_best-practices/) 345page before updating the files. 346 347#### Rebuilding the coreboot-sdk docker image to update the toolchain 348 349```sh 350make -C util/docker coreboot-sdk 351``` 352 353This takes a relatively long time. 354 355#### Test the coreboot-sdk docker image 356 357There are two methods of running the docker image - interactively as a 358shell, or doing the build directly. Running interactively as a shell is 359useful for early testing, because it allows you to update the image 360(without any changes getting saved) and re-test builds. This saves the 361time of having to rebuild the image for every issue you find. 362 363#### Running the docker image interactively 364 365Run: 366 367```sh 368make -C util/docker docker-jenkins-server 369make -C util/docker docker-jenkins-attach 370``` 371 372#### Running the build directly 373 374From the coreboot directory: 375 376```sh 377make -C util/docker docker-build-coreboot 378``` 379 380You’ll also want to test building the other projects and payloads: 381ChromeEC, flashrom, memtest86+, em100, Grub2, SeaBIOS, iPXE, coreinfo, 382nvramcui, tint... 383 384#### Pushing the coreboot-sdk image to hub.docker.com for use 385 386When you’re satisfied with the testing, push the coreboot-sdk image to 387the hub.docker.com 388 389```sh 390make -C util/docker upload-coreboot-sdk 391``` 392 393#### Building and pushing the coreboot-jenkins-node docker image 394 395This docker image is pretty simple, so there’s not really any testing 396that needs to be done. 397 398```sh 399make -C util/docker coreboot-jenkins-node 400make -C util/docker upload-coreboot-jenkins-node 401``` 402 403### Coverity Setup 404 405To run coverity jobs, the builder needs to have the tools available, and 406to be marked as a coverity builder. 407 408 409#### Set up the Coverity tools 410 411Download the Linux-64 coverity build tool and decompress it into your 412cache directory as defined by the `$COREBOOT_JENKINS_CACHE_DIR` variable 413on the jenkins server. 414 415[https://scan.coverity.com/download](https://scan.coverity.com/download) 416 417Rename the directory from its original name 418(cov-analysis-linux64-7.7.0.4) to ‘coverity’, or better, create a 419symlink: 420 421```sh 422ln -s cov-analysis-linux64-7.7.0.4 coverity 423``` 424 425 426Let the admins know that the ‘coverity’ label can be added to the 427builder. 428