Prevent double clean

This commit is contained in:
jpic 2020-02-16 19:57:44 +01:00
parent ba87dea428
commit ee25255028
5 changed files with 15 additions and 19 deletions

View File

@ -111,9 +111,8 @@ class Action:
self.output = self.output_factory(*args, **kwargs) self.output = self.output_factory(*args, **kwargs)
self.output_start() self.output_start()
self.status = 'running' self.status = 'running'
call = getattr(self, kwargs.pop('method', 'call'))
try: try:
result = await call(*args, **kwargs) result = await self.call(*args, **kwargs)
except Exception as e: except Exception as e:
self.output_fail(e) self.output_fail(e)
self.status = 'fail' self.status = 'fail'

View File

@ -62,3 +62,14 @@ class Image:
def __str__(self): def __str__(self):
return f'{self.repository}:{self.tags[-1]}' return f'{self.repository}:{self.tags[-1]}'
async def push(self, *args, **kwargs):
user = os.getenv('DOCKER_USER')
passwd = os.getenv('DOCKER_PASS')
action = kwargs.get('action', self)
if user and passwd:
action.output.cmd('buildah login -u ... -p ...' + self.registry)
await action.exec('buildah', 'login', '-u', user, '-p', passwd, self.registry or 'docker.io', debug=False)
for tag in self.tags:
await action.exec('buildah', 'push', f'{self.repository}:{tag}')

View File

@ -119,7 +119,7 @@ class Output:
])) ]))
def start(self, action): def start(self, action):
if self.debug is True: if self.debug is True or 'visit' in str(self.debug):
self(''.join([ self(''.join([
self.colors['orangebold'], self.colors['orangebold'],
'⚠ START ', '⚠ START ',

View File

@ -18,7 +18,7 @@ class Container(Script):
)(**kwargs) )(**kwargs)
if not args or 'push' in args: if not args or 'push' in args:
await self.kwargs['build'](method='push', **kwargs) await self.image.push(action=self)
#name = kwargs.get('name', os.getcwd()).split('/')[-1] #name = kwargs.get('name', os.getcwd()).split('/')[-1]

View File

@ -55,10 +55,6 @@ class Buildah(Localhost):
def __repr__(self): def __repr__(self):
return f'Base({self.base})' return f'Base({self.base})'
async def __call__(self, *args, **kwargs):
result = await super().__call__(*args, **kwargs)
return result
async def config(self, line): async def config(self, line):
"""Run buildah config.""" """Run buildah config."""
return await self.exec(f'buildah config {line} {self.ctr}', buildah=False) return await self.exec(f'buildah config {line} {self.ctr}', buildah=False)
@ -143,16 +139,6 @@ class Buildah(Localhost):
for tag in tags: for tag in tags:
await self.exec('buildah', 'tag', self.sha, tag, buildah=False) await self.exec('buildah', 'tag', self.sha, tag, buildah=False)
async def push(self, *args, **kwargs):
user = os.getenv('DOCKER_USER')
passwd = os.getenv('DOCKER_PASS')
if user and passwd:
self.output.cmd('buildah login -u ... -p ...' + self.image.registry)
await self.exec('buildah', 'login', '-u', user, '-p', passwd, self.image.registry or 'docker.io', debug=False)
for tag in self.image.tags:
await self.exec('buildah', 'push', f'{self.image.repository}:{tag}')
async def clean(self, *args, **kwargs): async def clean(self, *args, **kwargs):
if self.is_runnable(): if self.is_runnable():
for src, dst in self.mounts.items(): for src, dst in self.mounts.items():
@ -161,7 +147,7 @@ class Buildah(Localhost):
if self.status == 'success': if self.status == 'success':
await self.commit() await self.commit()
if 'push' in args: if 'push' in args:
await self.push() await self.image.push(action=self)
if self.mnt is not None: if self.mnt is not None:
await self.exec('buildah', 'umount', self.ctr, buildah=False) await self.exec('buildah', 'umount', self.ctr, buildah=False)