3 # Copyright (C) Catalyst.Net Ltd 2019
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.
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.
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/>.
19 Manage dependencies and bootstrap environments for Samba.
21 Config file for packages and templates.
23 Author: Joe Guo <joeg@catalyst.net.nz>
26 from os.path import abspath, dirname, join
27 HERE = abspath(dirname(__file__))
28 # output dir for rendered files
29 OUT = join(HERE, 'dists')
32 # pkgs with same name in all packaging systems
47 'psmisc', # for pstree in test
51 'sudo', # docker images has no sudo by default
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
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'),
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'),
90 ('libtasn1-dev', 'libtasn1-devel'),
92 ('uuid-dev', 'libuuid-devel'),
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'),
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'),
110 ('xsltproc', 'libxslt'),
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
125 ('python-dev', 'python-devel'),
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
134 ('python3-dev', 'python3-devel'),
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
144 ('', 'libsemanage-python'),
145 ('', 'policycoreutils-python'),
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'),
158 # @ means group for rpm, use fedora as rpm default
159 ('build-essential', '@development-tools'),
161 # rpm has no pkg for docbook-xml
162 ('docbook-xml', 'docbook-dtds'),
163 ('docbook-xsl', 'docbook-style-xsl'),
165 ('', 'keyutils-libs-devel'),
170 DEB_PKGS = COMMON + [pkg for pkg, _ in PKGS if pkg]
171 RPM_PKGS = COMMON + [pkg for _, pkg in PKGS if pkg]
178 export DEBIAN_FRONTEND=noninteractive
184 apt-get -y autoremove
195 yum -y -q install epel-release
198 yum -y -q --verbose install \
211 dnf -y -q --verbose install \
218 # A generic shell script to setup locale
223 # refer to /usr/share/i18n/locales
225 # refer to /usr/share/i18n/charmaps
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
231 # if locale is already correct, exit
232 ( locale | grep LC_ALL | grep -i $LOCALE ) && exit 0
234 # if locale not available, generate locale into /usr/lib/locale
235 if ! ( locale --all-locales | grep -i $LOCALE )
237 # no-archive means create its own dir
238 localedef --inputfile $INPUTFILE --charmap $CHARMAP --no-archive $LOCALE
241 # update locale conf and global env file
242 # set both LC_ALL and LANG for safe
244 # update conf for Debian family
245 FILE=/etc/default/locale
248 echo LC_ALL="$LOCALE" > $FILE
249 echo LANG="$LOCALE" >> $FILE
252 # update conf for RedHat family
253 FILE=/etc/locale.conf
256 # LC_ALL is not valid in this file, set LANG only
257 echo LANG="$LOCALE" > $FILE
260 # update global env file
261 FILE=/etc/environment
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
275 # pass in with --build-arg while build
277 RUN [ -n $SHA1SUM ] && echo $SHA1SUM > /sha1sum.txt
280 # need root permission, do it before USER samba
281 RUN /tmp/bootstrap.sh && /tmp/locale.sh
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"
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
293 # samba tests rely on this
294 ENV USER=samba LC_ALL=en_US.utf8 LANG=en_US.utf8
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"
307 # global Vagrantfile with snippets for all dists
308 VAGRANTFILE_GLOBAL = r"""
309 Vagrant.configure("2") do |config|
310 config.ssh.insert_key = false
312 {vagrantfile_snippets}
320 'docker_image': 'debian:7',
321 'vagrant_box': 'debian/wheezy64',
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
333 'docker_image': 'debian:8',
334 'vagrant_box': 'debian/jessie64',
336 'python-gpg': 'python-gpgme',
337 'python3-gpg': 'python3-gpgme',
338 'language-pack-en': '', # included in locales
342 'docker_image': 'debian:9',
343 'vagrant_box': 'debian/stretch64',
345 'language-pack-en': '', # included in locales
349 'docker_image': 'ubuntu:14.04',
350 'vagrant_box': 'ubuntu/trusty64',
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',
362 'docker_image': 'ubuntu:16.04',
363 'vagrant_box': 'ubuntu/xenial64',
365 'python-gpg': 'python-gpgme',
366 'python3-gpg': 'python3-gpgme',
370 'docker_image': 'ubuntu:18.04',
371 'vagrant_box': 'ubuntu/bionic64',
378 'docker_image': 'centos:6',
379 'vagrant_box': 'centos/6',
380 'bootstrap': YUM_BOOTSTRAP,
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
395 'docker_image': 'centos:7',
396 'vagrant_box': 'centos/7',
397 'bootstrap': YUM_BOOTSTRAP,
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
414 'docker_image': 'fedora:28',
415 'vagrant_box': 'fedora/28-cloud-base',
416 'bootstrap': DNF_BOOTSTRAP,
419 'docker_image': 'fedora:29',
420 'vagrant_box': 'fedora/29-cloud-base',
421 'bootstrap': DNF_BOOTSTRAP,
429 'bootstrap': APT_BOOTSTRAP, # family default
437 'bootstrap': YUM_BOOTSTRAP, # family default
448 def expand_family_dists(family):
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']
456 # replace dist specific pkgs
457 replace = config.get('replace', {})
459 for pkg in family['pkgs']:
460 pkg = replace.get(pkg, pkg) # replace if exists or get self
465 lines = [' - {}'.format(pkg) for pkg in pkgs]
466 config['packages.yml'] = YML_HEADER.lstrip() + os.linesep.join(lines)
468 sep = ' \\' + os.linesep + ' '
469 config['pkgs'] = sep.join(pkgs)
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()
476 config['Dockerfile'] = DOCKERFILE.format(**config).strip()
477 # keep the indent, no strip
478 config['vagrantfile_snippet'] = VAGRANTFILE_SNIPPET.format(**config)
484 # expanded config for dists
485 DEB_DISTS_EXP = expand_family_dists(DEB_FAMILY)
486 RPM_DISTS_EXP = expand_family_dists(RPM_FAMILY)
488 # assemble all together
490 DISTS.update(DEB_DISTS_EXP)
491 DISTS.update(RPM_DISTS_EXP)
494 def render_vagrantfile(dists):
496 Render all snippets for each dist into global Vagrantfile.
498 Vagrant supports multiple vms in one Vagrantfile.
499 This make it easier to manage the fleet, e.g:
501 start all: vagrant up
502 start one: vagrant up ubuntu1804
504 All other commands apply to above syntax, e.g.: status, destroy, provision
506 # sort dists by name and put all vagrantfile snippets together
508 dists[dist]['vagrantfile_snippet']
509 for dist in sorted(dists.keys())]
511 return VAGRANTFILE_GLOBAL.format(vagrantfile_snippets=''.join(snippets))
514 VAGRANTFILE = render_vagrantfile(DISTS)
517 # data we need to expose
518 __all__ = ['DISTS', 'VAGRANTFILE', 'OUT']