6 Commits
Author SHA1 Message Date
jpic 0eef6241a7 Breaking it 2020-05-31 13:37:09 +02:00
jpic 879bb6f79e Silence pip output 2020-05-31 13:24:31 +02:00
jpic e733694f2d A bit of work on the command line 2020-05-31 13:22:36 +02:00
jpic 0ec287c977 Tag/build/push refactor 2020-05-31 12:53:57 +02:00
jpic 833cef7527 Typo in ci 2020-05-31 12:28:49 +02:00
jpic 28f555bcf3 Try more build 2020-05-31 12:23:48 +02:00
5 changed files with 49 additions and 38 deletions
+9 -2
View File
@@ -2,13 +2,20 @@ build:
cache: cache:
key: cache key: cache
paths: [.cache] paths: [.cache]
image: quay.io/buildah/stable image: yourlabs/buildah
script: script:
- dnf install -y python3-pip
- pip3 install -U --user -e .[cli] - pip3 install -U --user -e .[cli]
- CACHE_DIR=$(pwd)/.cache python3 ./shlaxfile.py build - CACHE_DIR=$(pwd)/.cache python3 ./shlaxfile.py build
stage: build stage: build
build-itself:
cache:
key: cache
paths: [.cache]
image: shlax:$CI_COMMIT_SHORT_SHA
script: python3 ./shlaxfile.py build
stage: test
test: test:
image: yourlabs/python image: yourlabs/python
stage: build stage: build
+4 -1
View File
@@ -19,7 +19,10 @@ class Pip(Action):
raise Exception('Could not find pip nor python') raise Exception('Could not find pip nor python')
# ensure pip module presence # ensure pip module presence
result = await target.exec(python, '-m', 'pip', raises=False) result = await target.exec(
python, '-m', 'pip',
raises=False, quiet=True
)
if result.rc != 0: if result.rc != 0:
if not os.path.exists('get-pip.py'): if not os.path.exists('get-pip.py'):
req = request.urlopen( req = request.urlopen(
+24 -9
View File
@@ -20,22 +20,37 @@ class Group(cli2.Group):
self.cmdclass = Command self.cmdclass = Command
class TargetArgument(cli2.Argument):
"""DSN of the target to execute on, localhost by default, TBI"""
def __init__(self, cmd, param, doc=None, color=None, default=None):
from shlax.targets.base import Target
super().__init__(cmd, param, doc=self.__doc__, default=Target())
self.alias = ['target', 't']
class Command(cli2.Command): class Command(cli2.Command):
def call(self, *args, **kwargs): def setargs(self):
return self.shlax_target(self.target) cli2.arg('target', cls=TargetArgument)(self.target)
super().setargs()
# that works though, so I went for that
# self['target'] = TargetArgument(
# self,
# self.sig.parameters['target'],
# )
if 'actions' in self:
del self['actions']
def __call__(self, *argv): def __call__(self, *argv):
from shlax.targets.base import Target super().__call__(*argv)
self.shlax_target = Target() self['target'].value.output.results(self['target'].value)
result = super().__call__(*argv)
self.shlax_target.output.results(self.shlax_target)
return result
class ActionCommand(Command): class ActionCommand(cli2.Command):
def call(self, *args, **kwargs): def call(self, *args, **kwargs):
self.target = self.target(*args, **kwargs) self.target = self.target(*args, **kwargs)
return super().call(*args, **kwargs) from shlax.targets.base import Target
return super().call(Target())
class ConsoleScript(Group): class ConsoleScript(Group):
+3
View File
@@ -18,6 +18,9 @@ class Target:
self.parent = None self.parent = None
self.root = root or os.getcwd() self.root = root or os.getcwd()
def __str__(self):
return 'localhost'
@property @property
def parent(self): def parent(self):
return self._parent or Target() return self._parent or Target()
+7 -24
View File
@@ -63,22 +63,17 @@ class Buildah(Target):
if actions: if actions:
actions = actions[len(keep):] actions = actions[len(keep):]
if not actions: if not actions:
return self.uptodate() return self.output.success('Image up to date')
else: else:
self.actions = self.actions[len(keep):] self.actions = self.actions[len(keep):]
if not self.actions: if not self.actions:
return self.uptodate() return self.output.success('Image up to date')
self.ctr = (await self.parent.exec('buildah', 'from', self.base)).out self.ctr = (await self.parent.exec('buildah', 'from', self.base)).out
self.root = Path((await self.parent.exec('buildah', 'mount', self.ctr)).out) self.root = Path((await self.parent.exec('buildah', 'mount', self.ctr)).out)
return await super().__call__(*actions) return await super().__call__(*actions)
def uptodate(self):
self.clean = None
self.output.success('Image up to date')
return
async def layers(self): async def layers(self):
ret = set() ret = set()
results = await self.parent.exec( results = await self.parent.exec(
@@ -144,19 +139,15 @@ class Buildah(Target):
return stop return stop
async def clean(self, target, result): async def clean(self, target, result):
if self.ctr is not None:
for src, dst in self.mounts.items(): for src, dst in self.mounts.items():
await self.parent.exec('umount', self.root / str(dst)[1:]) await self.parent.exec('umount', self.root / str(dst)[1:])
if self.root is not None:
await self.parent.exec('buildah', 'umount', self.ctr) await self.parent.exec('buildah', 'umount', self.ctr)
if self.ctr is not None:
if result.status == 'success':
await self.commit()
await self.parent.exec('buildah', 'rm', self.ctr) await self.parent.exec('buildah', 'rm', self.ctr)
if result.status == 'success' and os.getenv('BUILDAH_PUSH'): if result.status == 'success':
await self.commit()
if os.getenv('BUILDAH_PUSH'):
await self.image.push(target) await self.image.push(target)
async def mount(self, src, dst): async def mount(self, src, dst):
@@ -184,13 +175,6 @@ class Buildah(Target):
for key, value in self.config.items(): for key, value in self.config.items():
await self.parent.exec(f'buildah config --{key} "{value}" {self.ctr}') await self.parent.exec(f'buildah config --{key} "{value}" {self.ctr}')
self.sha = (await self.parent.exec(
'buildah',
'commit',
'--format=' + image.format,
self.ctr,
)).out
ENV_TAGS = ( ENV_TAGS = (
# gitlab # gitlab
'CI_COMMIT_SHORT_SHA', 'CI_COMMIT_SHORT_SHA',
@@ -214,8 +198,7 @@ class Buildah(Target):
else: else:
tags = [image.repository] tags = [image.repository]
for tag in tags: await self.parent.exec('buildah', 'tag', self.image_previous, *tags)
await self.parent.exec('buildah', 'tag', self.sha, tag)
async def mkdir(self, path): async def mkdir(self, path):
return await self.parent.mkdir(self.path(path)) return await self.parent.mkdir(self.path(path))