From 2ea37fb01dfe16e3f90dbbf36567a7c6f8a58697 Mon Sep 17 00:00:00 2001 From: jpic Date: Sun, 16 Feb 2020 14:36:03 +0100 Subject: [PATCH] GitLabCI can now execute the same jobs it generates for gitlab --- .gitlab-ci.yml | 14 ++++---------- shlax/contrib/gitlab.py | 22 +++++++++++++++++++++- shlax/image.py | 2 +- shlaxfile.py | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d71d9db..f141d1c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,14 +1,8 @@ -build: - image: yourlabs/shlax - script: ./shlaxfile.py build - stage: build +build: {image: yourlabs/shlax, script: ./shlaxfile.py build, stage: build} pypi: image: yourlabs/python - only: - - tags + only: [tags] script: ./shlaxfile.py pypi stage: deploy -test: - image: yourlabs/shlax - script: ./shlaxfile.py test - stage: test +test: {image: 'yourlabs/shlax:$CI_COMMIT_SHORT_SHA', script: ./shlaxfile.py test, + stage: test} diff --git a/shlax/contrib/gitlab.py b/shlax/contrib/gitlab.py index f292d47..c125cac 100644 --- a/shlax/contrib/gitlab.py +++ b/shlax/contrib/gitlab.py @@ -1,3 +1,4 @@ +from copy import deepcopy import yaml from shlax import * @@ -8,10 +9,14 @@ class GitLabCI(Script): output = dict() for key, value in self.kwargs.items(): if isinstance(value, dict): - output[key] = value + output[key] = deepcopy(value) output[key]['script'] = './shlaxfile.py ' + key + image = output[key].get('image', 'alpine') + if hasattr(image, 'image'): + output[key]['image'] = image.image.repository + ':$CI_COMMIT_SHORT_SHA' else: output[key] = value + output = yaml.dump(output) if kwargs['debug'] is True: self.output(output) @@ -19,5 +24,20 @@ class GitLabCI(Script): with open('.gitlab-ci.yml', 'w+') as f: f.write(output) + from shlax.cli import cli + for arg in args: + job = self.kwargs[arg] + _args = [] + if not isinstance(job['image'], str): + await job['image'](**kwargs) + image = str(job['image'].image) + _args.append('recreate') + else: + image = job['image'] + await Docker( + *cli.shlaxfile.actions[arg].actions, + image=image + )(*_args, **kwargs) + def colorized(self): return type(self).__name__ diff --git a/shlax/image.py b/shlax/image.py index 173b8fa..bee742f 100644 --- a/shlax/image.py +++ b/shlax/image.py @@ -61,4 +61,4 @@ class Image: return await action.exec(*args, **self.kwargs) def __str__(self): - return self.repository + return f'{self.repository}:{self.tags[-1]}' diff --git a/shlaxfile.py b/shlaxfile.py index 556a02a..9a8d576 100755 --- a/shlaxfile.py +++ b/shlaxfile.py @@ -34,7 +34,7 @@ gitlabci = GitLabCI( ), test=dict( stage='test', - image='yourlabs/shlax', + image=build, ), pypi=dict( stage='deploy',