Add config overrides and use it to force rebuild
This commit is contained in:
parent
3755dc15e1
commit
fbd181fd5c
@ -87,11 +87,15 @@ def main():
|
||||
args = parse_args()
|
||||
stages = set(args.stages) - set(args.skip_stages)
|
||||
|
||||
config_override = {}
|
||||
if args.force_rebuild:
|
||||
config_override['rebuild_after'] = {'days': 0}
|
||||
|
||||
cb = cloud_build.CB(
|
||||
config=args.config,
|
||||
tasks=args.tasks,
|
||||
built_images_dir=args.built_images_dir,
|
||||
force_rebuild=args.force_rebuild,
|
||||
config_override=config_override,
|
||||
)
|
||||
|
||||
if 'build' in stages:
|
||||
|
@ -58,13 +58,11 @@ class CB:
|
||||
data_dir: Optional[PathLike] = None,
|
||||
tasks: Optional[dict[str, List[str]]] = None,
|
||||
built_images_dir: Optional[PathLike] = None,
|
||||
force_rebuild: bool = False,
|
||||
config_override: Optional[Dict] = None,
|
||||
) -> None:
|
||||
self.initialized = False
|
||||
self._save_cwd = os.getcwd()
|
||||
self.parse_config(config)
|
||||
if force_rebuild:
|
||||
self.rebuild_after = datetime.timedelta(0)
|
||||
self.parse_config(config, config_override)
|
||||
if tasks is None:
|
||||
self.tasks = {}
|
||||
else:
|
||||
@ -203,7 +201,14 @@ class CB:
|
||||
self.debug(f'Popd from {new_dir}')
|
||||
os.chdir(previous_dir)
|
||||
|
||||
def parse_config(self, config: str) -> None:
|
||||
def parse_config(
|
||||
self,
|
||||
config: str,
|
||||
override: Optional[Dict] = None
|
||||
) -> None:
|
||||
if override is None:
|
||||
override = {}
|
||||
|
||||
try:
|
||||
with open(config) as f:
|
||||
cfg = yaml.safe_load(f)
|
||||
@ -230,7 +235,10 @@ class CB:
|
||||
if self.external_files:
|
||||
self.external_files = self.expand_path(Path(self.external_files))
|
||||
|
||||
rebuild_after = cfg.get('rebuild_after', {'days': 1})
|
||||
rebuild_after = override.get(
|
||||
'rebuild_after',
|
||||
cfg.get('rebuild_after', {'days': 1}),
|
||||
)
|
||||
try:
|
||||
self.rebuild_after = datetime.timedelta(**rebuild_after)
|
||||
except TypeError as e:
|
||||
|
@ -45,7 +45,7 @@ class TestRebuild(TestCase):
|
||||
cb = CB(
|
||||
config='tests/test_rebuild.yaml',
|
||||
data_dir=self.data_dir,
|
||||
force_rebuild=True,
|
||||
config_override={'rebuild_after': {'days': 0}},
|
||||
)
|
||||
msg = 'Do not try to rebuild when force_rebuild'
|
||||
with self.assertRaises(BuildError, msg=msg):
|
||||
|
Loading…
Reference in New Issue
Block a user