1#!/usr/bin/python3 2# 3# Re-generate container recipes 4# 5# This script uses the "lcitool" available from 6# 7# https://gitlab.com/libvirt/libvirt-ci 8# 9# Copyright (c) 2020 Red Hat Inc. 10# 11# This work is licensed under the terms of the GNU GPL, version 2 12# or (at your option) any later version. See the COPYING file in 13# the top-level directory. 14 15import sys 16import os 17import subprocess 18 19from pathlib import Path 20 21if len(sys.argv) != 1: 22 print("syntax: %s" % sys.argv[0], file=sys.stderr) 23 sys.exit(1) 24 25self_dir = Path(__file__).parent 26src_dir = self_dir.parent.parent 27dockerfiles_dir = Path(src_dir, "tests", "docker", "dockerfiles") 28 29lcitool_path = Path(self_dir, "libvirt-ci", "lcitool") 30 31lcitool_cmd = [lcitool_path, "--data-dir", self_dir] 32 33def atomic_write(filename, content): 34 tmp = filename.with_suffix(filename.suffix + ".tmp") 35 try: 36 with tmp.open("w") as fp: 37 print(content, file=fp, end="") 38 tmp.rename(filename) 39 except Exception as ex: 40 tmp.unlink() 41 raise 42 43def generate(filename, cmd, trailer): 44 print("Generate %s" % filename) 45 lcitool=subprocess.run(cmd, capture_output=True) 46 47 if lcitool.returncode != 0: 48 raise Exception("Failed to generate %s: %s" % (filename, lcitool.stderr)) 49 50 content = lcitool.stdout.decode("utf8") 51 if trailer is not None: 52 content += trailer 53 atomic_write(filename, content) 54 55def generate_dockerfile(host, target, cross=None, trailer=None): 56 filename = Path(src_dir, "tests", "docker", "dockerfiles", host + ".docker") 57 cmd = lcitool_cmd + ["dockerfile"] 58 if cross is not None: 59 cmd.extend(["--cross", cross]) 60 cmd.extend([target, "qemu"]) 61 generate(filename, cmd, trailer) 62 63def generate_cirrus(target, trailer=None): 64 filename = Path(src_dir, ".gitlab-ci.d", "cirrus", target + ".vars") 65 cmd = [lcitool_path, "variables", target, "qemu"] 66 generate(filename, cmd, trailer) 67 68ubuntu1804_skipssh = [ 69 "# https://bugs.launchpad.net/qemu/+bug/1838763\n", 70 "ENV QEMU_CONFIGURE_OPTS --disable-libssh\n" 71] 72 73ubuntu2004_tsanhack = [ 74 "# Apply patch https://reviews.llvm.org/D75820\n", 75 "# This is required for TSan in clang-10 to compile with QEMU.\n", 76 "RUN sed -i 's/^const/static const/g' /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h\n" 77] 78 79try: 80 generate_dockerfile("centos8", "centos-8") 81 generate_dockerfile("fedora", "fedora-35") 82 generate_dockerfile("ubuntu1804", "ubuntu-1804", 83 trailer="".join(ubuntu1804_skipssh)) 84 generate_dockerfile("ubuntu2004", "ubuntu-2004", 85 trailer="".join(ubuntu2004_tsanhack)) 86 generate_dockerfile("opensuse-leap", "opensuse-leap-152") 87 generate_dockerfile("alpine", "alpine-edge") 88 89 generate_cirrus("freebsd-12") 90 generate_cirrus("freebsd-13") 91 generate_cirrus("macos-11") 92 93 sys.exit(0) 94except Exception as ex: 95 print(str(ex), file=sys.stderr) 96 sys.exit(1) 97