1#!/usr/bin/env python3 2 3# Copyright © 2022 Valve Corporation 4# 5# Permission is hereby granted, free of charge, to any person obtaining a 6# copy of this software and associated documentation files (the "Software"), 7# to deal in the Software without restriction, including without limitation 8# the rights to use, copy, modify, merge, publish, distribute, sublicense, 9# and/or sell copies of the Software, and to permit persons to whom the 10# Software is furnished to do so, subject to the following conditions: 11# 12# The above copyright notice and this permission notice (including the next 13# paragraph) shall be included in all copies or substantial portions of the 14# Software. 15# 16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22# IN THE SOFTWARE. 23 24from jinja2 import Environment, FileSystemLoader 25from argparse import ArgumentParser 26from os import environ, path 27 28 29parser = ArgumentParser() 30parser.add_argument('--ci-job-id') 31parser.add_argument('--container-cmd') 32parser.add_argument('--initramfs-url') 33parser.add_argument('--job-success-regex') 34parser.add_argument('--job-warn-regex') 35parser.add_argument('--kernel-url') 36parser.add_argument('--log-level', type=int) 37parser.add_argument('--poweroff-delay', type=int) 38parser.add_argument('--session-end-regex') 39parser.add_argument('--session-reboot-regex') 40parser.add_argument('--tags', nargs='?', default='') 41parser.add_argument('--template', default='b2c.yml.jinja2.jinja2') 42parser.add_argument('--timeout-boot-minutes', type=int) 43parser.add_argument('--timeout-boot-retries', type=int) 44parser.add_argument('--timeout-first-minutes', type=int) 45parser.add_argument('--timeout-first-retries', type=int) 46parser.add_argument('--timeout-minutes', type=int) 47parser.add_argument('--timeout-overall-minutes', type=int) 48parser.add_argument('--timeout-retries', type=int) 49parser.add_argument('--job-volume-exclusions', nargs='?', default='') 50parser.add_argument('--volume', action='append') 51parser.add_argument('--mount-volume', action='append') 52parser.add_argument('--local-container', default=environ.get('B2C_LOCAL_CONTAINER', 'alpine:latest')) 53parser.add_argument('--working-dir') 54args = parser.parse_args() 55 56env = Environment(loader=FileSystemLoader(path.dirname(args.template)), 57 trim_blocks=True, lstrip_blocks=True) 58 59template = env.get_template(path.basename(args.template)) 60 61values = {} 62values['ci_job_id'] = args.ci_job_id 63values['container_cmd'] = args.container_cmd 64values['initramfs_url'] = args.initramfs_url 65values['job_success_regex'] = args.job_success_regex 66values['job_warn_regex'] = args.job_warn_regex 67values['kernel_url'] = args.kernel_url 68values['log_level'] = args.log_level 69values['poweroff_delay'] = args.poweroff_delay 70values['session_end_regex'] = args.session_end_regex 71values['session_reboot_regex'] = args.session_reboot_regex 72values['tags'] = args.tags 73values['template'] = args.template 74values['timeout_boot_minutes'] = args.timeout_boot_minutes 75values['timeout_boot_retries'] = args.timeout_boot_retries 76values['timeout_first_minutes'] = args.timeout_first_minutes 77values['timeout_first_retries'] = args.timeout_first_retries 78values['timeout_minutes'] = args.timeout_minutes 79values['timeout_overall_minutes'] = args.timeout_overall_minutes 80values['timeout_retries'] = args.timeout_retries 81if len(args.job_volume_exclusions) > 0: 82 exclusions = args.job_volume_exclusions.split(",") 83 values['job_volume_exclusions'] = [excl for excl in exclusions if len(excl) > 0] 84if args.volume is not None: 85 values['volumes'] = args.volume 86if args.mount_volume is not None: 87 values['mount_volumes'] = args.mount_volume 88values['working_dir'] = args.working_dir 89 90assert(len(args.local_container) > 0) 91values['local_container'] = args.local_container.replace( 92 # Use the gateway's pull-through registry cache to reduce load on fd.o. 93 'registry.freedesktop.org', '{{ fdo_proxy_registry }}' 94) 95 96if 'B2C_KERNEL_CMDLINE_EXTRAS' in environ: 97 values['cmdline_extras'] = environ['B2C_KERNEL_CMDLINE_EXTRAS'] 98 99f = open(path.splitext(path.basename(args.template))[0], "w") 100f.write(template.render(values)) 101f.close() 102