Try to short-circuit podman execution

This commit is contained in:
jpic 2020-01-26 18:34:16 +01:00
parent 2aa657d5ef
commit c88aea9ba9
2 changed files with 15 additions and 12 deletions

2
pod.py
View File

@ -8,7 +8,7 @@ from podctl import *
podctl = Container( podctl = Container(
Base('quay.io/podman/stable'), Base('quay.io/podman/stable'),
Packages('python3', 'buildah'), Packages('python3', 'buildah', mgr='dnf'),
Copy(['setup.py', 'podctl'], '/app'), Copy(['setup.py', 'podctl'], '/app'),
Pip('/app'), Pip('/app'),
Config(cmd='podctl', author='jpic'), Config(cmd='podctl', author='jpic'),

View File

@ -20,21 +20,24 @@ class Packages:
), ),
) )
def __init__(self, *packages): def __init__(self, *packages, mgr=None):
self.packages = list(packages) self.packages = list(packages)
self.mgr = None self.mgr = mgr
def pre_build(self, script): def pre_build(self, script):
base = script.container.variable('base') base = script.container.variable('base')
for mgr, cmds in self.mgrs.items(): if self.mgr:
cmd = ['podman', 'run', base, 'sh', '-c', f'type {mgr}'] self.cmds = self.mgrs[self.mgr]
try: else:
subprocess.check_call(cmd) for mgr, cmds in self.mgrs.items():
self.mgr = mgr cmd = ['podman', 'run', base, 'sh', '-c', f'type {mgr}']
self.cmds = cmds try:
break subprocess.check_call(cmd)
except subprocess.CalledProcessError: self.mgr = mgr
continue self.cmds = cmds
break
except subprocess.CalledProcessError:
continue
if not self.mgr: if not self.mgr:
raise Exception('Packages does not yet support this distro') raise Exception('Packages does not yet support this distro')