diff --git a/shlax/actions/base.py b/shlax/actions/base.py index d2e0e76..3872926 100644 --- a/shlax/actions/base.py +++ b/shlax/actions/base.py @@ -111,8 +111,9 @@ class Action: self.output = self.output_factory(*args, **kwargs) self.output_start() self.status = 'running' + call = getattr(self, kwargs.pop('method', 'call')) try: - result = await self.call(*args, **kwargs) + result = await call(*args, **kwargs) except Exception as e: self.output_fail(e) self.status = 'fail' diff --git a/shlax/output.py b/shlax/output.py index 21dda39..18e58b2 100644 --- a/shlax/output.py +++ b/shlax/output.py @@ -25,13 +25,14 @@ class Output: def colorize(self, code, content): return self.color(code) + content + self.color() - def __init__(self, prefix=None, regexps=None, debug=False, write=None, flush=None): + def __init__(self, prefix=None, regexps=None, debug=False, write=None, flush=None, **kwargs): self.prefix = prefix self.debug = debug self.prefix_length = 0 self.regexps = regexps or dict() self.write = write or sys.stdout.buffer.write self.flush = flush or sys.stdout.flush + self.kwargs = kwargs def prefix_line(self): if self.prefix not in self.prefixes: diff --git a/shlax/strategies/pod.py b/shlax/strategies/pod.py index ce7ca39..5cd5e61 100644 --- a/shlax/strategies/pod.py +++ b/shlax/strategies/pod.py @@ -18,22 +18,7 @@ class Container(Script): )(*args, **kwargs) if not args or 'push' in args: - user = os.getenv('DOCKER_USER') - passwd = os.getenv('DOCKER_PASS') - if user and passwd and os.getenv('CI') and self.registry: - await self.exec( - 'podman', - 'login', - '-u', - user, - '-p', - passwd, - self.registry, - buildah=False, - ) - - for tag in self.image.tags: - await self.exec('podman', 'push', f'{self.image.repository}:{tag}') + await self.kwargs['build'](method='push', **kwargs) #name = kwargs.get('name', os.getcwd()).split('/')[-1] diff --git a/shlax/targets/buildah.py b/shlax/targets/buildah.py index 9181c6f..e2cfed4 100644 --- a/shlax/targets/buildah.py +++ b/shlax/targets/buildah.py @@ -143,17 +143,15 @@ class Buildah(Localhost): for tag in tags: await self.exec('buildah', 'tag', self.sha, tag, buildah=False) - async def push(self): + async def push(self, *args, **kwargs): user = os.getenv('DOCKER_USER') passwd = os.getenv('DOCKER_PASS') - if user and passwd and os.getenv('CI'): + if user and passwd: self.output.cmd('buildah login -u ... -p ...' + self.image.registry) - old = self.output.debug - self.output.debug = False - await self.exec('buildah', 'login', '-u', user, '-p', passwd, self.image.registry or 'docker.io', ) - self.output.debug = old + 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', self.image.registry or 'docker.io', f'{self.image.repository}:{tag}') + await self.exec('buildah', 'push', f'{self.image.repository}:{tag}') async def clean(self, *args, **kwargs): if self.is_runnable(): @@ -162,7 +160,7 @@ class Buildah(Localhost): if self.status == 'success': await self.commit() - if 'push' in args: + if 'push' in args or os.getenv('CI'): await self.push() if self.mnt is not None: diff --git a/shlax/targets/localhost.py b/shlax/targets/localhost.py index 8bc0294..d424179 100644 --- a/shlax/targets/localhost.py +++ b/shlax/targets/localhost.py @@ -30,7 +30,8 @@ class Localhost(Script): return args, kwargs async def exec(self, *args, **kwargs): - kwargs.setdefault('debug', self.call_kwargs.get('debug', False)) + if 'debug' not in kwargs: + kwargs['debug'] = getattr(self, 'call_kwargs', {}).get('debug', False) kwargs.setdefault('output', self.output) args, kwargs = self.shargs(*args, **kwargs) proc = await Proc(*args, **kwargs)() diff --git a/shlaxfile.py b/shlaxfile.py index 004530d..685cd93 100755 --- a/shlaxfile.py +++ b/shlaxfile.py @@ -35,17 +35,17 @@ shlax = Container( ) gitlabci = GitLabCI( - build=dict( + test=dict( stage='build', + script='pip install -U --user -e .[test] && ' + PYTEST, + image='yourlabs/python', + ), + build=dict( + stage='test', image='yourlabs/shlax', script='pip install -U --user -e . && CACHE_DIR=$(pwd)/.cache ./shlaxfile.py -d shlax build push', cache=dict(paths=['.cache'], key='cache'), ), - test=dict( - stage='test', - script='pip install -U --user -e . && ./shlaxfile.py -d test', - image=build, - ), pypi=dict( stage='deploy', only=['tags'],