From 8b145e6378e803066e6f1ef820403db06e75e427 Mon Sep 17 00:00:00 2001 From: jpic Date: Sun, 16 Feb 2020 16:12:12 +0100 Subject: [PATCH] Add automatic build test --- shlax/output.py | 10 ++++++++++ shlax/targets/buildah.py | 14 +++++++++++++- shlax/targets/docker.py | 4 +++- shlaxfile.py | 21 +++++++++------------ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/shlax/output.py b/shlax/output.py index ee38572..21dda39 100644 --- a/shlax/output.py +++ b/shlax/output.py @@ -97,6 +97,16 @@ class Output: return line + def test(self, action): + if self.debug is True: + self(''.join([ + self.colors['purplebold'], + '! TEST ', + self.colors['reset'], + action.colorized(), + '\n', + ])) + def clean(self, action): if self.debug is True: self(''.join([ diff --git a/shlax/targets/buildah.py b/shlax/targets/buildah.py index a271a94..ee54592 100644 --- a/shlax/targets/buildah.py +++ b/shlax/targets/buildah.py @@ -20,7 +20,7 @@ class Buildah(Localhost): The build script iterates over visitors and runs the build functions, it also provides wrappers around the buildah command. """ - contextualize = Localhost.contextualize + ['mnt', 'ctr', 'mount'] + contextualize = Localhost.contextualize + ['mnt', 'ctr', 'mount', 'image'] def __init__(self, base, *args, commit=None, push=False, cmd=None, **kwargs): if isinstance(base, Action): @@ -56,6 +56,18 @@ class Buildah(Localhost): def __repr__(self): return f'Base({self.base})' + async def __call__(self, *args, **kwargs): + result = await super().__call__(*args, **kwargs) + if 'test' in self.kwargs and self.is_runnable(): + self.output.test(self) + await self.action('Docker', + *self.kwargs['test'].actions, + image=self.image, + mount={'.': '/app'}, + workdir='/app', + )(*args, **kwargs) + return result + async def config(self, line): """Run buildah config.""" return await self.exec(f'buildah config {line} {self.ctr}', buildah=False) diff --git a/shlax/targets/docker.py b/shlax/targets/docker.py index 80db9c5..450fe19 100644 --- a/shlax/targets/docker.py +++ b/shlax/targets/docker.py @@ -10,7 +10,9 @@ class Docker(Localhost): contextualize = Localhost.contextualize + ['mnt', 'ctr', 'mount'] def __init__(self, *args, **kwargs): - self.image = Image(kwargs.get('image', 'alpine')) + self.image = kwargs.get('image', 'alpine') + if not isinstance(self.image, Image): + self.image = Image(image) super().__init__(*args, **kwargs) self.context['ctr'] = None diff --git a/shlaxfile.py b/shlaxfile.py index 6c0fb1c..3554b5f 100755 --- a/shlaxfile.py +++ b/shlaxfile.py @@ -3,6 +3,11 @@ from shlax.contrib.gitlab import * PYTEST = 'py.test -svv tests' +test = Script( + Pip('.[test]'), + Run(PYTEST), +) + build = Buildah( 'quay.io/podman/stable', Packages('python38', 'buildah', 'unzip', 'findutils', 'python3-yaml', upgrade=False), @@ -14,23 +19,15 @@ build = Buildah( mkdir -p /usr/local/lib/python3.8/site-packages/ sh -c "cd setuptools-* && python3.8 setup.py install" easy_install-3.8 pip + echo python3.8 -m pip > /usr/bin/pip + chmod +x /usr/bin/pip '''), Copy('shlax/', 'setup.py', '/app'), ), - Pip('/app', pip='python3.8 -m pip'), + Pip('/app'), commit='yourlabs/shlax', workdir='/app', -) - -test = Script( - Pip('.[test]'), - Run(PYTEST), -) - -buildtest = Docker( - *test.actions, - mount={'.': '/app'}, - workdir='/app', + test=test, ) pypi = Run(