Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions runbot/models/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class BuildParameters(models.Model):

build_ids = fields.One2many('runbot.build', 'params_id')
builds_reference_ids = fields.Many2many('runbot.build', relation='runbot_build_params_references', copy=True)
reference_build_id = fields.Many2one('runbot.build', 'Reference Build', index=True)
modules = fields.Char('Modules')

upgrade_to_build_id = fields.Many2one('runbot.build', index=True) # use to define sources to use with upgrade script
Expand Down Expand Up @@ -145,6 +146,8 @@ def get_commit_links_ident(commit_link):
'dockerfile_id': param.dockerfile_id.id,
'skip_requirements': param.skip_requirements,
}
if param.reference_build_id:
cleaned_vals['reference_build_id'] = param.reference_build_id.id
if param.upgrade_to_build_id:
cleaned_vals['upgrade_to_build_dockerfile_id'] = param.upgrade_to_build_id.params_id.dockerfile_id.id
cleaned_vals['upgrade_to_build_commits'] = get_commit_links_ident(param.upgrade_to_build_id.params_id.commit_link_ids)
Expand Down Expand Up @@ -525,7 +528,7 @@ def write(self, values):

return res

def _add_child(self, param_values, orphan=False, description=False, additionnal_commit_links=False):
def _add_child(self, param_values, orphan=False, description=False, additionnal_commit_links=False, use_parent=...):
build_values = {key: value for key, value in param_values.items() if key not in self.params_id._fields}
param_values = {key: value for key, value in param_values.items() if key in self.params_id._fields}

Expand All @@ -538,6 +541,15 @@ def _add_child(self, param_values, orphan=False, description=False, additionnal_
commit_link_ids |= additionnal_commit_links
param_values['commit_link_ids'] = commit_link_ids

config = param_values.get('config_id') or self.params_id.config_id
if isinstance(config, int):
config = self.env['runbot.build.config'].browse(config)

if use_parent == ...:
use_parent = config._default_uses_parent(param_values)
if use_parent:
param_values['reference_build_id'] = self.id

return self.create({
'params_id': self.params_id.copy(param_values).id,
'parent_id': self.id,
Expand Down Expand Up @@ -1396,8 +1408,9 @@ def _cmd(self, python_params=None, py_version=None, local_only=True, sub_command

faketime = []
if faketime_params := self.params_id.config_data.get('faketime'):
if self.parent_id:
parent_time_offset = (self.parent_id.build_end or self.create_date) - self.parent_id.build_start
reference_build = self.params_id.reference_build_id or self.parent_id # TODO cleanup parent_id
if reference_build:
parent_time_offset = (reference_build.build_end or self.create_date) - reference_build.build_start
faketime_params = (parser.parse(faketime_params) + parent_time_offset).strftime('%Y-%m-%d %H:%M %Z')
faketime = ['faketime', faketime_params]

Expand Down
23 changes: 20 additions & 3 deletions runbot/models/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def VARS(vars, path):
'max_builds': OPTIONAL(INT),
'if': OPTIONAL(DYNAMIC_VALUE),
'log': OPTIONAL(DYNAMIC_VALUE),
'use_parent': OPTIONAL(BOOL),
}
valid_steps['restore'] = {
'name': REQUIRED(NAME),
Expand Down Expand Up @@ -371,6 +372,18 @@ def _check_recursion(self, visited=None):
for create_config in step.create_config_ids:
create_config._check_recursion(visited[:])

def _default_uses_parent(self, param_values):
if param_values.get('dump_db'):
return False
config_data = param_values.get('config_data', {}) or {}
if config_data.get('dump_url'):
return False
if config_data.get('restore_build_id'):
return False
if config_data.get('dump_trigger_id'):
return False
return any(step.job_type == 'restore' for step in self.step_ids)


class ConfigStepUpgradeDb(models.Model):
_name = 'runbot.config.step.upgrade.db'
Expand Down Expand Up @@ -589,7 +602,7 @@ def _run_step(self, build, **kwargs):
return build._docker_run(self, **docker_params)
return True

def _run_create_build(self, build, config_data=None, max_build=200):
def _run_create_build(self, build, config_data=None, max_build=200, use_parent=...):
if config_data:
config_data = {**config_data, **build.params_id.config_data}
else:
Expand All @@ -613,7 +626,7 @@ def _run_create_build(self, build, config_data=None, max_build=200):
build._log('create_build', f'More than {max_build} build created, stopping', level='WARNING')
return
config_name = config_name or create_config.name
child = build._add_child(child_data_values, orphan=self.make_orphan, description=description or config_name)
child = build._add_child(child_data_values, orphan=self.make_orphan, description=description or config_name, use_parent=use_parent)
build._log('create_build', 'created with config %s' % config_name, log_type='subbuild', path=str(child.id))

def _make_python_ctx(self, build):
Expand Down Expand Up @@ -1122,7 +1135,7 @@ def _run_restore(self, build, config_data=None):
dump_build = dump_db.build_id
else:
download_db_suffix = config_data.get('dump_suffix', self.restore_download_db_suffix or 'all')
dump_build = build.parent_id
dump_build = params.reference_build_id or build.parent_id # TODO cleanup parent_id
assert download_db_suffix and dump_build
download_db_name = '%s-%s' % (dump_build.dest, download_db_suffix)
zip_name = '%s.zip' % download_db_name
Expand Down Expand Up @@ -1604,11 +1617,15 @@ def _run_dynamic(self, build):
'config_name': config_name,
'description': description,
}
if current_step.get('use_parent') or (current_step.get('use_parent') is None and any(step.get('job_type') == 'restore' for step in child.get('steps', []))):
# TODO improve, not needed is other restore params are given
child_data['reference_build_id'] = build.id
child_data_list.append(child_data)
return self._run_create_build(
build,
{'child_data': child_data_list, 'number_build': current_step.get('number_builds', 1)},
max_build=min(current_step.get('max_builds', 20), 200),
use_parent=current_step.get('use_parent', ...)
)

if current_step['job_type'] == 'restore':
Expand Down