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): async def test_pod_story(pod):
await pod.script('down')() await pod.script('down')()
await pod.script('build')('ex') await pod.script('build')('ex')
return await pod.script('up')()
assert await pod.script('up')() == 0 await pod.script('down')()
assert await pod.script('down')() == 0
async def aoeutest_podctl(host): async def aoeutest_podctl(host):

View File

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

View File

@ -1,5 +1,6 @@
from .build import Build from .build import Build
from .exceptions import WrongResult from .exceptions import WrongResult
from .proc import output
from .visitable import Visitable from .visitable import Visitable
@ -12,6 +13,10 @@ class Container(Visitable):
def container_name(self): def container_name(self):
return '-'.join([self.pod.name, self.name]) 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): async def down(self, script):
try: try:
await script.exec('podman', 'inspect', self.container_name) await script.exec('podman', 'inspect', self.container_name)
@ -37,17 +42,14 @@ class Container(Visitable):
try: try:
await script.exec('podman', 'inspect', self.container_name) await script.exec('podman', 'inspect', self.container_name)
except WrongResult as ee: except WrongResult as ee:
tag = ':'.join(( output('Container creating', self.name)
self.variable('repo'), breakpoint()
self.variable('tags')[0],
))
print(f'{self.name} | Container creating')
await script.exec( await script.exec(
'podman', 'run', '-d', '--name', self.container_name, 'podman', 'run', '-d', '--name', self.container_name,
tag, self.image_name,
) )
print(f'{self.name} | Container created') output('Container created', self.name)
else: else:
print(f'{self.name} | Container starting') output('Container starting', self.name)
await script.exec('podman', 'start', self.container_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 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 = [] results = []
async def clean(): async def clean():
for visitor in visitable.visitors: for visitor in visitable.visitors:
@ -58,10 +66,11 @@ class Script:
''.join([ ''.join([
'.'.join([type(visitor).__name__, method]), '.'.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: if result:
await result await result
@ -78,10 +87,11 @@ class Script:
''.join([ ''.join([
'.'.join([type(visitor).__name__, method]), '.'.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) result = getattr(visitor, method)(self)

View File

@ -10,15 +10,12 @@ class Visitable:
self.scripts = deepcopy(self.default_scripts) self.scripts = deepcopy(self.default_scripts)
self.scripts.update(scripts) self.scripts.update(scripts)
'''
def script(self, name):
script = copy(self.scripts[name])
return script
'''
def visitor(self, name): def visitor(self, name):
for visitor in self.visitors: 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 return visitor
def variable(self, name): def variable(self, name):

View File

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