From e80955936c789ab8bbb8bfab634ca74228854721 Mon Sep 17 00:00:00 2001 From: jpic Date: Thu, 13 Feb 2020 03:56:45 +0100 Subject: [PATCH] Fix podctl build itself --- examples/simple/pod.py | 54 +++++++++++++++++++++++++++++++++++++ podctl/script.py | 3 +++ podctl/visitors/__init__.py | 1 - podctl/visitors/copy.py | 8 +++--- podctl/visitors/packages.py | 6 ++--- 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 examples/simple/pod.py diff --git a/examples/simple/pod.py b/examples/simple/pod.py new file mode 100644 index 0000000..9f87f0a --- /dev/null +++ b/examples/simple/pod.py @@ -0,0 +1,54 @@ +from podctl import * + +ex = Container( + Base('docker.io/alpine'), + Packages('bash'), + DumbInit('sleep 55'), + Commit('test'), +) + +podctl2 = Container( + Base('docker.io/alpine'), + Packages('bash python-dev'), + Commit('test2'), +) + + +async def test_pod_story2(pod): + await pod.script('down')() + + +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 + + +async def aoeutest_podctl(host): + from podctl.console_script import console_script + console_script.options['debug'] = 'visit' + console_script.options['debug'] = True + + + from podctl.podfile import Podfile + pod = Podfile.factory(__file__).pod + + from podctl.proc import Proc + + #await Proc('podctl', 'down')() + #await Proc('podctl', 'build', 'ex')() + #await Proc('podctl', '-d=cmd,out,visit', 'up', 'ex')() + #assert host.podman('simple-ex').is_running + ##import time; time.sleep(5) + #await Proc('podctl', 'down')() + #assert 'simple-ex' not in [c.name for c in host.podman.get_containers()] + #return + + await pod.script('down')() + await pod.script('build')('ex') + await pod.script('up')('ex') + assert host.podman('ex').is_running + await pod.script('down')() + assert 'simple-ex' not in [c.name for c in host.podman.get_containers()] diff --git a/podctl/script.py b/podctl/script.py index 737595b..9a046c3 100644 --- a/podctl/script.py +++ b/podctl/script.py @@ -95,12 +95,15 @@ class Script: 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, diff --git a/podctl/visitors/__init__.py b/podctl/visitors/__init__.py index 1c4f181..05324ee 100644 --- a/podctl/visitors/__init__.py +++ b/podctl/visitors/__init__.py @@ -11,4 +11,3 @@ from .pip import Pip # noqa from .run import Run # noqa from .template import Append, Template # noqa from .user import User # noqa -from .uwsgi import uWSGI # noqa diff --git a/podctl/visitors/copy.py b/podctl/visitors/copy.py index a8c51cf..529f204 100644 --- a/podctl/visitors/copy.py +++ b/podctl/visitors/copy.py @@ -14,12 +14,12 @@ class Copy: self.owner = script.variable('user') async def build(self, script): - await script.run(f'sudo mkdir -p {self.dst}') + await script.crexec(f'mkdir -p {self.dst}') for item in self.src: - await script.append(f'cp -a {item} $mnt{self.dst}') + await script.exec(f'cp -a {item} {script.mnt}{self.dst}') if self.mode: - await script.run(f'sudo chmod {self.mode} $mnt{self.dst}') + await script.crexec(f'chmod {self.mode} {script.mnt}{self.dst}') if self.owner: - await script.run(f'sudo chown -R {self.owner} $mnt{self.dst}') + await script.crexec(f'chown -R {self.owner} {script.mnt}{self.dst}') diff --git a/podctl/visitors/packages.py b/podctl/visitors/packages.py index 9e1b0a5..0d38c72 100644 --- a/podctl/visitors/packages.py +++ b/podctl/visitors/packages.py @@ -29,9 +29,9 @@ class Packages: install='apt-get -y --no-install-recommends install', ), dnf=dict( - update='dnf update', - upgrade='dnf upgrade --exclude container-selinux --best --assumeyes', # noqa - install='dnf install --exclude container-selinux --setopt=install_weak_deps=False --best --assumeyes', # noqa + update='dnf makecache --assumeyes', + upgrade='dnf upgrade --best --assumeyes --skip-broken', # noqa + install='dnf install --setopt=install_weak_deps=False --best --assumeyes', # noqa ), yum=dict( update='yum update',