bootstrap/config.py: add libicu-dev/libicu-devel
[pshilovsky/samba-autobuild/.git] / bootstrap / config.py
1 #!/usr/bin/env python3
2
3 # Copyright (C) Catalyst.Net Ltd 2019
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 """
19 Manage dependencies and bootstrap environments for Samba.
20
21 Config file for packages and templates.
22
23 Author: Joe Guo <joeg@catalyst.net.nz>
24 """
25 import os
26 from os.path import abspath, dirname, join
27 HERE = abspath(dirname(__file__))
28 # output dir for rendered files
29 OUT = join(HERE, 'dists')
30
31
32 # pkgs with same name in all packaging systems
33 COMMON = [
34     'acl',
35     'attr',
36     'autoconf',
37     'binutils',
38     'bison',
39     'curl',
40     'gcc',
41     'gdb',
42     'git',
43     'htop',
44     'make',
45     'patch',
46     'perl',
47     'psmisc',  # for pstree in test
48     'rng-tools',
49     'rsync',
50     'sed',
51     'sudo',  # docker images has no sudo by default
52     'tar',
53     'tree',
54 ]
55
56
57 # define pkgs for all packaging systems in parallel
58 # make it easier to find missing ones
59 # use latest ubuntu and fedora as defaults
60 # deb, rpm, ...
61 PKGS = [
62     # NAME1-dev, NAME2-devel
63     ('lmdb-utils', 'lmdb-devel'),
64     ('nettle-dev', 'nettle-devel'),
65     ('zlib1g-dev', 'zlib-devel'),
66     ('libbsd-dev', 'libbsd-devel'),
67     ('libaio-dev', 'libaio-devel'),
68     ('libarchive-dev', 'libarchive-devel'),
69     ('libblkid-dev', 'libblkid-devel'),
70     ('libcap-dev', 'libcap-devel'),
71     ('libacl1-dev', 'libacl-devel'),
72     ('libattr1-dev', 'libattr-devel'),
73
74     # libNAME1-dev, NAME2-devel
75     ('libpopt-dev', 'popt-devel'),
76     ('libreadline-dev', 'readline-devel'),
77     ('libjansson-dev', 'jansson-devel'),
78     ('liblmdb-dev', 'lmdb-devel'),
79     ('libncurses5-dev', 'ncurses-devel'),
80     # NOTE: Debian 7+ or Ubuntu 16.04+
81     ('libsystemd-dev', 'systemd-devel'),
82     ('libkrb5-dev', 'krb5-devel'),
83     ('libldap2-dev', 'openldap-devel'),
84     ('libcups2-dev', 'cups-devel'),
85     ('libpam0g-dev', 'pam-devel'),
86     ('libgpgme11-dev', 'gpgme-devel'),
87     # NOTE: Debian 8+ and Ubuntu 14.04+
88     ('libgnutls28-dev', 'gnutls-devel'),
89     ('libtasn1-bin', ''),
90     ('libtasn1-dev', 'libtasn1-devel'),
91     ('', 'quota-devel'),
92     ('uuid-dev', 'libuuid-devel'),
93     ('libjs-jquery', ''),
94     ('libavahi-common-dev', 'avahi-devel'),
95     ('libdbus-1-dev', 'dbus-devel'),
96     ('libpcap-dev', 'libpcap-devel'),
97     ('libunwind-dev', 'libunwind-devel'),  # for back trace
98     ('libglib2.0-dev', 'glib2-devel'),
99     ('libicu-dev', 'libicu-devel'),
100
101     # NAME1, NAME2
102     # for debian, locales provide locale support with language packs
103     # ubuntu split language packs to language-pack-xx
104     # for centos, glibc-common provide locale support with language packs
105     # fedora split language packs  to glibc-langpack-xx
106     ('locales', 'glibc-common'),  # required for locale
107     ('language-pack-en', 'glibc-langpack-en'),  # we need en_US.UTF-8
108     ('bind9utils', 'bind-utils'),
109     ('dnsutils', ''),
110     ('xsltproc', 'libxslt'),
111     ('krb5-user', ''),
112     ('krb5-config', ''),
113     ('', 'krb5-server'),
114     ('apt-utils', 'yum-utils'),
115     ('pkg-config', 'pkgconfig'),
116     ('procps', 'procps-ng'),  # required for the free cmd in tests
117     ('lsb-release', 'redhat-lsb'),  # we need lsb_relase to show info
118     ('', 'rpcgen'),  # required for test
119     # refer: https://fedoraproject.org/wiki/Changes/SunRPCRemoval
120     ('', 'libtirpc-devel'),  # for <rpc/rpc.h> header on fedora
121     ('', 'libnsl2-devel'),  # for <rpcsvc/yp_prot.h> header on fedora
122     ('mawk', 'gawk'),
123
124     # python
125     ('python-dev', 'python-devel'),
126     ('python-dbg', ''),
127     ('python-iso8601', ''),
128     ('python-gpg', 'python2-gpg'),  # defaults to ubuntu/fedora latest
129     ('python-crypto', 'python-crypto'),
130     ('python-markdown', 'python-markdown'),
131     ('python-dnspython', 'python-dns'),
132     ('python-pexpect', ''),  # for wintest only
133
134     ('python3-dev', 'python3-devel'),
135     ('python3-dbg', ''),
136     ('python3-iso8601', ''),
137     ('python3-gpg', 'python3-gpg'),  # defaults to ubuntu/fedora latest
138     ('python3-crypto', 'python3-crypto'),
139     ('python3-markdown', 'python3-markdown'),
140     ('python3-matplotlib', ''),
141     ('python3-dnspython', 'python3-dns'),
142     ('python3-pexpect', ''),  # for wintest only
143
144     ('', 'libsemanage-python'),
145     ('', 'policycoreutils-python'),
146
147     # perl
148     ('libparse-yapp-perl', 'perl-Parse-Yapp'),
149     ('libjson-perl', 'perl-JSON-Parse'),
150     ('perl-modules', ''),
151     ('', 'perl-Archive-Tar'),
152     ('', 'perl-ExtUtils-MakeMaker'),
153     ('', 'perl-Test-Base'),
154     ('', 'perl-generators'),
155     ('', 'perl-interpreter'),
156
157     # misc
158     # @ means group for rpm, use fedora as rpm default
159     ('build-essential', '@development-tools'),
160     ('debhelper', ''),
161     # rpm has no pkg for docbook-xml
162     ('docbook-xml', 'docbook-dtds'),
163     ('docbook-xsl', 'docbook-style-xsl'),
164     ('flex', ''),
165     ('', 'keyutils-libs-devel'),
166
167 ]
168
169
170 DEB_PKGS = COMMON + [pkg for pkg, _ in PKGS if pkg]
171 RPM_PKGS = COMMON + [pkg for _, pkg in PKGS if pkg]
172
173
174 APT_BOOTSTRAP = r"""
175 #!/bin/bash
176 set -xueo pipefail
177
178 export DEBIAN_FRONTEND=noninteractive
179 apt-get -y update
180
181 apt-get -y install \
182     {pkgs}
183
184 apt-get -y autoremove
185 apt-get -y autoclean
186 apt-get -y clean
187 """
188
189
190 YUM_BOOTSTRAP = r"""
191 #!/bin/bash
192 set -xueo pipefail
193
194 yum -y -q update
195 yum -y -q install epel-release
196 yum -y -q update
197
198 yum -y -q --verbose install \
199     {pkgs}
200
201 yum clean all
202 """
203
204
205 DNF_BOOTSTRAP = r"""
206 #!/bin/bash
207 set -xueo pipefail
208
209 dnf -y -q update
210
211 dnf -y -q --verbose install \
212     {pkgs}
213
214 dnf clean all
215 """
216
217
218 # A generic shell script to setup locale
219 LOCALE_SETUP = r"""
220 #!/bin/bash
221 set -xueo pipefail
222
223 # refer to /usr/share/i18n/locales
224 INPUTFILE=en_US
225 # refer to /usr/share/i18n/charmaps
226 CHARMAP=UTF-8
227 # locale to generate in /usr/lib/locale
228 # glibc/localedef will normalize UTF-8 to utf8, follow the naming style
229 LOCALE=$INPUTFILE.utf8
230
231 # if locale is already correct, exit
232 ( locale | grep LC_ALL | grep -i $LOCALE ) && exit 0
233
234 # if locale not available, generate locale into /usr/lib/locale
235 if ! ( locale --all-locales | grep -i $LOCALE )
236 then
237     # no-archive means create its own dir
238     localedef --inputfile $INPUTFILE --charmap $CHARMAP --no-archive $LOCALE
239 fi
240
241 # update locale conf and global env file
242 # set both LC_ALL and LANG for safe
243
244 # update conf for Debian family
245 FILE=/etc/default/locale
246 if [ -f $FILE ]
247 then
248     echo LC_ALL="$LOCALE" > $FILE
249     echo LANG="$LOCALE" >> $FILE
250 fi
251
252 # update conf for RedHat family
253 FILE=/etc/locale.conf
254 if [ -f $FILE ]
255 then
256     # LC_ALL is not valid in this file, set LANG only
257     echo LANG="$LOCALE" > $FILE
258 fi
259
260 # update global env file
261 FILE=/etc/environment
262 if [ -f $FILE ]
263 then
264     # append LC_ALL if not exist
265     grep LC_ALL $FILE || echo LC_ALL="$LOCALE" >> $FILE
266     # append LANG if not exist
267     grep LANG $FILE || echo LANG="$LOCALE" >> $FILE
268 fi
269 """
270
271
272 DOCKERFILE = r"""
273 FROM {docker_image}
274
275 # pass in with --build-arg while build
276 ARG SHA1SUM
277 RUN [ -n $SHA1SUM ] && echo $SHA1SUM > /sha1sum.txt
278
279 ADD *.sh /tmp/
280 # need root permission, do it before USER samba
281 RUN /tmp/bootstrap.sh && /tmp/locale.sh
282
283 # if ld.gold exists, force link it to ld
284 RUN set -x; LD=$(which ld); LD_GOLD=$(which ld.gold); test -x $LD_GOLD && ln -sf $LD_GOLD $LD && test -x $LD && echo "$LD is now $LD_GOLD"
285
286 # make test can not work with root, so we have to create a new user
287 RUN useradd -m -s /bin/bash samba && \
288     mkdir -p /etc/sudoers.d && \
289     echo "samba ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/samba
290
291 USER samba
292 WORKDIR /home/samba
293 # samba tests rely on this
294 ENV USER=samba LC_ALL=en_US.utf8 LANG=en_US.utf8
295 """
296
297 # Vagrantfile snippet for each dist
298 VAGRANTFILE_SNIPPET = r"""
299     config.vm.define "{name}" do |v|
300         v.vm.box = "{vagrant_box}"
301         v.vm.hostname = "{name}"
302         v.vm.provision :shell, path: "{name}/bootstrap.sh"
303         v.vm.provision :shell, path: "{name}/locale.sh"
304     end
305 """
306
307 # global Vagrantfile with snippets for all dists
308 VAGRANTFILE_GLOBAL = r"""
309 Vagrant.configure("2") do |config|
310     config.ssh.insert_key = false
311
312 {vagrantfile_snippets}
313
314 end
315 """
316
317
318 DEB_DISTS = {
319     'debian7': {
320         'docker_image': 'debian:7',
321         'vagrant_box': 'debian/wheezy64',
322         'replace': {
323             'libgnutls28-dev': 'libgnutls-dev',
324             'libsystemd-dev': '',  # not available, remove
325             'lmdb-utils': '',  # not available, remove
326             'liblmdb-dev': '',  # not available, remove
327             'python-gpg': 'python-gpgme',
328             'python3-gpg': '',  # no python3 gpg pkg available, remove
329             'language-pack-en': '',   # included in locales
330         }
331     },
332     'debian8': {
333         'docker_image': 'debian:8',
334         'vagrant_box': 'debian/jessie64',
335         'replace': {
336             'python-gpg': 'python-gpgme',
337             'python3-gpg': 'python3-gpgme',
338             'language-pack-en': '',   # included in locales
339         }
340     },
341     'debian9': {
342         'docker_image': 'debian:9',
343         'vagrant_box': 'debian/stretch64',
344         'replace': {
345             'language-pack-en': '',   # included in locales
346         }
347     },
348     'ubuntu1404': {
349         'docker_image': 'ubuntu:14.04',
350         'vagrant_box': 'ubuntu/trusty64',
351         'replace': {
352             'libsystemd-dev': '',  # remove
353             'libgnutls28-dev': 'libgnutls-dev',
354             'python-gpg': 'python-gpgme',
355             'python3-gpg': 'python3-gpgme',
356             'lmdb-utils': 'lmdb-utils/trusty-backports',
357             'liblmdb-dev': 'liblmdb-dev/trusty-backports',
358             'libunwind-dev': 'libunwind8-dev',
359         }
360     },
361     'ubuntu1604': {
362         'docker_image': 'ubuntu:16.04',
363         'vagrant_box': 'ubuntu/xenial64',
364         'replace': {
365             'python-gpg': 'python-gpgme',
366             'python3-gpg': 'python3-gpgme',
367         }
368     },
369     'ubuntu1804': {
370         'docker_image': 'ubuntu:18.04',
371         'vagrant_box': 'ubuntu/bionic64',
372     },
373 }
374
375
376 RPM_DISTS = {
377     'centos6': {
378         'docker_image': 'centos:6',
379         'vagrant_box': 'centos/6',
380         'bootstrap': YUM_BOOTSTRAP,
381         'replace': {
382             'python3-devel': 'python34-devel',
383             'python2-gpg': 'pygpgme',
384             'python3-gpg': '',  # no python3-gpg yet
385             '@development-tools': '"@Development Tools"',  # add quotes
386             'glibc-langpack-en': '',  # included in glibc-common
387             'glibc-locale-source': '',  # included in glibc-common
388             'procps-ng': 'procps',  # centos6 still use old name
389             # update perl core modules on centos
390             # fix: Can't locate Archive/Tar.pm in @INC
391             'perl': 'perl-core',
392         }
393     },
394     'centos7': {
395         'docker_image': 'centos:7',
396         'vagrant_box': 'centos/7',
397         'bootstrap': YUM_BOOTSTRAP,
398         'replace': {
399             'python3-devel': 'python34-devel',
400             # although python36-devel is available
401             # after epel-release installed
402             # however, all other python3 pkgs are still python34-ish
403             'python2-gpg': 'pygpgme',
404             'python3-gpg': '',  # no python3-gpg yet
405             '@development-tools': '"@Development Tools"',  # add quotes
406             'glibc-langpack-en': '',  # included in glibc-common
407             'glibc-locale-source': '',  # included in glibc-common
408             # update perl core modules on centos
409             # fix: Can't locate Archive/Tar.pm in @INC
410             'perl': 'perl-core',
411         }
412     },
413     'fedora28': {
414         'docker_image': 'fedora:28',
415         'vagrant_box': 'fedora/28-cloud-base',
416         'bootstrap': DNF_BOOTSTRAP,
417     },
418     'fedora29': {
419         'docker_image': 'fedora:29',
420         'vagrant_box': 'fedora/29-cloud-base',
421         'bootstrap': DNF_BOOTSTRAP,
422     },
423 }
424
425
426 DEB_FAMILY = {
427     'name': 'deb',
428     'pkgs': DEB_PKGS,
429     'bootstrap': APT_BOOTSTRAP,  # family default
430     'dists': DEB_DISTS,
431 }
432
433
434 RPM_FAMILY = {
435     'name': 'rpm',
436     'pkgs': RPM_PKGS,
437     'bootstrap': YUM_BOOTSTRAP,  # family default
438     'dists': RPM_DISTS,
439 }
440
441
442 YML_HEADER = r"""
443 ---
444 packages:
445 """
446
447
448 def expand_family_dists(family):
449     dists = {}
450     for name, config in family['dists'].items():
451         config = config.copy()
452         config['name'] = name
453         config['home'] = join(OUT, name)
454         config['family'] = family['name']
455
456         # replace dist specific pkgs
457         replace = config.get('replace', {})
458         pkgs = []
459         for pkg in family['pkgs']:
460             pkg = replace.get(pkg, pkg)  # replace if exists or get self
461             if pkg:
462                 pkgs.append(pkg)
463         pkgs.sort()
464
465         lines = ['  - {}'.format(pkg) for pkg in pkgs]
466         config['packages.yml'] = YML_HEADER.lstrip() + os.linesep.join(lines)
467
468         sep = ' \\' + os.linesep + '    '
469         config['pkgs'] = sep.join(pkgs)
470
471         # get dist bootstrap template or fall back to family default
472         bootstrap_template = config.get('bootstrap', family['bootstrap'])
473         config['bootstrap.sh'] = bootstrap_template.format(**config).strip()
474         config['locale.sh'] = LOCALE_SETUP.format(**config).strip()
475
476         config['Dockerfile'] = DOCKERFILE.format(**config).strip()
477         # keep the indent, no strip
478         config['vagrantfile_snippet'] = VAGRANTFILE_SNIPPET.format(**config)
479
480         dists[name] = config
481     return dists
482
483
484 # expanded config for dists
485 DEB_DISTS_EXP = expand_family_dists(DEB_FAMILY)
486 RPM_DISTS_EXP = expand_family_dists(RPM_FAMILY)
487
488 # assemble all together
489 DISTS = {}
490 DISTS.update(DEB_DISTS_EXP)
491 DISTS.update(RPM_DISTS_EXP)
492
493
494 def render_vagrantfile(dists):
495     """
496     Render all snippets for each dist into global Vagrantfile.
497
498     Vagrant supports multiple vms in one Vagrantfile.
499     This make it easier to manage the fleet, e.g:
500
501     start all: vagrant up
502     start one: vagrant up ubuntu1804
503
504     All other commands apply to above syntax, e.g.: status, destroy, provision
505     """
506     # sort dists by name and put all vagrantfile snippets together
507     snippets = [
508         dists[dist]['vagrantfile_snippet']
509         for dist in sorted(dists.keys())]
510
511     return VAGRANTFILE_GLOBAL.format(vagrantfile_snippets=''.join(snippets))
512
513
514 VAGRANTFILE = render_vagrantfile(DISTS)
515
516
517 # data we need to expose
518 __all__ = ['DISTS', 'VAGRANTFILE', 'OUT']