Improve Buildah clean method

This commit is contained in:
jpic 2020-05-31 03:40:00 +02:00
parent 93b95a1f50
commit c6d7eedde2

View File

@ -126,33 +126,33 @@ class Buildah(Target):
return self.image.layer(sha1.hexdigest()) return self.image.layer(sha1.hexdigest())
async def action(self, action, reraise=False): async def action(self, action, reraise=False):
result = await super().action(action, reraise) stop = await super().action(action, reraise)
action_image = await self.action_image(action) if not stop:
await self.parent.exec( action_image = await self.action_image(action)
'buildah', await self.parent.exec(
'commit', 'buildah',
'--format=' + action_image.format, 'commit',
self.ctr, '--format=' + action_image.format,
action_image, self.ctr,
) action_image,
self.image_previous = action_image )
return result self.image_previous = action_image
return stop
async def clean(self, target): async def clean(self, target):
for src, dst in self.mounts.items(): for src, dst in self.mounts.items():
await self.parent.exec('umount', self.root / str(dst)[1:]) await self.parent.exec('umount', self.root / str(dst)[1:])
if self.result.status == 'success':
await self.commit()
if self.root is not None: if self.root is not None:
await self.parent.exec('buildah', 'umount', self.ctr) await self.parent.exec('buildah', 'umount', self.ctr)
if self.ctr is not None: if self.ctr is not None:
if self.result.status == 'success':
await self.commit()
await self.parent.exec('buildah', 'rm', self.ctr) await self.parent.exec('buildah', 'rm', self.ctr)
if self.result.status == 'success': if self.result.status == 'success' and os.getenv('BUILDAH_PUSH'):
if os.getenv('BUILDAH_PUSH'):
await self.image.push(target) await self.image.push(target)
async def mount(self, src, dst): async def mount(self, src, dst):