Skip to content

Commit 3abe0e4

Browse files
authored
refactor of "add" to generate a container.yaml first to close #519 (#520)
* refactor of "add" to generate a container.yaml first to close #519 * this set of changes re-organizes the container template to be under the container module, and also moves around some code in modules and container (base.py and config.py) because in development I find the current locations not intuititve enough. * add should only support maintaining the namespace for the docker:// uri Signed-off-by: vsoch <[email protected]>
1 parent 5517836 commit 3abe0e4

File tree

26 files changed

+1022
-661
lines changed

26 files changed

+1022
-661
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,28 @@ jobs:
3434
run: |
3535
export PATH="/usr/share/miniconda/bin:$PATH"
3636
source activate black
37+
pyflakes shpc/utils/fileio.py
38+
pyflakes shpc/utils/terminal.py
3739
pyflakes shpc/main/*.py
3840
pyflakes shpc/main/modules
3941
pyflakes shpc/main/container/base.py
4042
pyflakes shpc/main/container/podman.py
4143
pyflakes shpc/main/container/docker.py
4244
pyflakes shpc/main/container/singularity.py
45+
pyflakes shpc/main/container/update/docker.py
46+
pyflakes shpc/tests
47+
pyflakes shpc/*.py
48+
pyflakes shpc/client/add.py
49+
pyflakes shpc/client/check.py
50+
pyflakes shpc/client/config.py
51+
pyflakes shpc/client/docgen.py
52+
pyflakes shpc/client/get.py
53+
pyflakes shpc/client/inspect.py
54+
pyflakes shpc/client/install.py
55+
pyflakes shpc/client/listing.py
56+
pyflakes shpc/client/namespace.py
57+
pyflakes shpc/client/pull.py
58+
pyflakes shpc/client/show.py
59+
pyflakes shpc/client/test.py
60+
pyflakes shpc/client/uninstall.py
61+
pyflakes shpc/main/wrappers

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/singularityhub/singularity-hpc/tree/main) (0.0.x)
17+
- refactor to "add" to generate a container.yaml first (0.0.49)
1718
- Properly cleanup empty module directories, and asking to remove a container that doesn't exist now logs a _warning_ (0.0.48)
1819
- wrapper script generation permissions error (0.0.47)
1920
- fixing but with stream command repeating output (0.0.46)

docs/getting_started/user-guide.rst

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,19 +1114,87 @@ Add
11141114
---
11151115

11161116
It might be the case that you have a container locally, and you want to
1117-
make it available as a module (without pulling it from a registry). Although
1118-
this is discouraged because it means you will need to manually maintain
1119-
versions, shpc does support the "add" command to do this. You can simply provide
1120-
the container path and the unique resource identifier:
1117+
make it available as a module (without pulling it from a registry). You might also
1118+
have a container on Docker Hub that you want to contribute to the registry!
1119+
shpc does support the "add" command to perform both of these functions.
1120+
The steps for adding a container are:
1121+
1122+
1. Running ``shpc add`` to create a container.yaml in the registry namespace
1123+
2. Customizing the container.yaml to your liking
1124+
3. Running ``shpc install`` to formally install your new container.
1125+
1126+
In the case of a docker image that is public (that you can share) you are encouraged
1127+
to contribute your recipe directly to shpc for others to use, and once in the repository
1128+
tags will also get updated automatically.
1129+
1130+
Add a Local Container
1131+
^^^^^^^^^^^^^^^^^^^^^
1132+
1133+
As an example, let's start with the container ``salad_latest.sif``. We have it
1134+
on our local machine and cannot pull it from a registry. First, let's run ``shpc add``
1135+
and tell shpc that we want it under the ``dinosaur/salad`` namespace.
1136+
1137+
.. code-block:: console
1138+
1139+
$ shpc add salad_latest.sif dinosaur/salad:latest
1140+
Registry entry dinosaur/salad:latest was added! Before shpc install, edit:
1141+
/home/vanessa/Desktop/Code/shpc/registry/dinosaur/salad/container.yaml
1142+
1143+
At this point, you should open up the container.yaml generated and edit to your liking.
1144+
This usually means updating the description, maintainer, aliases, and possibly providing a url
1145+
to find more information or support. Also notice we've provided the tag to be latest. If you update this registry
1146+
entry in the future with a new version, you'll want to provide a new tag. If you provide
1147+
an existing tag, you'll be asked to confirm before continuing. When you are happy,
1148+
it's time to install it, just as you would a regular container!
11211149

11221150
.. code-block:: console
11231151
1124-
$ shpc add salad_latest.sif vanessa/salad:latest
1152+
$ shpc install dinosaur/salad:latest
1153+
1154+
1155+
And this will generate the expected module and container in your respective directory bases:
1156+
1157+
1158+
.. code-block:: console
1159+
1160+
$ tree modules/dinosaur/salad/
1161+
modules/dinosaur/salad/
1162+
└── latest
1163+
├── 99-shpc.sh
1164+
└── module.lua
1165+
1166+
1 directory, 2 files
1167+
1168+
$ tree containers/dinosaur/salad/
1169+
containers/dinosaur/salad/
1170+
└── latest
1171+
└── sha256:77c7326e74d0e8b46d4e50d99e848fc950ed047babd60203e17449f5df8f39d4.sif
1172+
1173+
1 directory, 1 file
1174+
1175+
1176+
Add a Registry Container
1177+
^^^^^^^^^^^^^^^^^^^^^^^^
1178+
1179+
Let's say we want to generate a container.yaml recipe for a container on Docker Hub.
1180+
Let's say we want to add `vanessa/pokemon <https://hub.docker.com/r/vanessa/pokemon>`_.
1181+
First, let's run ``shpc add``. Note that we provide the ``docker://`` unique resource
1182+
identifier to tell shpc it's from a Docker (OCI) registry.
1183+
1184+
.. code-block:: console
1185+
1186+
$ shpc add docker://vanessa/pokemon
1187+
Registry entry vanessa/pokemon:latest was added! Before shpc install, edit:
1188+
/home/vanessa/Desktop/Code/shpc/registry/vanessa/pokemon/container.yaml
1189+
1190+
1191+
And that's it! The container module will use the same namespace, ``vanessa/pokemon`` as the Docker image,
1192+
and we do this purposefully as a design decision. Note that ``add`` previously would add the container directly to the module
1193+
directory, and as of version 0.0.49 it's been updated to generate the container.yaml first.
1194+
Also note that ``add`` is only supported for Singularity, as Docker and Podman containers are
1195+
typically provided via registries. If you are looking for support for add for another
1196+
container technology, please `open a new issue <https://github.com/singularityhub/singularity-hpc/issues>`_.
11251197

1126-
If the unique resource identifier corresponds with a registry entry, you
1127-
will not be allowed to create it, as this would create a namespace conflict.
1128-
Since we don't have a configuration file to define custom aliases, the container
1129-
will just be exposed as it's command to run it.
11301198

11311199
Get
11321200
---

registry/tensorflow/tensorflow/container.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ url: https://hub.docker.com/r/tensorflow/tensorflow
33
maintainer: '@vsoch'
44
description: An end-to-end open source platform for machine learning.
55
latest:
6-
2.8.0: sha256:7c01f75d58fadc2cd1109d5baac1925ed131e05925d840b1b49363c794d1c4db
6+
2.7.1-gpu: sha256:581575fc3a736398f0dff9e950f57f2e6d808296267ac98325451a0b1d101dd0
77
tags:
8-
2.2.2: sha256:e2cde2bb70055511521d995cba58a28561089dfc443895fd5c66e65bbf33bfc0
98
2.5.0-custom-op-gpu-ubuntu16: sha256:478bee6f0691b48d74adc3fcffe3e9ececf35df5c02860cc51a2c48b1d92c730
109
2.5.0rc0-gpu-jupyter: sha256:9808e04142b09482bb6b3d1738430ae7472a214dd38e086d41e481b376fa9abd
1110
2.6.0: sha256:773d5ce09e4ce003db02740c6a372a8a9f43be2bac23544d8f452bfec5347c53
1211
2.6.0rc0-gpu-jupyter: sha256:358b5bf90aaf4e56813ff22f2981d86fab7ddc59552b0be6022ae04d6a9f43c3
1312
2.7.0: sha256:31e09cf438a41f12c759cc8cc79c6b0fbb0db5abfc3de8169e916c8c9ac38dc5
1413
2.7.0rc0: sha256:abbc457c9b7c0725d7d0db885dbb313db3d0ae25733b083900a508efb672af94
15-
2.7.1-gpu: sha256:581575fc3a736398f0dff9e950f57f2e6d808296267ac98325451a0b1d101dd0
1614
2.8.0: sha256:7c01f75d58fadc2cd1109d5baac1925ed131e05925d840b1b49363c794d1c4db
1715
2.8.0rc0: sha256:11e5d21a786da523d2f7de530c083d5c72a06e02c8895c84595d107c579027a1
1816
latest-gpu: sha256:1e03623e335aac1610b1a3cfa6a96cf10156acb095287f9d6031df3980148663
17+
2.7.1-gpu: sha256:581575fc3a736398f0dff9e950f57f2e6d808296267ac98325451a0b1d101dd0
1918
filter:
2019
- 2.*
2120
- latest-gpu

shpc/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from shpc.version import __version__
2+
3+
assert __version__

shpc/client/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ def get_parser():
129129

130130
# Add a container direcly
131131
add = subparsers.add_parser("add", description="add an image to modules manually")
132-
add.add_argument("sif_path", help="full path to container image file", nargs=1)
132+
add.add_argument("container_uri", help="full path to container image file")
133133
add.add_argument(
134-
"module_id", help='desired identifier for module (e.g. "name/version")', nargs=1
134+
"module_id",
135+
help='desired identifier for module (e.g. "name/version"). Not required for docker)',
136+
nargs="?",
135137
)
136138

137139
check = subparsers.add_parser(
@@ -368,11 +370,11 @@ def help(return_code=0):
368370

369371
# Pass on to the correct parser
370372
return_code = 0
371-
try:
372-
main(args=args, parser=parser, extra=extra, subparser=helper)
373-
sys.exit(return_code)
374-
except UnboundLocalError:
375-
return_code = 1
373+
# try:
374+
main(args=args, parser=parser, extra=extra, subparser=helper)
375+
sys.exit(return_code)
376+
# except UnboundLocalError:
377+
# return_code = 1
376378

377379
help(return_code)
378380

shpc/client/add.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ def main(args, parser, extra, subparser):
1313
module=args.module,
1414
container_tech=args.container_tech,
1515
)
16-
cli.add(args.sif_path[0], args.module_id[0])
16+
# If we don't have a module name, we derive from container URI
17+
cli.add(args.container_uri, args.module_id)

0 commit comments

Comments
 (0)