This commit is contained in:
jpic 2020-02-13 04:53:09 +01:00
parent 00fa16052d
commit 6e8b2ec2a7
6 changed files with 56 additions and 38 deletions

View File

@ -21,9 +21,8 @@ async def test_pod_story2(pod):
async def test_pod_story(pod):
await pod.script('down')()
await pod.script('build')('ex')
return
assert await pod.script('up')() == 0
assert await pod.script('down')() == 0
await pod.script('up')()
await pod.script('down')()
async def aoeutest_podctl(host):

View File

@ -31,6 +31,12 @@ async def test(*args, **kwargs):
continue
podfile = Podfile.factory(candidate)
output.print(
'\n\x1b[1;38;5;160;48;5;118m BUILD START \x1b[0m'
+ ' ' + podfile.path + '\n'
)
podfile.pod.script('build')()
for name, test in podfile.tests.items():
name = '::'.join([podfile.path, name])
output.print(
@ -65,14 +71,16 @@ async def test(*args, **kwargs):
'\n\x1b[1;38;5;200;48;5;44m TEST TOTAL: \x1b[0m'
+ str(len(report))
)
output.print(
'\n\x1b[1;38;5;15;48;5;196m TEST FAIL: \x1b[0m'
+ str(len(failures))
)
if success:
output.print(
'\n\x1b[1;38;5;200;48;5;44m TEST SUCCESS: \x1b[0m'
+ str(len(success))
)
if failures:
output.print(
'\n\x1b[1;38;5;15;48;5;196m TEST FAIL: \x1b[0m'
+ str(len(failures))
)
if failures:
console_script.exit_code = 1

View File

@ -1,5 +1,6 @@
from .build import Build
from .exceptions import WrongResult
from .proc import output
from .visitable import Visitable
@ -12,6 +13,10 @@ class Container(Visitable):
def container_name(self):
return '-'.join([self.pod.name, self.name])
@property
def image_name(self):
return self.pod.visitor(self.name).variable('repotags')[0]
async def down(self, script):
try:
await script.exec('podman', 'inspect', self.container_name)
@ -37,17 +42,14 @@ class Container(Visitable):
try:
await script.exec('podman', 'inspect', self.container_name)
except WrongResult as ee:
tag = ':'.join((
self.variable('repo'),
self.variable('tags')[0],
))
print(f'{self.name} | Container creating')
output('Container creating', self.name)
breakpoint()
await script.exec(
'podman', 'run', '-d', '--name', self.container_name,
tag,
self.image_name,
)
print(f'{self.name} | Container created')
output('Container created', self.name)
else:
print(f'{self.name} | Container starting')
output('Container starting', self.name)
await script.exec('podman', 'start', self.container_name)
print(f'{self.name} | Container started')
output('Container started', self.name)

View File

@ -47,6 +47,14 @@ class Script:
visitors = visitable.visitors
def val(k, v):
if isinstance(v, list) and len(v) > 1:
return '[' + str(v[-1]) + '...]'
if k == 'scripts':
return dict()
return v
results = []
async def clean():
for visitor in visitable.visitors:
@ -58,10 +66,11 @@ class Script:
''.join([
'.'.join([type(visitor).__name__, method]),
'(',
', '.join(f'{k}={v}' for k, v in visitor.__dict__.items()),
', '.join(f'{k}={val(k, v)}' for k, v in visitor.__dict__.items()),
')'
]),
getattr(visitable, 'name', None)
getattr(visitor, 'name',
getattr(visitable, 'name', None))
)
if result:
await result
@ -78,10 +87,11 @@ class Script:
''.join([
'.'.join([type(visitor).__name__, method]),
'(',
', '.join(f'{k}={v}' for k, v in visitor.__dict__.items()),
', '.join(f'{k}={val(k, v)}' for k, v in visitor.__dict__.items()),
')'
]),
getattr(visitable, 'name', None)
getattr(visitor, 'name',
getattr(visitable, 'name', None))
)
result = getattr(visitor, method)(self)

View File

@ -10,15 +10,12 @@ class Visitable:
self.scripts = deepcopy(self.default_scripts)
self.scripts.update(scripts)
'''
def script(self, name):
script = copy(self.scripts[name])
return script
'''
def visitor(self, name):
for visitor in self.visitors:
if name.lower() == type(visitor).__name__.lower():
if name.lower() in (
type(visitor).__name__.lower(),
getattr(visitor, 'name', '')
):
return visitor
def variable(self, name):

View File

@ -48,6 +48,12 @@ class Commit:
if not self.tags:
self.tags = ['latest']
# default tag for master too
if 'master' in self.tags:
self.tags.append('latest')
self.repotags = [f'{self.registry}/{self.repo}:{tag}' for tag in self.tags]
async def post_build(self, script):
self.sha = (await script.exec(
'buildah',
@ -56,13 +62,9 @@ class Commit:
script.ctr,
)).out
if 'master' in self.tags:
self.tags.append('latest')
if self.tags:
for tag in self.tags:
await script.exec('buildah', 'tag', self.sha, self.repo,
f'{self.repo}:{tag}')
for tag in self.repotags:
await script.exec('buildah', 'tag', self.sha, self.repo, tag)
if self.push:
user = os.getenv('DOCKER_USER')
@ -79,7 +81,7 @@ class Commit:
)
for tag in self.tags:
await script.exec('podman', 'push', f'{self.repo}:{tag}')
await script.exec('podman', 'push', tag)
await script.umount()
def __repr__(self):