From 895f0e164b9c934d598b2159f9c356022c0445d5 Mon Sep 17 00:00:00 2001 From: jpic Date: Sun, 26 Jan 2020 19:54:59 +0100 Subject: [PATCH] Multiline Run scripts, and going pretty far for python 3.8 --- pod.py | 11 +++++++++-- podctl/visitors/pip.py | 24 ++++++++++++++---------- podctl/visitors/run.py | 4 +++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/pod.py b/pod.py index 3d58fd6..eecf631 100644 --- a/pod.py +++ b/pod.py @@ -8,9 +8,16 @@ from podctl import * podctl = Container( Base('quay.io/podman/stable'), - Packages('python3', 'buildah', mgr='dnf'), + Packages('python38', 'buildah', 'unzip', mgr='dnf'), + Run(''' + curl -o setuptools.zip https://files.pythonhosted.org/packages/42/3e/2464120172859e5d103e5500315fb5555b1e908c0dacc73d80d35a9480ca/setuptools-45.1.0.zip + unzip setuptools.zip + mkdir -p /usr/local/lib/python3.8/site-packages/ + sh -c "cd setuptools-* && python3.8 setup.py install" + easy_install-3.8 pip + '''), Copy(['setup.py', 'podctl'], '/app'), - Pip('/app'), + Pip('/app', pip='pip3.8'), Config(cmd='podctl', author='jpic'), Commit('docker.io/yourlabs/podctl'), ) diff --git a/podctl/visitors/pip.py b/podctl/visitors/pip.py index 3bee27b..9e2457b 100644 --- a/podctl/visitors/pip.py +++ b/podctl/visitors/pip.py @@ -1,17 +1,21 @@ class Pip: - def __init__(self, *pip_packages): + def __init__(self, *pip_packages, pip=None): self.pip_packages = pip_packages + self.pip = pip def build(self, script): - script.append(f''' - if {script._run("bash -c 'type pip3'")}; then - _pip=pip3 - elif {script._run("bash -c 'type pip'")}; then - _pip=pip - elif {script._run("bash -c 'type pip2'")}; then - _pip=pip2 - fi - ''') + if self.pip: + script.append('_pip=' + self.pip) + else: + script.append(f''' + if {script._run("bash -c 'type pip3'")}; then + _pip=pip3 + elif {script._run("bash -c 'type pip'")}; then + _pip=pip + elif {script._run("bash -c 'type pip2'")}; then + _pip=pip2 + fi + ''') script.mount('.cache/pip', '/root/.cache/pip') script.run('sudo $_pip install --upgrade pip') source = [p for p in self.pip_packages if p.startswith('/')] diff --git a/podctl/visitors/run.py b/podctl/visitors/run.py index 6e16577..b7472db 100644 --- a/podctl/visitors/run.py +++ b/podctl/visitors/run.py @@ -4,4 +4,6 @@ class Run: def build(self, script): for command in self.commands: - script.run(command) + for line in command.split('\n'): + if line.strip(): + script.run(line.strip())