mirror of
https://github.com/vyos/vyos-build.git
synced 2025-10-01 20:28:40 +02:00
build-script: T3664: Allowed all options in both config file and command args
Moved defaults away from argparser to `defaults.py`. This unlocks the ability to pass values that can be defined as command line arguments via a config file. With this change logic looks like this (in order of overrides). Pre-build config: `data/defaults.toml` -> `build-flavors/<flavor>.toml` -> `--<command line argument>` Build config: `defaults.py` -> `data/defaults.toml` -> `build-types/<type>.toml` -> `architectures/<architecture>.toml` -> `build-flavors/<flavor>.toml` -> `--<command line argument>`
This commit is contained in:
parent
eff3d4aab6
commit
8186e82024
@ -26,8 +26,6 @@ import uuid
|
|||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
import getpass
|
|
||||||
import platform
|
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
@ -130,12 +128,9 @@ except OSError as e:
|
|||||||
def field_to_option(s):
|
def field_to_option(s):
|
||||||
return re.sub(r'_', '-', s)
|
return re.sub(r'_', '-', s)
|
||||||
|
|
||||||
def get_default_build_by():
|
|
||||||
return "{user}@{host}".format(user= getpass.getuser(), host=platform.node())
|
|
||||||
|
|
||||||
def get_validator(optdict, name):
|
def get_validator(optdict, name):
|
||||||
try:
|
try:
|
||||||
return optdict[name][2]
|
return optdict[name][1]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -190,38 +185,35 @@ if __name__ == "__main__":
|
|||||||
# Options dict format:
|
# Options dict format:
|
||||||
# '$option_name_without_leading_dashes': { ('$help_string', $default_value_generator_thunk, $value_checker_thunk) }
|
# '$option_name_without_leading_dashes': { ('$help_string', $default_value_generator_thunk, $value_checker_thunk) }
|
||||||
options = {
|
options = {
|
||||||
'architecture': ('Image target architecture (amd64 or arm64)', None, lambda x: x in ['amd64', 'arm64', None]),
|
'architecture': ('Image target architecture (amd64 or arm64)', lambda x: x in ['amd64', 'arm64', None]),
|
||||||
'build-by': ('Builder identifier (e.g. jrandomhacker@example.net)', get_default_build_by, None),
|
'build-by': ('Builder identifier (e.g. jrandomhacker@example.net)', None),
|
||||||
'debian-mirror': ('Debian repository mirror', None, None),
|
'debian-mirror': ('Debian repository mirror', None),
|
||||||
'debian-security-mirror': ('Debian security updates mirror', None, None),
|
'debian-security-mirror': ('Debian security updates mirror', None),
|
||||||
'pbuilder-debian-mirror': ('Debian repository mirror for pbuilder env bootstrap', None, None),
|
'pbuilder-debian-mirror': ('Debian repository mirror for pbuilder env bootstrap', None),
|
||||||
'vyos-mirror': ('VyOS package mirror', None, None),
|
'vyos-mirror': ('VyOS package mirror', None),
|
||||||
'build-type': ('Build type, release or development', None, lambda x: x in ['release', 'development']),
|
'build-type': ('Build type, release or development', lambda x: x in ['release', 'development']),
|
||||||
'version': ('Version number (release builds only)', None, None),
|
'version': ('Version number (release builds only)', None),
|
||||||
'build-comment': ('Optional build comment', lambda: '', None)
|
'build-comment': ('Optional build comment', None)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create the option parser
|
# Create the option parser
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
for k, v in options.items():
|
for k, v in options.items():
|
||||||
help_string, default_value_thunk = v[0], v[1]
|
help_string = v[0]
|
||||||
if default_value_thunk is None:
|
parser.add_argument('--' + k, type=str, help=help_string)
|
||||||
parser.add_argument('--' + k, type=str, help=help_string)
|
|
||||||
else:
|
|
||||||
parser.add_argument('--' + k, type=str, help=help_string, default=default_value_thunk())
|
|
||||||
|
|
||||||
# Debug options
|
# Debug options
|
||||||
parser.add_argument('--debug', help='Enable debug output', action='store_true')
|
parser.add_argument('--debug', help='Enable debug output', action='store_true')
|
||||||
parser.add_argument('--dry-run', help='Check build configuration and exit', action='store_true')
|
parser.add_argument('--dry-run', help='Check build configuration and exit', action='store_true')
|
||||||
|
|
||||||
# Custom APT entry and APT key options can be used multiple times
|
# Custom APT entry and APT key options can be used multiple times
|
||||||
parser.add_argument('--custom-apt-entry', help="Custom APT entry", action='append', default=[])
|
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', default=[])
|
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', default=[])
|
parser.add_argument('--custom-package', help="Custom package to install from repositories", action='append')
|
||||||
|
|
||||||
# Options relevant for non-ISO format flavors
|
# Options relevant for non-ISO format flavors
|
||||||
parser.add_argument('--reuse-iso', help='Use an existing ISO file to build additional image formats', type=str, action='store', default=None)
|
parser.add_argument('--reuse-iso', help='Use an existing ISO file to build additional image formats', type=str, action='store')
|
||||||
parser.add_argument('--disk-size', help='Disk size for non-ISO image formats', type=int, action='store', default=10)
|
parser.add_argument('--disk-size', help='Disk size for non-ISO image formats', type=int, action='store')
|
||||||
|
|
||||||
# Build flavor is a positional argument
|
# Build flavor is a positional argument
|
||||||
parser.add_argument('build_flavor', help='Build flavor', nargs='?', action='store')
|
parser.add_argument('build_flavor', help='Build flavor', nargs='?', action='store')
|
||||||
@ -295,8 +287,11 @@ if __name__ == "__main__":
|
|||||||
args['build_dir'] = defaults.BUILD_DIR
|
args['build_dir'] = defaults.BUILD_DIR
|
||||||
args['pbuilder_config'] = os.path.join(defaults.BUILD_DIR, defaults.PBUILDER_CONFIG)
|
args['pbuilder_config'] = os.path.join(defaults.BUILD_DIR, defaults.PBUILDER_CONFIG)
|
||||||
|
|
||||||
|
## Add hardcoded defaults
|
||||||
|
build_config = merge_defaults(defaults.HARDCODED_BUILD, defaults={})
|
||||||
|
|
||||||
## Combine the arguments with non-configurable defaults
|
## Combine the arguments with non-configurable defaults
|
||||||
build_config = copy.deepcopy(build_defaults)
|
build_config = merge_defaults(build_defaults, defaults=build_config)
|
||||||
|
|
||||||
## Load correct mix-ins
|
## Load correct mix-ins
|
||||||
with open(make_toml_path(defaults.BUILD_TYPES_DIR, pre_build_config["build_type"]), 'rb') as f:
|
with open(make_toml_path(defaults.BUILD_TYPES_DIR, pre_build_config["build_type"]), 'rb') as f:
|
||||||
|
|||||||
@ -17,6 +17,11 @@
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import getpass
|
||||||
|
import platform
|
||||||
|
|
||||||
|
def get_default_build_by():
|
||||||
|
return "{user}@{host}".format(user= getpass.getuser(), host=platform.node())
|
||||||
|
|
||||||
# Default boot settings
|
# Default boot settings
|
||||||
boot_settings: dict[str, str] = {
|
boot_settings: dict[str, str] = {
|
||||||
@ -27,6 +32,17 @@ boot_settings: dict[str, str] = {
|
|||||||
'bootmode': 'normal'
|
'bootmode': 'normal'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Hardcoded default values
|
||||||
|
HARDCODED_BUILD = {
|
||||||
|
'custom_apt_entry': [],
|
||||||
|
'custom_apt_key': [],
|
||||||
|
'custom_package': [],
|
||||||
|
'reuse_iso': None,
|
||||||
|
'disk_size': 10,
|
||||||
|
'build_by': get_default_build_by(),
|
||||||
|
'build_comment': '',
|
||||||
|
}
|
||||||
|
|
||||||
# Relative to the repository directory
|
# Relative to the repository directory
|
||||||
|
|
||||||
BUILD_DIR = 'build'
|
BUILD_DIR = 'build'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user