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