Commit 3188b786 authored by David M. Rogers's avatar David M. Rogers
Browse files

Fixed container naming, py3.8 compat.

parent 14829525
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -56,6 +56,6 @@ on podman's conventions. You can save and load
the extended container environment information
using:

    c2.write("my_container.json")
    c2 = Container.read("my_container.json")
    c2.store("my_container.json")
    c2 = Container.load("my_container.json")
+14 −10
Original line number Diff line number Diff line
@@ -8,17 +8,22 @@ from .container_env import ContainerEnv
import contaminate.podman as podman

def incr_name(name : str) -> str:
    s = name.split(":", 1)
    if len(s) > 1:
    s = name.split(":")
    if len(s) == 2:
        name = s[0]
    elif len(s) == 3:
        name = s[1]
    elif len(s) > 1:
        raise ValueError("Too many colons in {name}")
    name = name.rsplit("/", 1)[-1]
    s = name.rsplit(".", 1)
    if len(s) == 1:
        return f"{name}.1"
    try:
        i = int(s[1])
    except ValueError:
        i = 0
    return f"{name}.{i+1}"
        return f"{name}.1"
    return f"{s[0]}.{i+1}"

class Container(BaseModel):
    name   : str           # container name
@@ -27,23 +32,22 @@ class Container(BaseModel):
    value  : str           # current container output text

    @classmethod
    def read(cls, fname : Union[str,Path]) -> "Container":
    def load(cls, fname : Union[str,Path]) -> "Container":
        with open(fname, "r", encoding="utf-8") as f:
            return Container.model_validate_json(f.read())

    def write(self, fname : Union[str,Path]) -> None:
    def store(self, fname : Union[str,Path]) -> None:
        Path(fname).write_text(
                    self.model_dump_json(indent=4))

    def run(self, *actions, name: Optional[str] = None
           ) -> "Container":
        assert len(actions) > 0, "inaction not implemented"
        c = self.copy()
        end = len(actions)-1
        for i, a in enumerate(actions):
            if name is not None and i == end: # rename on last step
                c.name = name
            c = a(c)
        if name is not None:
            podman.rename(c.name, name)
            c.name = name
        return c

    def with_value(self, val : str) -> "Container":
+7 −2
Original line number Diff line number Diff line
from typing import List
import subprocess
from tempfile import mkstemp
import os
@@ -17,7 +18,7 @@ def to_oneliner(cmds):
            shell += cmd + ";"
    return shell

def runcmd(*cmd) -> list[str]:
def runcmd(*cmd) -> List[str]:
    # Run the command. Print stdout and stderr.
    # Return the command's ouput, split into lines.
    proc = subprocess.Popen(cmd, universal_newlines=True,
@@ -52,6 +53,10 @@ def run(name : str,
                 "--rm", "/bin/bash", "-c", cmd)
    return "\n".join(ans)

def rename(name : str, newname : str) -> None:
    runcmd("podman", "image", "tag",
           name, newname)

def build(name : str,
          newname : str,
          cmds : str) -> str:
@@ -66,7 +71,7 @@ def build(name : str,
        Path(fname).write_text(
                f"FROM {name} as base\n{cmds}\n")
        print(f"Created dockerfile: {fname}")
        ans = runcmd("podman", "build", "-t", newname,
        ans = runcmd("podman", "build", "--net", "host", "-t", newname,
                     "-f", fname, ".")
        os.close(fd)
    finally:
+2 −2
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@ system: summit
arch: ppc64le
modules:
 - gcc/9.1.0
ld_preload: 
  - /gpfs/alpine/stf007/world-shared/containers/utils/libpami_cudahook.so
#ld_preload:
#  - /gpfs/alpine/stf007/world-shared/containers/utils/libpami_cudahook.so
containlibs:
 - /usr/lib64/libucp.so*
 - /usr/lib64/libuct.so*