Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0eef6241a7 | ||
|
|
879bb6f79e | ||
|
|
e733694f2d | ||
|
|
0ec287c977 | ||
|
|
833cef7527 | ||
|
|
28f555bcf3 |
+9
-4
@@ -2,15 +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 curl python38
|
|
||||||
- curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
|
|
||||||
- python3 get-pip.py
|
|
||||||
- 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
|
||||||
|
|||||||
@@ -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
@@ -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):
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user