diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-03-25 00:27:18 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-03-25 00:27:18 +0100 |
commit | 9209f34d4337aa2b848019b0c88297eda9213728 (patch) | |
tree | 8b3d3b6d77b5d8f1b1ded759c160db87490a933e /scripts | |
parent | a9f2c0468889ae061d4f5a88ba7548e496627ea3 (diff) | |
download | vyos-build-9209f34d4337aa2b848019b0c88297eda9213728.tar.gz vyos-build-9209f34d4337aa2b848019b0c88297eda9213728.zip |
T1313: add support for reusable build flavor files.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build-config | 56 | ||||
-rwxr-xr-x | scripts/build-submodules | 1 | ||||
-rw-r--r-- | scripts/defaults.py | 15 | ||||
-rwxr-xr-x | scripts/live-build-config | 15 |
4 files changed, 41 insertions, 46 deletions
diff --git a/scripts/build-config b/scripts/build-config index ce83f74e..a12ecdc4 100755 --- a/scripts/build-config +++ b/scripts/build-config @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2018, VyOS maintainers and contributors +# Copyright (C) 2019, VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -49,19 +49,28 @@ def get_validator(optdict, name): return None +# Load the build flavor file +build_flavor = os.getenv('VYOS_BUILD_FLAVOR') +if build_flavor is None: + build_flavor = defaults.DEFAULT_BUILD_FLAVOR +try: + with open(build_flavor, 'r') as f: + build_defaults = json.load(f) +except Exception as e: + print("Failed to open the build flavor file {0}: {1}".format(build_flavor, e)) + sys.exit(1) + + # Options dict format: # '$option_name_without_leading_dashes': { ('$help_string', $default_value_generator_thunk, $value_checker_thunk) } options = { - 'architecture': ('Image target architecture (amd64 or i386 or armhf)', lambda: 'amd64', lambda x: x in ['amd64', 'i386', 'armhf']), + 'architecture': ('Image target architecture (amd64 or i386 or armhf)', lambda: build_defaults['architecture'], lambda x: x in ['amd64', 'i386', 'armhf']), 'build-by': ('Builder identifier (e.g. jrandomhacker@example.net)', get_default_build_by, None), - 'debian-mirror': ('Debian repository mirror for ISO build', lambda: defaults.DEBIAN_MIRROR, None), - 'debian-security-mirror': ('Debian security updated mirror', lambda: defaults.DEBIAN_SECURITY_MIRROR, None), - 'pbuilder-debian-mirror': ('Debian repository mirror for pbuilder env bootstrap', lambda: defaults.DEBIAN_MIRROR, None), - 'salt-mirror': ('Salt package mirror', lambda: defaults.SALT_MIRROR, None), - 'vyos-mirror': ('VyOS package mirror', lambda: defaults.VYOS_MIRROR, None), - 'pdns-mirror': ('PowerDNS package mirror', lambda: defaults.PDNS_MIRROR, None), + 'debian-mirror': ('Debian repository mirror for ISO build', lambda: build_defaults['debian_mirror'], None), + 'debian-security-mirror': ('Debian security updated mirror', lambda: build_defaults['debian_security_mirror'], None), + 'pbuilder-debian-mirror': ('Debian repository mirror for pbuilder env bootstrap', lambda: build_defaults['debian_mirror'], None), + 'vyos-mirror': ('VyOS package mirror', lambda: build_defaults["vyos_mirror"], None), 'build-type': ('Build type, release or development', lambda: 'development', lambda x: x in ['release', 'development']), - 'custom-packages': ('Custom packages to install from repositories', lambda: '', None), 'version': ('Version number (release builds only)', None, None) } @@ -80,6 +89,7 @@ parser.add_argument('--debug', help="Enable debug output", action='store_true') # Custom APT entry and APT key options can be used multiple times parser.add_argument('--custom-apt-entry', help="Custom APT entry", action='append') parser.add_argument('--custom-apt-key', help="Custom APT key file", action='append') +parser.add_argument('--custom-package', help="Custom package to install from repositories", action='append') args = vars(parser.parse_args()) @@ -95,8 +105,8 @@ for k, v in args.items(): # Some fixup for mirror settings. # The idea is: if --debian-mirror is specified but --pbuilder-debian-mirror is not, # use the --debian-mirror value for both lb and pbuilder bootstrap -if (args['debian_mirror'] != defaults.DEBIAN_MIRROR) and \ - (args['pbuilder_debian_mirror'] == defaults.DEBIAN_MIRROR): +if (args['debian_mirror'] != build_defaults["debian_mirror"]) and \ + (args['pbuilder_debian_mirror'] == build_defaults["debian_mirror"]): args['pbuilder_debian_mirror'] = args['debian_mirror'] # Version can only be set for release builds, @@ -109,16 +119,19 @@ if args['build_type'] == 'development': # Populate some defaults that are not configurable, # but that are handy to have in the options hash -args['distribution'] = defaults.DEBIAN_DISTRIBUTION +args['distribution'] = build_defaults["debian_distribution"] args['build_dir'] = os.path.join(os.getcwd(), defaults.BUILD_DIR) args['pbuilder_config'] = defaults.PBUILDER_CONFIG -args['vyos_branch'] = defaults.VYOS_BRANCH +args['vyos_branch'] = build_defaults["vyos_branch"] -# Convert a whitespace-separated string of custom packages to a list -if args['custom_packages']: - args['custom_packages'] = re.split(r'\s+', args['custom_packages']) -else: - args['custom_packages'] = [] +# Add custom packages from build defaults +if not args['custom_package']: + args['custom_package'] = [] +args['custom_package'] = args['custom_package'] + build_defaults['custom_packages'] + +if not args['custom_apt_entry']: + args['custom_apt_entry'] = [] +args['custom_apt_entry'] = args['custom_apt_entry'] + build_defaults['additional_repositories'] # Check the build environment and dependencies @@ -126,10 +139,8 @@ env_check_retval = os.system("scripts/check-build-env") if env_check_retval > 0: print("Build environment check failed, fix the issues and retry") -# Get the kernel version from data/kernel_version -with open("data/kernel_version") as f: - kernel_version = f.read().strip() - args['kernel_version'] = kernel_version +args['kernel_version'] = build_defaults['kernel_version'] +args['kernel_flavor'] = build_defaults['kernel_flavor'] # Save to file @@ -138,3 +149,4 @@ print("Saving the build config to {0}".format(defaults.BUILD_CONFIG)) with open(defaults.BUILD_CONFIG, 'w') as f: json.dump(args, f, indent=4, sort_keys=True) print("\n", file=f) + diff --git a/scripts/build-submodules b/scripts/build-submodules index e6e9cda3..fc8fdf83 100755 --- a/scripts/build-submodules +++ b/scripts/build-submodules @@ -343,7 +343,6 @@ build_kernel() { PATCHLEVEL=$(grep "^PATCHLEVEL" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') SUBLEVEL=$(grep "^SUBLEVEL" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') ARCH=$(dpkg --print-architecture) - echo "$VERSION.$PATCHLEVEL.$SUBLEVEL" > $ROOTDIR/data/kernel_version status_ok } build_kernel diff --git a/scripts/defaults.py b/scripts/defaults.py index 5f1941c1..5d489e48 100644 --- a/scripts/defaults.py +++ b/scripts/defaults.py @@ -21,27 +21,16 @@ import os BUILD_DIR = 'build' BUILD_CONFIG = os.path.join(BUILD_DIR, 'build-config.json') -# The default mirror was chosen entirely at random -DEBIAN_MIRROR = 'http://deb.debian.org/debian' -DEBIAN_SECURITY_MIRROR = 'http://deb.debian.org/debian-security' - -DEBIAN_DISTRIBUTION = 'jessie' - -SALT_MIRROR = 'http://repo.saltstack.com/apt/debian/8/amd64/2017.7' -PDNS_MIRROR = 'http://repo.powerdns.com/debian' - PBUILDER_CONFIG = os.path.join(BUILD_DIR, 'pbuilderrc') PBUILDER_DIR = os.path.join(BUILD_DIR, 'pbuilder') LB_CONFIG_DIR = os.path.join(BUILD_DIR, 'config') CHROOT_INCLUDES_DIR = os.path.join(LB_CONFIG_DIR, 'includes.chroot') -VYOS_MIRROR = 'http://dev.packages.vyos.net/repositories/current' - -VYOS_BRANCH = 'current' - ARCHIVES_DIR = 'config/archives/' VYOS_REPO_FILE = 'config/archives/vyos.list.chroot' CUSTOM_REPO_FILE = 'config/archives/custom.list.chroot' CUSTOM_PACKAGE_LIST_FILE = 'config/package-lists/custom.list.chroot' + +DEFAULT_BUILD_FLAVOR = 'data/defaults.json' diff --git a/scripts/live-build-config b/scripts/live-build-config index 1aea4dc5..f158ba5c 100755 --- a/scripts/live-build-config +++ b/scripts/live-build-config @@ -36,12 +36,12 @@ lb_config_tmpl = """ lb config noauto \ --architectures {{architecture}} \ --bootappend-live "boot=live components hostname=vyos username=live nopersistence noautologin nonetworking union=overlay" \ - --linux-flavours {{architecture}}-vyos \ + --linux-flavours {{kernel_flavor}} \ --linux-packages linux-image-{{kernel_version}} \ --bootloader syslinux,grub-efi \ --binary-images iso-hybrid \ --debian-installer false \ - --distribution jessie \ + --distribution {{distribution}} \ --iso-application "VyOS" \ --iso-publisher "{{build_by}}" \ --iso-volume "VyOS" \ @@ -70,8 +70,6 @@ debug = build_config['debug'] print("Setting up additional APT entries") vyos_repo_entry = "deb {0}/vyos {1} main\n".format(build_config['vyos_mirror'], build_config['vyos_branch']) vyos_debian_repo_entry = "deb {0}/debian {1} main\n".format(build_config['vyos_mirror'], build_config['vyos_branch']) -salt_repo_entry = "deb {0} {1} main\n".format(build_config['salt_mirror'], build_config['distribution']) -pdns_repo_entry = "deb {0} {1}-rec-41 main\n".format(build_config['pdns_mirror'], build_config['distribution']) apt_file = os.path.join(build_config['build_dir'], defaults.VYOS_REPO_FILE) @@ -79,14 +77,10 @@ if debug: print("Adding these entries to {0}:".format(apt_file)) print("\t", vyos_repo_entry) print("\t", vyos_debian_repo_entry) - print("\t", salt_repo_entry) - print("\t", pdns_repo_entry) with open(apt_file, 'w') as f: f.write(vyos_repo_entry) f.write(vyos_debian_repo_entry) - f.write(salt_repo_entry) - f.write(pdns_repo_entry) # Add custom APT entries if build_config['custom_apt_entry']: @@ -97,6 +91,7 @@ if build_config['custom_apt_entry']: print(entries) with open(custom_apt_file, 'w') as f: f.write(entries) + f.write("\n") # Add custom APT keys if build_config['custom_apt_key']: @@ -106,9 +101,9 @@ if build_config['custom_apt_key']: shutil.copy(k, os.path.join(key_dir, dst_name)) # Add custom packages -if build_config['custom_packages']: +if build_config['custom_package']: package_list_file = os.path.join(build_config['build_dir'], defaults.CUSTOM_PACKAGE_LIST_FILE) - packages = "\n".join(build_config['custom_packages']) + packages = "\n".join(build_config['custom_package']) with open (package_list_file, 'w') as f: f.write(packages) |