GitLabCI can now execute the same jobs it generates for gitlab

This commit is contained in:
jpic 2020-02-16 14:36:03 +01:00
parent 6924d39590
commit 2ea37fb01d
4 changed files with 27 additions and 13 deletions

View File

@ -1,14 +1,8 @@
build: build: {image: yourlabs/shlax, script: ./shlaxfile.py build, stage: build}
image: yourlabs/shlax
script: ./shlaxfile.py build
stage: build
pypi: pypi:
image: yourlabs/python image: yourlabs/python
only: only: [tags]
- tags
script: ./shlaxfile.py pypi script: ./shlaxfile.py pypi
stage: deploy stage: deploy
test: test: {image: 'yourlabs/shlax:$CI_COMMIT_SHORT_SHA', script: ./shlaxfile.py test,
image: yourlabs/shlax stage: test}
script: ./shlaxfile.py test
stage: test

View File

@ -1,3 +1,4 @@
from copy import deepcopy
import yaml import yaml
from shlax import * from shlax import *
@ -8,10 +9,14 @@ class GitLabCI(Script):
output = dict() output = dict()
for key, value in self.kwargs.items(): for key, value in self.kwargs.items():
if isinstance(value, dict): if isinstance(value, dict):
output[key] = value output[key] = deepcopy(value)
output[key]['script'] = './shlaxfile.py ' + key 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: else:
output[key] = value output[key] = value
output = yaml.dump(output) output = yaml.dump(output)
if kwargs['debug'] is True: if kwargs['debug'] is True:
self.output(output) self.output(output)
@ -19,5 +24,20 @@ class GitLabCI(Script):
with open('.gitlab-ci.yml', 'w+') as f: with open('.gitlab-ci.yml', 'w+') as f:
f.write(output) 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): def colorized(self):
return type(self).__name__ return type(self).__name__

View File

@ -61,4 +61,4 @@ class Image:
return await action.exec(*args, **self.kwargs) return await action.exec(*args, **self.kwargs)
def __str__(self): def __str__(self):
return self.repository return f'{self.repository}:{self.tags[-1]}'

View File

@ -34,7 +34,7 @@ gitlabci = GitLabCI(
), ),
test=dict( test=dict(
stage='test', stage='test',
image='yourlabs/shlax', image=build,
), ),
pypi=dict( pypi=dict(
stage='deploy', stage='deploy',