From b771e9bd1a6018623a99447c7362110a2b2bf954 Mon Sep 17 00:00:00 2001 From: jpic Date: Sun, 16 Feb 2020 17:45:04 +0100 Subject: [PATCH] Added Container strategy --- shlax/strategies/__init__.py | 1 + shlax/strategies/pod.py | 42 ++++++++++++++++++++++++++++++++++++ shlaxfile.py | 4 ++++ 3 files changed, 47 insertions(+) create mode 100644 shlax/strategies/pod.py diff --git a/shlax/strategies/__init__.py b/shlax/strategies/__init__.py index 3ee13c2..1712bfe 100644 --- a/shlax/strategies/__init__.py +++ b/shlax/strategies/__init__.py @@ -1,2 +1,3 @@ from .asyn import Async from .script import Script +from .pod import Pod, Container diff --git a/shlax/strategies/pod.py b/shlax/strategies/pod.py new file mode 100644 index 0000000..ce7ca39 --- /dev/null +++ b/shlax/strategies/pod.py @@ -0,0 +1,42 @@ +import os +from .script import Script + + +class Container(Script): + async def call(self, *args, **kwargs): + if not args or 'build' in args: + await self.kwargs['build'](*args, **kwargs) + self.image = self.kwargs['build'].image + + if not args or 'test' in args: + self.output.test(self) + await self.action('Docker', + *self.kwargs['test'].actions, + image=self.image, + mount={'.': '/app'}, + workdir='/app', + )(*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}') + + #name = kwargs.get('name', os.getcwd()).split('/')[-1] + + +class Pod(Script): + pass diff --git a/shlaxfile.py b/shlaxfile.py index 3554b5f..f7bd3df 100755 --- a/shlaxfile.py +++ b/shlaxfile.py @@ -27,6 +27,10 @@ build = Buildah( Pip('/app'), commit='yourlabs/shlax', workdir='/app', +) + +shlax = Container( + build=build, test=test, )