def main(): parser = argparse.ArgumentParser() parser.add_argument('--outfile', default='tasks.yaml') parsed = parser.parse_args() build_task_yaml_path = os.path.join(paths.own_dir, 'build-task.yaml.template') with open(build_task_yaml_path) as f: raw_build_task = yaml.safe_load(f) promote_task = tasks.promote_task( committish=NamedParam(name='committish'), gardenlinux_epoch=NamedParam(name='gardenlinux_epoch'), snapshot_timestamp=NamedParam(name='snapshot_timestamp'), cicd_cfg_name=NamedParam(name='cicd_cfg_name'), version=NamedParam(name='version'), promote_target=NamedParam(name='promote_target'), promote_mode=NamedParam(name='promote_mode'), flavourset=NamedParam(name='flavourset'), ) raw_promote_task = dataclasses.asdict(promote_task) clone_step = steps.clone_step( committish=tkn.model.NamedParam(name='committish'), repo_dir=tkn.model.NamedParam(name='repodir'), git_url=tkn.model.NamedParam(name='giturl'), ) clone_step_dict = dataclasses.asdict(clone_step) upload_step = steps.upload_results_step( cicd_cfg_name=NamedParam(name='cicd_cfg_name'), committish=NamedParam(name='committish'), architecture=NamedParam(name='architecture'), platform=NamedParam(name='platform'), gardenlinux_epoch=NamedParam(name='gardenlinux_epoch'), fnameprefix=NamedParam(name='fnameprefix'), modifiers=NamedParam(name='modifiers'), version=NamedParam(name='version'), outfile=NamedParam(name='outfile'), repo_dir=tkn.model.NamedParam(name='repodir'), ) upload_step_dict = dataclasses.asdict(upload_step) # hack: patch-in clone-step (avoid redundancy with other tasks) raw_build_task['spec']['steps'][0] = clone_step_dict raw_build_task['spec']['steps'][-1] = upload_step_dict with open(parsed.outfile, 'w') as f: yaml.safe_dump_all((raw_build_task, raw_promote_task), f) print(f'dumped tasks to {parsed.outfile}')
def main(): parser = argparse.ArgumentParser() parser.add_argument('--use-secrets-server', action='store_true') parser.add_argument('--outfile', default='tasks.yaml') parsed = parser.parse_args() if not parsed.use_secrets_server: env_vars = [{ 'name': 'SECRETS_SERVER_CACHE', 'value': '/secrets/config.json', }] volume_mounts = [{ 'name': 'secrets', 'mountPath': '/secrets', }] else: env_vars = [] volume_mounts = [] build_task_yaml_path = os.path.join(paths.own_dir, 'build-task.yaml.template') with open(build_task_yaml_path) as f: raw_build_task = yaml.safe_load(f) promote_task = tasks.promote_task( branch=NamedParam(name='branch'), cicd_cfg_name=NamedParam(name='cicd_cfg_name'), committish=NamedParam(name='committish'), flavourset=NamedParam(name='flavourset'), gardenlinux_epoch=NamedParam(name='gardenlinux_epoch'), publishing_actions=NamedParam(name='publishing_actions'), snapshot_timestamp=NamedParam(name='snapshot_timestamp'), version=NamedParam(name='version'), env_vars=env_vars, volume_mounts=volume_mounts, ) raw_promote_task = dataclasses.asdict(promote_task) clone_step = steps.clone_step( committish=NamedParam(name='committish'), git_url=NamedParam(name='giturl'), repo_dir=NamedParam(name='repodir'), env_vars=env_vars, volume_mounts=volume_mounts, ) clone_step_dict = dataclasses.asdict(clone_step) pre_build_step = steps.pre_build_step( architecture=NamedParam(name='architecture'), cicd_cfg_name=NamedParam(name='cicd_cfg_name'), committish=NamedParam(name='committish'), gardenlinux_epoch=NamedParam(name='gardenlinux_epoch'), modifiers=NamedParam(name='modifiers'), platform=NamedParam(name='platform'), publishing_actions=NamedParam(name='publishing_actions'), repo_dir=NamedParam(name='repodir'), version=NamedParam(name='version'), env_vars=env_vars, volume_mounts=volume_mounts, ) pre_build_step_dict = dataclasses.asdict(pre_build_step) upload_step = steps.upload_results_step( architecture=NamedParam(name='architecture'), cicd_cfg_name=NamedParam(name='cicd_cfg_name'), committish=NamedParam(name='committish'), gardenlinux_epoch=NamedParam(name='gardenlinux_epoch'), modifiers=NamedParam(name='modifiers'), outfile=NamedParam(name='outfile'), platform=NamedParam(name='platform'), publishing_actions=NamedParam(name='publishing_actions'), repo_dir=NamedParam(name='repodir'), version=NamedParam(name='version'), env_vars=env_vars, volume_mounts=volume_mounts, ) upload_step_dict = dataclasses.asdict(upload_step) promote_step = steps.promote_single_step( architecture=NamedParam(name='architecture'), cicd_cfg_name=NamedParam(name='cicd_cfg_name'), committish=NamedParam(name='committish'), gardenlinux_epoch=NamedParam(name='gardenlinux_epoch'), modifiers=NamedParam(name='modifiers'), platform=NamedParam(name='platform'), publishing_actions=NamedParam(name='publishing_actions'), repo_dir=NamedParam(name='repodir'), version=NamedParam(name='version'), env_vars=env_vars, volume_mounts=volume_mounts, ) promote_step_dict = dataclasses.asdict(promote_step) # hack: patch-in clone-step (avoid redundancy with other tasks) raw_build_task['spec']['steps'][0] = clone_step_dict raw_build_task['spec']['steps'][1] = pre_build_step_dict raw_build_task['spec']['steps'][-1] = upload_step_dict raw_build_task['spec']['steps'].append(promote_step_dict) if not parsed.use_secrets_server: print(raw_build_task['spec']['volumes']) raw_build_task['spec']['volumes'].append({ 'name': 'secrets', 'secret': { 'secretname': 'secrets', } }) with open(parsed.outfile, 'w') as f: yaml.safe_dump_all((raw_build_task, raw_promote_task), f) print(f'dumped tasks to {parsed.outfile}')
def build_task( env_vars, volume_mounts, volumes=[], ): params = _get_build_and_test_parameters() clone_step = steps.clone_step( committish=params.committish, git_url=params.giturl, repo_dir=_repodir, env_vars=env_vars, volume_mounts=volume_mounts, ) pre_build_step = steps.pre_build_step( architecture=params.arch, cicd_cfg_name=params.cicd_cfg_name, committish=params.committish, gardenlinux_epoch=params.glepoch, modifiers=params.modifiers, platform=params.platform, publishing_actions=params.publishing_actions, repo_dir=_repodir, version=params.version, env_vars=env_vars, volume_mounts=volume_mounts, ) build_image_step = steps.build_image_step( arch=params.arch, suite=params.suite, gardenlinux_epoch=params.glepoch, timestamp=params.snapshot_ts, platform=params.platform, modifiers=params.modifiers, committish=params.committish, gardenversion=params.version, env_vars=env_vars, volume_mounts=volume_mounts, repo_dir=_repodir, ) upload_step = steps.upload_results_step( architecture=params.arch, cicd_cfg_name=params.cicd_cfg_name, committish=params.committish, gardenlinux_epoch=params.glepoch, modifiers=params.modifiers, outfile=params.outfile, platform=params.platform, publishing_actions=params.publishing_actions, repo_dir=_repodir, version=params.version, env_vars=env_vars, volume_mounts=volume_mounts, ) task_volumes = [v for v in volumes] task_volumes.extend( [{ 'name': 'dev', 'hostPath': {'path': '/dev', 'type': 'Directory'}, }, { 'name': 'build', 'emptyDir': {'medium': 'Memory'}, }] ) return tkn.model.Task( metadata=tkn.model.Metadata(name='build-gardenlinux-task'), spec=tkn.model.TaskSpec( params=[ params.arch, params.build_image, params.cicd_cfg_name, params.committish, params.flavourset, params.giturl, params.glepoch, params.modifiers, params.outfile, params.platform, params.promote_target, params.publishing_actions, _repodir, params.snapshot_ts, params.suite, params.version, ], steps=[ clone_step, pre_build_step, build_image_step, upload_step, ], volumes=task_volumes, ), )
def build_task( env_vars, volume_mounts, volumes=[], ): params = [all_params.build_image, all_params.gardenlinux_build_deb_image] clone_step, params_step = steps.clone_step( params=all_params, env_vars=env_vars, volume_mounts=volume_mounts, ) params += params_step pre_build_step, params_step = steps.pre_build_step( params=all_params, env_vars=env_vars, volume_mounts=volume_mounts, ) params += params_step write_key_step, params_step = steps.write_key_step( params=all_params, env_vars=env_vars, volume_mounts=volume_mounts, ) params += params_step build_certs_step, params_step = steps.build_cert_step( params=all_params, env_vars=env_vars, volume_mounts=volume_mounts, ) params += params_step build_image_step, params_step = steps.build_image_step( params=all_params, env_vars=env_vars, volume_mounts=volume_mounts, ) params += params_step upload_step, params_step = steps.upload_results_step( params=all_params, env_vars=env_vars, volume_mounts=volume_mounts, ) params += params_step promote_step, params_step = steps.promote_single_step( params=all_params, env_vars=env_vars, volume_mounts=volume_mounts, ) params += params_step task_volumes = [v for v in volumes] task_volumes.extend( [{ 'name': 'dev', 'hostPath': {'path': '/dev', 'type': 'Directory'}, }, { 'name': 'build', 'emptyDir': {'medium': 'Memory'}, }] ) task_steps = [ clone_step, pre_build_step, write_key_step, build_certs_step, build_image_step, upload_step, promote_step, ] params = unify_params(params) return tkn.model.Task( metadata=tkn.model.Metadata(name='build-gardenlinux-task'), spec=tkn.model.TaskSpec( params=params, steps=task_steps, volumes=task_volumes, ), )