Refactor building and signing to be manually run

This commit is contained in:
Mikhail Gordeev 2019-09-07 00:34:55 +03:00
parent d9f3c00355
commit 0a1dd9ecec

View File

@ -34,6 +34,8 @@ class CB:
self.ensure_run_once()
self.checksum_command = 'sha256sum'
self.images_dir = data_dir / 'images'
self.work_dir = data_dir / 'work'
self.out_dir = data_dir / 'out'
@ -471,7 +473,6 @@ Dir::Etc::preferencesparts "/var/empty";
def create_images(self) -> None:
self.clear_imager_dir()
for branch in self.branches:
images_in_branch = []
for image in self.images:
self.ensure_scripts(image)
target = self.target_by_image(image)
@ -494,21 +495,19 @@ Dir::Etc::preferencesparts "/var/empty";
**test,
):
self.error(f'Test for {image} failed')
images_in_branch.append(image_path)
self.checksum_sign(images_in_branch)
self.remove_old_tarballs()
def checksum_sign(self, images):
if len(images) == 0:
self.error('Empty list of images to checksum_sign')
sum_file = 'SHA256SUM'
with self.pushd(os.path.dirname(images[0])):
files = [os.path.basename(x) for x in images]
def sign(self):
sum_file = self.checksum_command.upper()
for branch in self.branches():
with self.pushd(self.images_dir / branch):
files = [f
for f in os.listdir()
if not f.startswith(sum_file)]
string = ','.join(files)
cmd = ['sha256sum'] + files
cmd = [self.checksum_command] + files
self.info(f'Calculate checksum of {string}')
self.call(cmd, stdout_to_file=sum_file)
@ -523,10 +522,12 @@ Dir::Etc::preferencesparts "/var/empty";
self.call(['ssh', host, 'kick'])
def sync(self) -> None:
self.create_images()
for branch in self.branches:
remote = self.remote(branch)
files = glob.glob(f'{self.images_dir}/{branch}/*')
if f'self.checksum_command.upper().asc' not in files:
self.error(f'No checksum signature in branch {branch}')
else:
cmd = ['rsync', '-v'] + files + [remote]
self.call(cmd)
@ -567,6 +568,8 @@ def parse_args():
def main():
args = parse_args()
cloud_build = CB(args.config, args.data_dir)
cloud_build.create_images()
cloud_build.sign()
cloud_build.sync()