1*ff41da50SThomas HuthJobs on Custom Runners
2*ff41da50SThomas Huth======================
3*ff41da50SThomas Huth
4*ff41da50SThomas HuthBesides the jobs run under the various CI systems listed before, there
5*ff41da50SThomas Huthare a number additional jobs that will run before an actual merge.
6*ff41da50SThomas HuthThese use the same GitLab CI's service/framework already used for all
7*ff41da50SThomas Huthother GitLab based CI jobs, but rely on additional systems, not the
8*ff41da50SThomas Huthones provided by GitLab as "shared runners".
9*ff41da50SThomas Huth
10*ff41da50SThomas HuthThe architecture of GitLab's CI service allows different machines to
11*ff41da50SThomas Huthbe set up with GitLab's "agent", called gitlab-runner, which will take
12*ff41da50SThomas Huthcare of running jobs created by events such as a push to a branch.
13*ff41da50SThomas HuthHere, the combination of a machine, properly configured with GitLab's
14*ff41da50SThomas Huthgitlab-runner, is called a "custom runner".
15*ff41da50SThomas Huth
16*ff41da50SThomas HuthThe GitLab CI jobs definition for the custom runners are located under::
17*ff41da50SThomas Huth
18*ff41da50SThomas Huth  .gitlab-ci.d/custom-runners.yml
19*ff41da50SThomas Huth
20*ff41da50SThomas HuthCustom runners entail custom machines.  To see a list of the machines
21*ff41da50SThomas Huthcurrently deployed in the QEMU GitLab CI and their maintainers, please
22*ff41da50SThomas Huthrefer to the QEMU `wiki <https://wiki.qemu.org/AdminContacts>`__.
23*ff41da50SThomas Huth
24*ff41da50SThomas HuthMachine Setup Howto
25*ff41da50SThomas Huth-------------------
26*ff41da50SThomas Huth
27*ff41da50SThomas HuthFor all Linux based systems, the setup can be mostly automated by the
28*ff41da50SThomas Huthexecution of two Ansible playbooks.  Create an ``inventory`` file
29*ff41da50SThomas Huthunder ``scripts/ci/setup``, such as this::
30*ff41da50SThomas Huth
31*ff41da50SThomas Huth  fully.qualified.domain
32*ff41da50SThomas Huth  other.machine.hostname
33*ff41da50SThomas Huth
34*ff41da50SThomas HuthYou may need to set some variables in the inventory file itself.  One
35*ff41da50SThomas Huthvery common need is to tell Ansible to use a Python 3 interpreter on
36*ff41da50SThomas Huththose hosts.  This would look like::
37*ff41da50SThomas Huth
38*ff41da50SThomas Huth  fully.qualified.domain ansible_python_interpreter=/usr/bin/python3
39*ff41da50SThomas Huth  other.machine.hostname ansible_python_interpreter=/usr/bin/python3
40*ff41da50SThomas Huth
41*ff41da50SThomas HuthBuild environment
42*ff41da50SThomas Huth~~~~~~~~~~~~~~~~~
43*ff41da50SThomas Huth
44*ff41da50SThomas HuthThe ``scripts/ci/setup/$DISTRO/build-environment.yml`` Ansible
45*ff41da50SThomas Huthplaybook will set up machines with the environment needed to perform
46*ff41da50SThomas Huthbuilds and run QEMU tests. This playbook consists on the installation
47*ff41da50SThomas Huthof various required packages (and a general package update while at
48*ff41da50SThomas Huthit).
49*ff41da50SThomas Huth
50*ff41da50SThomas HuthThe minimum required version of Ansible successfully tested in this
51*ff41da50SThomas Huthplaybook is 2.8.0 (a version check is embedded within the playbook
52*ff41da50SThomas Huthitself).  To run the playbook, execute::
53*ff41da50SThomas Huth
54*ff41da50SThomas Huth  cd scripts/ci/setup
55*ff41da50SThomas Huth  ansible-playbook -i inventory $DISTRO/build-environment.yml
56*ff41da50SThomas Huth
57*ff41da50SThomas HuthPlease note that most of the tasks in the playbook require superuser
58*ff41da50SThomas Huthprivileges, such as those from the ``root`` account or those obtained
59*ff41da50SThomas Huthby ``sudo``.  If necessary, please refer to ``ansible-playbook``
60*ff41da50SThomas Huthoptions such as ``--become``, ``--become-method``, ``--become-user``
61*ff41da50SThomas Huthand ``--ask-become-pass``.
62*ff41da50SThomas Huth
63*ff41da50SThomas Huthgitlab-runner setup and registration
64*ff41da50SThomas Huth~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65*ff41da50SThomas Huth
66*ff41da50SThomas HuthThe gitlab-runner agent needs to be installed on each machine that
67*ff41da50SThomas Huthwill run jobs.  The association between a machine and a GitLab project
68*ff41da50SThomas Huthhappens with a registration token.  To find the registration token for
69*ff41da50SThomas Huthyour repository/project, navigate on GitLab's web UI to:
70*ff41da50SThomas Huth
71*ff41da50SThomas Huth * Settings (the gears-like icon at the bottom of the left hand side
72*ff41da50SThomas Huth   vertical toolbar), then
73*ff41da50SThomas Huth * CI/CD, then
74*ff41da50SThomas Huth * Runners, and click on the "Expand" button, then
75*ff41da50SThomas Huth * Under "Set up a specific Runner manually", look for the value under
76*ff41da50SThomas Huth   "And this registration token:"
77*ff41da50SThomas Huth
78*ff41da50SThomas HuthCopy the ``scripts/ci/setup/vars.yml.template`` file to
79*ff41da50SThomas Huth``scripts/ci/setup/vars.yml``.  Then, set the
80*ff41da50SThomas Huth``gitlab_runner_registration_token`` variable to the value obtained
81*ff41da50SThomas Huthearlier.
82*ff41da50SThomas Huth
83*ff41da50SThomas HuthTo run the playbook, execute::
84*ff41da50SThomas Huth
85*ff41da50SThomas Huth  cd scripts/ci/setup
86*ff41da50SThomas Huth  ansible-playbook -i inventory gitlab-runner.yml
87*ff41da50SThomas Huth
88*ff41da50SThomas HuthFollowing the registration, it's necessary to configure the runner tags,
89*ff41da50SThomas Huthand optionally other configurations on the GitLab UI.  Navigate to:
90*ff41da50SThomas Huth
91*ff41da50SThomas Huth * Settings (the gears like icon), then
92*ff41da50SThomas Huth * CI/CD, then
93*ff41da50SThomas Huth * Runners, and click on the "Expand" button, then
94*ff41da50SThomas Huth * "Runners activated for this project", then
95*ff41da50SThomas Huth * Click on the "Edit" icon (next to the "Lock" Icon)
96*ff41da50SThomas Huth
97*ff41da50SThomas HuthTags are very important as they are used to route specific jobs to
98*ff41da50SThomas Huthspecific types of runners, so it's a good idea to double check that
99*ff41da50SThomas Huththe automatically created tags are consistent with the OS and
100*ff41da50SThomas Hutharchitecture.  For instance, an Ubuntu 20.04 aarch64 system should
101*ff41da50SThomas Huthhave tags set as::
102*ff41da50SThomas Huth
103*ff41da50SThomas Huth  ubuntu_20.04,aarch64
104*ff41da50SThomas Huth
105*ff41da50SThomas HuthBecause the job definition at ``.gitlab-ci.d/custom-runners.yml``
106*ff41da50SThomas Huthwould contain::
107*ff41da50SThomas Huth
108*ff41da50SThomas Huth  ubuntu-20.04-aarch64-all:
109*ff41da50SThomas Huth   tags:
110*ff41da50SThomas Huth   - ubuntu_20.04
111*ff41da50SThomas Huth   - aarch64
112*ff41da50SThomas Huth
113*ff41da50SThomas HuthIt's also recommended to:
114*ff41da50SThomas Huth
115*ff41da50SThomas Huth * increase the "Maximum job timeout" to something like ``2h``
116*ff41da50SThomas Huth * give it a better Description
117