]> git.arvados.org - arvados.git/blob - tools/ansible/install-dev-tools.yml
22958: Introduce distro_packages role
[arvados.git] / tools / ansible / install-dev-tools.yml
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4 #
5 # install-dev-tools.yml - Install Arvados development tooling
6 #
7 ### Introduction
8 #
9 # This playbook installs and configures software necessary for Arvados
10 # development. It uses host groups from your inventory to select which
11 # dependencies are managed.
12 #
13 # The most inclusive group is `arvados_test_all`. Hosts in this group will
14 # have everything they need to clone the Arvados source and run
15 # `build/run-tests.sh`.
16 #
17 # Another useful group is `arvados_build_all`. Hosts in this group will have
18 # enough software to build Arvados binaries and language packages like Ruby
19 # gems. This is NOT enough software to run an Arvados cluster; it's mainly
20 # useful for building distribution packages and related tooling.
21 #
22 ### Example Inventory
23 #
24 # arvados_test_all:
25 #   hosts:
26 #     dev.arvados.example:
27 #   vars:
28 #     # See files/default-test-config.yml for an example.
29 #     # You can change the Arvados database configuration and this playbook
30 #     # will set up PostgreSQL to match.
31 #     arvados_config_file: /home/example/path/arvados/config.yml
32 #
33 ### Run the playbook
34 #
35 # $ ansible-playbook -Ki YOUR-INVENTORY.yml install-dev-tools.yml
36 #
37 ### Advanced groups
38 #
39 # This documentation is aimed at Arvados developers building tooling with
40 # this playbook.
41 #
42 # The pattern of group names is `arvados_build_COMPONENT` and
43 # `arvados_test_COMPONENT`. The `build` group installs everything you need
44 # to "build" the component from source. (Exactly what that means varies by
45 # language.) `arvados_test_COMPONENT` adds everything you need to run that
46 # component's tests. Any host in an `arvados_test` group is automatically
47 # added to its corresponding `arvados_build` group.
48 #
49 # See the `core_components` variable below for the list of components. In
50 # general, it is the name of a language we have multiple components in; or
51 # the name of a component that can be tested independently in `run-tests.sh`.
52
53 - name: Bootstrap nodes
54   hosts: all
55   gather_facts: no
56   vars:
57     # The `arvados_build_all` group will be expanded to the
58     # `arvados_build_NAME` group for every name in this list.
59     # This corresponds to the components we build distribution packages for.
60     core_components:
61       - cwl
62       - doc
63       - go
64       - python
65       - ruby
66       - workbench
67     # `arvados_test_all` works similarly with additional components.
68     # The primary user of `arvados_build_all` is package build Docker images,
69     # so excluding components we don't package avoids Docker image bloat.
70     test_components:
71       - deb
72       - java
73       - R
74       - rpm
75
76   tasks:
77     - ansible.builtin.include_role:
78         name: distro_bootstrap
79
80     # If the host is in no `arvados` groups, add it to `arvados_test_all`.
81     - name: Build default group arvados_test_all
82       when: "hostvars[item]['group_names']|map('regex_search', '^arvados_')|select|first is undefined"
83       ansible.builtin.add_host:
84         host: "{{ item }}"
85         groups:
86           - arvados_test_all
87       loop: "{{ ansible_play_hosts }}"
88
89     - name: Expand arvados_build_all group
90       ansible.builtin.add_host:
91         host: "{{ item }}"
92         groups: "{{ core_components|map('replace', '', 'arvados_build_', 1) }}"
93       loop: "{{ groups.arvados_build_all|default([]) }}"
94
95     - name: Expand arvados_test_all group
96       ansible.builtin.add_host:
97         host: "{{ item }}"
98         groups: "{{ (core_components + test_components)|map('replace', '', 'arvados_test_', 1) }}"
99       loop: "{{ groups.arvados_test_all|default([]) }}"
100
101     - name: Add test hosts to build groups
102       ansible.builtin.add_host:
103         host: "{{ item }}"
104         groups: "{{ hostvars[item]['group_names']|map('regex_replace', '^arvados_test_', 'arvados_build_', 1)|list }}"
105       loop: "{{ ansible_play_hosts }}"
106
107 ### Core dependencies
108
109 - hosts: arvados_build_*
110   tasks:
111     - ansible.builtin.include_role:
112         name: distro_packages
113       vars:
114         task_name: Install common build tools
115         package_names:
116           - ca-certificates
117           - curl
118           - diffutils
119           - findutils
120           - git
121           - jq
122
123     - name: Set up Arvados development user
124       become: yes
125       ansible.builtin.user:
126         name: "{{ arvados_dev_user|default(ansible_user_id) }}"
127       register: dev_user
128
129 # All of these test suites will spin up an entire development cluster, which
130 # requires:
131 #  * building and running arvados-server
132 #  * building Ruby gems and running the API server in test mode
133 #  * installing the Python SDK to run `run_test_server.py`
134 # So we take this as one big group, and this is the play where we set up all
135 # the prerequisites to do that.
136 - hosts: arvados_test_cwl:arvados_test_go:arvados_test_python:arvados_test_ruby
137   tasks:
138     - name: Add host to prerequisite build groups
139       ansible.builtin.add_host:
140         host: "{{ item }}"
141         groups:
142           - arvados_build_go
143           - arvados_build_python
144           - arvados_build_ruby
145       loop: "{{ ansible_play_hosts }}"
146
147     - name: Load Arvados configuration file
148       delegate_to: localhost
149       ansible.builtin.include_vars:
150         name: arvados_config
151         file: "{{ arvados_config_file }}"
152
153     - name: Load Arvados cluster configuration
154       ansible.builtin.set_fact:
155         arvados_cluster: "{{ arvados_config.Clusters.zzzzz }}"
156       failed_when: arvados_cluster is undefined
157
158     - name: Install shared test dependencies
159       ansible.builtin.apt:
160         name:
161           - locales
162           - nginx
163           - openssl
164           # Direct dependencies of run-tests.sh
165           - bsdextrautils
166           - net-tools
167
168     # Tests assume the underlying database uses en_US.UTF-8.
169     # It must be generated before starting the PostgreSQL server.
170     - name: Configure en_US.UTF-8 locale
171       become: yes
172       ansible.builtin.lineinfile:
173         path: /etc/locale.gen
174         regexp: "^[# ]*en_US.UTF-8 +UTF-8 *$"
175         line: en_US.UTF-8 UTF-8
176       register: locale_gen
177
178     - name: Run locale-gen
179       when: locale_gen.changed
180       become: yes
181       ansible.builtin.command:
182         cmd: locale-gen
183
184     - ansible.builtin.include_role:
185         name: arvados_postgresql
186       vars:
187         arvados_postgresql_config: {}
188         arvados_postgresql_hba_sources:
189           - "127.0.0.0/24"
190           - "::1/128"
191
192     - ansible.builtin.include_role:
193         name: arvados_database
194       vars:
195         arvados_database_login_host: ""
196         # Let the test user drop and recreate the database wholesale
197         arvados_database_role_attr_flags: CREATEDB
198
199     - name: Set up .config/arvados
200       become: yes
201       become_user: "{{ dev_user.name }}"
202       ansible.builtin.file:
203         path: "{{ (dev_user.home, item)|path_join }}"
204         state: directory
205       loop:
206         - .config
207         - .config/arvados
208
209     - name: Write arvados/config.yml for testing
210       become: yes
211       become_user: "{{ dev_user.name }}"
212       ansible.builtin.copy:
213         src: "{{ arvados_config_file }}"
214         dest: "{{ (dev_user.home, '.config/arvados/config.yml')|path_join }}"
215         mode: 0600
216
217     - name: Add Arvados test configuration to profile.d
218       become: yes
219       ansible.builtin.copy:
220         content: |
221           if [ -z "${CONFIGSRC:-}" ] && [ -e ~/.config/arvados/config.yml ]; then
222             export CONFIGSRC="$HOME/.config/arvados"
223           fi
224         dest: /etc/profile.d/arvados-test.sh
225
226 ### Core language build dependencies
227
228 - hosts: arvados_build_go
229   tasks:
230     - ansible.builtin.include_role:
231         name: arvados_go
232
233     - ansible.builtin.include_role:
234         name: distro_packages
235       vars:
236         task_name: Install Go build dependencies
237         package_names:
238           - libpam-dev
239
240 - hosts: arvados_build_python
241   tasks:
242     - ansible.builtin.include_role:
243         name: distro_packages
244       vars:
245         task_name: Install Python build requirements
246         package_names:
247           - g++
248           - libcurl4-openssl-dev
249           - libfuse-dev
250           - libssl-dev
251           - make
252           - pkgconf
253           - python3-dev
254           - python3-venv
255
256 - hosts: arvados_build_ruby
257   tasks:
258     - ansible.builtin.include_role:
259         name: distro_packages
260       vars:
261         task_name: Install Ruby build requirements
262         package_names:
263           - bison
264           - g++
265           - libcurl4-openssl-dev
266           - libpq-dev
267           - libssl-dev
268           - libyaml-dev
269           - make
270           - pkgconf
271           - postgresql-client
272           - procps
273           - ruby
274           - ruby-dev
275           - shared-mime-info
276           - zlib1g-dev
277
278 ### Distribution package dependencies
279 # These are ordered here because some of the language test suites later
280 # expand the Docker installation.
281
282 - hosts: arvados_build_deb:arvados_build_rpm
283   tasks:
284     - ansible.builtin.include_role:
285         name: arvados_ansible
286       vars:
287         arvados_ansible_galaxy_user: "{{ dev_user.name }}"
288
289     - ansible.builtin.include_role:
290         name: arvados_docker
291
292     - name: Add development user to docker group
293       become: yes
294       ansible.builtin.user:
295         name: "{{ dev_user.name }}"
296         groups:
297           - docker
298         append: yes
299
300 - hosts: arvados_test_deb
301   tasks:
302     - name: Install deb test dependencies
303       become: yes
304       ansible.builtin.apt:
305         name:
306           - apt-utils
307           - dpkg-dev
308
309 - hosts: arvados_test_rpm
310   tasks:
311     - name: Install RPM test dependencies
312       become: yes
313       ansible.builtin.apt:
314         name:
315           - createrepo-c
316
317 ### Core language test dependencies
318
319 - hosts: arvados_test_cwl:arvados_test_go
320   tasks:
321     - ansible.builtin.include_role:
322         name: arvados_compute
323       vars:
324         arvados_compute_packages: []
325         arvados_compute_docker: true
326         arvados_compute_singularity: "{{ 'arvados_test_go' in group_names }}"
327
328     - name: Add development user to docker group
329       become: yes
330       ansible.builtin.user:
331         name: "{{ dev_user.name }}"
332         groups:
333           - docker
334         append: yes
335
336 - hosts: arvados_test_go
337   tasks:
338     - name: Install Go test dependencies
339       become: yes
340       ansible.builtin.apt:
341         name:
342           # lib/controller
343           - rsync
344           # services/keep-web
345           - cadaver
346           - mime-support
347
348 ### Individual component dependencies
349
350 - hosts: arvados_build_doc
351   tasks:
352     - name: Install doc build requirements
353       become: yes
354       ansible.builtin.apt:
355         name:
356           - python3-venv
357           - ruby
358
359 - hosts: arvados_test_doc
360   tasks:
361     - name: Install doc test requirements
362       become: yes
363       ansible.builtin.apt:
364         name:
365           - linkchecker
366
367 - hosts: arvados_build_java
368   tasks:
369     - name: Install Java build requirements
370       become: yes
371       ansible.builtin.apt:
372         name:
373           - default-jdk-headless
374           - gradle
375
376 - hosts: arvados_build_R
377   tasks:
378     - name: Install R build requirements
379       become: yes
380       ansible.builtin.apt:
381         name:
382           - g++
383           - libfontconfig1-dev
384           - libfreetype6-dev
385           - libfribidi-dev
386           - libharfbuzz-dev
387           - libjpeg-dev
388           - libpng-dev
389           - libtiff5-dev
390           - libxml2-dev
391           - make
392           - r-base
393
394 - hosts: arvados_test_R
395   tasks:
396     - name: Install R test requirements
397       become: yes
398       ansible.builtin.apt:
399         name:
400           - r-cran-testthat
401
402 - hosts: arvados_build_workbench
403   tasks:
404     - ansible.builtin.include_role:
405         name: arvados_nodejs
406
407 - hosts: arvados_test_workbench
408   tasks:
409     - name: Install Workbench test requirements
410       become: yes
411       ansible.builtin.apt:
412         name:
413           # <https://docs.cypress.io/app/get-started/install-cypress#Linux-Prerequisites>
414           - firefox-esr
415           - libasound2
416           - libgbm-dev
417           - libgtk-3-0
418           - libgtk2.0-0
419           - libnotify-dev
420           - libnss3
421           - libxss1
422           - libxtst6
423           - xauth
424           - xvfb
425
426     - name: Check fs.inotify.max_user_watches sysctl value
427       ansible.builtin.command:
428         cmd: /sbin/sysctl --values fs.inotify.max_user_watches
429       register: max_user_watches_value
430
431     - name: Increase fs.inotify.max_user_watches
432       vars:
433         max_user_watches_wanted: 524288
434       when: "max_user_watches_value.stdout|int < max_user_watches_wanted"
435       become: yes
436       ansible.builtin.command:
437         argv:
438           - sysctl
439           - "fs.inotify.max_user_watches={{ max_user_watches_wanted }}"
440       register: max_user_watches_set
441
442     - name: Set fs.inotify.max_user_watches permanently
443       when: max_user_watches_set.changed
444       become: yes
445       ansible.builtin.copy:
446         content: |
447           ### This file is managed by Ansible
448           # React sets many inotify watchers and needs the limit increased.
449           {{ max_user_watches_set.stdout }}
450         dest: /etc/sysctl.d/arvados-workbench.conf
451         owner: root
452         group: root
453         mode: 0644