|
4 | 4 |
|
5 | 5 | from singularity.cli import Singularity |
6 | 6 |
|
7 | | -# The default will ask for your sudo password, and then not ask again to |
8 | | -# run commands. It is not stored anywhere, however you should not save / pickle |
9 | | -# the object as it will expose your password. |
| 7 | +# Create a client |
10 | 8 | S = Singularity() |
11 | 9 |
|
12 | 10 | # Get general help: |
13 | 11 | S.help() |
14 | 12 |
|
15 | 13 | # These are the defaults, which can be specified |
16 | | -S = Singularity(sudo=True,verbose=False) |
17 | | - |
18 | | -# Let's define a path to an image |
19 | | -# wget http://www.vbmis.com/bmi/project/singularity/package_image/ubuntu:latest-2016-04-06.img |
20 | | -image_path = 'ubuntu:latest-2016-04-06.img' |
21 | | - |
22 | | -# Run singularity --exec |
23 | | -S.execute(image_path=image_path,command='ls') |
24 | | -# $'docker2singularity.sh\nget_docker_container_id.sh\nget_docker_meta.py\nmakeBases.py\nsingularity\nubuntu:latest-2016-04-06.img\n' |
25 | | -# These are the defaults, which can be specified |
| 14 | +S = Singularity(sudo=False,sudopw=None,debug=False) |
| 15 | + |
| 16 | +# Create an image |
| 17 | +image = S.create('myimage.img') |
| 18 | + |
| 19 | +# Import into it |
| 20 | +S.importcmd(image,'docker://ubuntu:latest') |
| 21 | + |
| 22 | +# Execute command to container |
| 23 | +result = S.execute(image,command='cat /singularity') |
| 24 | +print(result) |
| 25 | +''' |
| 26 | +#!/bin/sh |
| 27 | +
|
| 28 | +if test -x /bin/bash; then |
| 29 | + exec /bin/bash "$@" |
| 30 | +elif test -x /bin/sh; then |
| 31 | + exec /bin/sh "$@" |
| 32 | +else |
| 33 | + echo "ERROR: No valid shell within container" |
| 34 | + exit 255 |
| 35 | +fi |
| 36 | +''' |
26 | 37 |
|
27 | 38 | # For any function you can get the docs: |
28 | 39 | S.help(command="exec") |
29 | 40 |
|
30 | | -# or return as string |
31 | | -help = S.help(command="exec",stdout=False) |
32 | | - |
33 | | -# export an image, default export_type="tar" , pipe=False , output_file = None will produce file in tmp |
34 | | -tmptar = S.export(image_path=image_path) |
35 | | - |
36 | | -# create an empty image |
37 | | -S.create(image_path='test.img') |
| 41 | +# export an image as a byte array |
| 42 | +byte_array = S.export(image,pipe=True) |
38 | 43 |
|
39 | | -# import a docker image |
40 | | -S.importcmd(image_path,input_source='docker://ubuntu:latest') |
| 44 | +# Get an in memory tar |
| 45 | +from singularity.reproduce import get_memory_tar |
| 46 | +tar = get_memory_tar(image) |
0 commit comments