wip
This commit is contained in:
+43
-2
@@ -4,9 +4,10 @@ import asyncio
|
||||
import signal
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
from .proc import Proc
|
||||
from .proc import Proc, output
|
||||
from .script import Script
|
||||
|
||||
|
||||
@@ -20,6 +21,8 @@ class Build(Script):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.mounts = dict()
|
||||
self.ctr = None
|
||||
self.mnt = None
|
||||
|
||||
async def config(self, line):
|
||||
"""Run buildah config."""
|
||||
@@ -56,7 +59,8 @@ class Build(Script):
|
||||
|
||||
async def umount(self):
|
||||
"""Unmount the buildah container with buildah unmount."""
|
||||
await self.exec(f'buildah unmount {self.ctr}')
|
||||
if self.ctr:
|
||||
await self.exec(f'buildah unmount {self.ctr}')
|
||||
|
||||
async def paths(self):
|
||||
"""Return the list of $PATH directories"""
|
||||
@@ -79,3 +83,40 @@ class Build(Script):
|
||||
|
||||
def __repr__(self):
|
||||
return f'Build'
|
||||
|
||||
async def run(self, *args, **kwargs):
|
||||
if os.getuid() == 0:
|
||||
return await super().run(*args, **kwargs)
|
||||
|
||||
from podctl.console_script import console_script
|
||||
# restart under buildah unshare environment !
|
||||
argv = [
|
||||
'buildah', 'unshare',
|
||||
sys.argv[0], # current podctl location
|
||||
]
|
||||
if console_script.options.get('debug') is True:
|
||||
argv.append('-d')
|
||||
elif isinstance(console_script.options.get('debug'), str):
|
||||
argv.append('-d=' + console_script.options.get('debug'))
|
||||
argv += [
|
||||
type(self).__name__.lower(), # script name ?
|
||||
]
|
||||
output(' '.join(argv), 'EXECUTION')
|
||||
|
||||
proc = await asyncio.create_subprocess_shell(
|
||||
shlex.join(argv),
|
||||
stderr=sys.stderr,
|
||||
stdin=sys.stdin,
|
||||
stdout=sys.stdout,
|
||||
)
|
||||
await proc.communicate()
|
||||
console_script.exit_code = proc.returncode
|
||||
return
|
||||
pp = subprocess.Popen(
|
||||
argv,
|
||||
stderr=sys.stderr,
|
||||
stdin=sys.stdin,
|
||||
stdout=sys.stdout,
|
||||
)
|
||||
pp.communicate()
|
||||
console_script.exit_code = pp.returncode
|
||||
|
||||
@@ -35,7 +35,19 @@ async def test(*args, **kwargs):
|
||||
'\n\x1b[1;38;5;160;48;5;118m BUILD START \x1b[0m'
|
||||
+ ' ' + podfile.path + '\n'
|
||||
)
|
||||
podfile.pod.script('build')()
|
||||
|
||||
old_exit_code = console_script.exit_code
|
||||
console_script.exit_code = 0
|
||||
try:
|
||||
await podfile.pod.script('build')()
|
||||
except Exception as e:
|
||||
report.append(('build ' + candidate, False))
|
||||
continue
|
||||
|
||||
if console_script.exit_code != 0:
|
||||
report.append(('build ' + candidate, False))
|
||||
continue
|
||||
console_script.exit_code = old_exit_code
|
||||
|
||||
for name, test in podfile.tests.items():
|
||||
name = '::'.join([podfile.path, name])
|
||||
|
||||
@@ -43,7 +43,6 @@ class Container(Visitable):
|
||||
await script.exec('podman', 'inspect', self.container_name)
|
||||
except WrongResult as ee:
|
||||
output('Container creating', self.name)
|
||||
breakpoint()
|
||||
await script.exec(
|
||||
'podman', 'run', '-d', '--name', self.container_name,
|
||||
self.image_name,
|
||||
|
||||
@@ -104,25 +104,6 @@ class Script:
|
||||
sys.stdout.flush()
|
||||
|
||||
async def run(self, *args, **kwargs):
|
||||
if self.unshare and os.getuid() != 0:
|
||||
from podctl.console_script import console_script
|
||||
# restart under buildah unshare environment !
|
||||
argv = [
|
||||
'buildah', 'unshare',
|
||||
sys.argv[0], # current podctl location
|
||||
] + console_script.parser.argv + [
|
||||
type(self).__name__.lower() # script name ?
|
||||
] + list(args)
|
||||
print('Executing', ' '.join(argv))
|
||||
pp = subprocess.Popen(
|
||||
argv,
|
||||
stderr=sys.stderr,
|
||||
stdin=sys.stdin,
|
||||
stdout=sys.stdout,
|
||||
)
|
||||
pp.communicate()
|
||||
return pp.returncode
|
||||
|
||||
for key, value in kwargs.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ class Base:
|
||||
async def clean_build(self, script):
|
||||
await script.umounts()
|
||||
await script.umount()
|
||||
proc = await script.exec('buildah', 'rm', script.ctr, raises=False)
|
||||
if script.ctr:
|
||||
proc = await script.exec('buildah', 'rm', script.ctr, raises=False)
|
||||
|
||||
def __repr__(self):
|
||||
return f'Base({self.base})'
|
||||
|
||||
@@ -20,20 +20,24 @@ class Commit:
|
||||
self.repo = repo
|
||||
self.registry = registry or 'localhost'
|
||||
self.push = push or os.getenv('CI')
|
||||
self.tags = tags or []
|
||||
|
||||
# figure out registry host
|
||||
if '/' in self.repo and not registry:
|
||||
first = self.repo.split('/')[0]
|
||||
if '.' in first or ':' in first:
|
||||
self.registry = self.repo.split('/')[0]
|
||||
self.repo = '/'.join(self.repo.split('/')[1:])
|
||||
|
||||
if ':' in self.repo and not tags:
|
||||
self.tags = [self.repo.split(':')[1]]
|
||||
self.repo = self.repo.split(':')[0]
|
||||
|
||||
# docker.io currently has issues with oci format
|
||||
self.format = format or 'oci'
|
||||
if self.registry == 'docker.io':
|
||||
self.format = 'docker'
|
||||
|
||||
self.tags = tags or []
|
||||
|
||||
# figure tags from CI vars
|
||||
if not self.tags:
|
||||
for name in CI_VARS:
|
||||
|
||||
Reference in New Issue
Block a user