Skip to content

Commit

Permalink
refactoring organization to better support different container arhite…
Browse files Browse the repository at this point in the history
…ctures

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed May 30, 2021
1 parent 0b83f88 commit 5dde44f
Show file tree
Hide file tree
Showing 27 changed files with 1,251 additions and 759 deletions.
12 changes: 11 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ build_singularity: &install_singularity
./mconfig -p /usr/local && \
make -C builddir && \
sudo make -C builddir install
install_podman: &install_podman
name: Install Podman
command: |-
. /etc/os-release
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/testing/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:testing.list
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/testing/xUbuntu_${VERSION_ID}/Release.key | sudo apt-key add -
sudo apt-get update -qq
sudo apt-get -qq -y install podman
install_dependencies: &install_dependencies
name: install dependencies
command: |-
Expand Down Expand Up @@ -109,6 +118,7 @@ jobs:
keys: v1-dependencies
- run: *install_dependencies
- run: *setup_environment
- run: *install_podman
- run: *update_go
- run: *fetch_deb_deps
- run: *install_singularity
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ jobs:
run: |
export PATH="/usr/share/miniconda/bin:$PATH"
source activate black
pyflakes shpc/main
pyflakes shpc/main/*.py
pyflakes shpc/main/tcl
pyflakes shpc/main/lmod
pyflakes shpc/main/container/base.py
pyflakes shpc/main/container/podman.py
pyflakes shpc/main/container/singularity.py
3 changes: 3 additions & 0 deletions docs/getting_started/user-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ A summary table of variables is included below, and then further discussed in de
* - container_base
- Where to install containers. If not defined, they are installed alongside modules.
- null
* - container_tech
- The container technology to use (singularity or podman)
- singularity
* - updated_at
- a timestamp to keep track of when you last saved
- never
Expand Down
2 changes: 1 addition & 1 deletion shpc/client/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def main(args, parser, extra, subparser):
container_tech=args.container_tech,
)

sif = cli.get(args.module_name)
sif = cli.container.get(args.module_name)
if sif:
print(sif)
55 changes: 43 additions & 12 deletions shpc/client/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,46 @@ def main(args, parser, extra, subparser):

# Case 3: pretty print the whole thing
else:
for key, value in metadata.get("attributes", {}).items():
# skip the runscript
if key == "runscript":
continue

print("👉️ %s 👈️" % key.upper())
if isinstance(value, str):
print(value)
elif isinstance(value, dict):
for k, v in value.items():
print("%s : %s" % (k, v))
print()

# Inspect Singularity formatted metadata
if "attributes" in metadata:
for key, value in metadata.get("attributes", {}).items():
# skip the runscript
if key == "runscript":
continue
print("👉️ %s 👈️" % key.upper())
if isinstance(value, str):
print(value)
elif isinstance(value, dict):
for k, v in value.items():
print("%s : %s" % (k, v))
print()

# Podman and docker oci manifests
elif isinstance(metadata, list):

def print_value(key, value):
if not value:
return
if isinstance(value, (str, int)):
print("👉️ %s 👈️" % key.upper())
print(value)
elif isinstance(value, dict):
for k, v in value.items():
print_value(k, v)
elif isinstance(value, list):
print("👉️ %s 👈️" % key.upper())
print("\n".join(value))
print()

for key in [
"Os",
"Architecture",
"Author",
"Size",
"Labels",
"RepoTags",
"Config",
]:
value = metadata[0].get(key)
print_value(key, value)
12 changes: 9 additions & 3 deletions shpc/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ def get_client(quiet=False, **kwargs):
# Add the container operator
if container == "singularity":
from .container import SingularityContainer
Client._container = SingularityContainer()

elif container == "podman"
Client.container = SingularityContainer()

elif container == "podman":
from .container import PodmanContainer
Client._container = PodmanContainer()

Client.container = PodmanContainer()

# The containe should have access to settings too
if hasattr(Client, "container"):
Client.container.settings = settings

# Give the user a warning:
if not check_install():
Expand Down
45 changes: 8 additions & 37 deletions shpc/main/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,13 @@ class Client:
def __init__(self, settings_file=None):

# We don't necessarily need a container technology handle
if not hasattr(self, "_container"):
self._container = None
if not hasattr(self, "container"):
self.container = None

# If we don't have default settings, load
if not hasattr(self, "settings"):
self.settings = Settings(settings_file)

# If client initialized with _init_db, do it
if hasattr(self, "_init_db"):
self._init_db(self.settings.database_file)

def speak(self):
"""
A function for the client to announce him or herself.
Subclasses can define _speak() to add other meaningful information.
"""
if self.quiet is False:
logger.info("%s [database|%s]" % (self, self.database))

if hasattr(self, "_speak"):
self._speak()

def _speak(self):
pass

def announce(self, command=None):
"""
A wrapper to speak to control what commands are shown.
the client will announce itself given that a command is not in a
particular predefined list.
"""
if command and command not in ["get"] and self.quiet is False:
self.speak()

def __repr__(self):
return str(self)

Expand All @@ -88,21 +59,21 @@ def uninstall(self, name, tag=None):
"""
raise NotImplementedError

def add(self, sif, module_name):
def get(self, module_name):
"""
Add a container directly as a module
Get a container path or uri.
"""
raise NotImplementedError

def inspect(self, module_name):
def add(self, sif, module_name):
"""
Return complete metadata for the user from a container.
Add a container directly as a module
"""
raise NotImplementedError

def get(self, module_name):
def inspect(self, module_name):
"""
Get the path to a container for a module
Return complete metadata for the user from a container.
"""
raise NotImplementedError

Expand Down

0 comments on commit 5dde44f

Please sign in to comment.