def test_get_image(self):
     print("Testing singularity.cli.get_image")
     from singularity.cli import get_image
     from singularity.build.utils import test_container
     tmpimg = get_image('docker://ubuntu')
     self.assertTrue(os.path.exists(tmpimg))
     result = test_container(tmpimg)
     self.assertEqual(result['return_code'], 0)
 def setUp(self):
     self.tmpdir = tempfile.mkdtemp()
     self.container = get_image('docker://ubuntu:16.04')
     self.comparator = get_image('docker://ubuntu:12.04')
Beispiel #3
0
          'oraclelinux:6.7','oraclelinux:6.6','oraclelinux:5.11',
          'photon:1.0',
          'sourcemage:0.62',
          'swarm:1.2.6-rc1',
          'ubuntu:12.04.5','ubuntu:14.04.5','ubuntu:16.04','ubuntu:16.10','ubuntu:17.04']

image_type = 'os'

# You will need to export your sudopw to an environment variable called pancakes for it to not ask you :)
os.environ['pancakes'] = 'yoursecretpass'

# We will make subdirectories in package folder
output_folder = "%s/%s" %(output_base,image_type)

if not os.path.exists(output_folder):
   os.mkdir(output_folder)

for name in images:
    docker_image = "docker://%s" %(name)
    image = get_image(docker_image)
    package_name = "%s/%s.zip" %(output_folder,os.path.basename(image))
    if not os.path.exists(package_name):
        image_package = package(image_path=image,
                                output_folder=output_folder,
                                remove_image=True,
                                runscript=True,
                                software=True)
    tmpfolder = os.path.dirname(image)
    shutil.rmtree(tmpfolder)

def main():

    parser = get_parser()

    try:
        args = parser.parse_args()
    except:
        sys.exit(0)

    # Not running in Singularity Hub environment
    os.environ['SINGULARITY_HUB'] = "False"

    # if environment logging variable not set, make silent
    if args.debug is False:
        os.environ['MESSAGELEVEL'] = "CRITICAL"

    if args.version is True:
        print(singularity.__version__)
        sys.exit(0)

    # Initialize the message bot, with level above
    from singularity.logman import bot
    from singularity.utils import check_install
    from singularity.cli import get_image

    # Output folder will be pwd if not specified
    if args.outfolder is None:
        output_folder = os.getcwd()
    else:
        output_folder = args.outfolder

    # We can only continue if singularity is installed
    if check_install() is True:

       # If we are given an image, ensure full path
       if args.image is not None:

           image,existed = get_image(args.image,
                                     return_existed=True,
                                     size=args.size)

           if image is None:
               bot.logger.error("Cannot find image. Exiting.")
               sys.exit(1)

           # the user wants to make a tree
           if args.tree is True:
               from singularity.app import make_tree
               make_tree(image)
               clean_up(image,existed)

           # The user wants to estimate the os
           elif args.os is True:
               from singularity.analysis.classify import estimate_os
               estimated_os = estimate_os(container=image)
               print(estimated_os)

           # The user wants to get a list of all os
           elif args.oscalc is True:
               from singularity.analysis.classify import estimate_os
               estimated_os = estimate_os(container=image,return_top=False)
               print(estimated_os["SCORE"].to_dict())

           # The user wants to get a list of tags
           elif args.tags is True:
               from singularity.analysis.classify import get_tags
               tags = get_tags(container=image)
               print(tags)

           # The user wants to plot image vs. the docker os
           elif args.osplot is True:
               from singularity.app import plot_os_sims
               plot_os_sims(image)
               clean_up(image,existed)

           # The user wants to package the image
           elif args.package is True:
               from singularity.package import package
               remove_image = not args.include_image
               package(image_path=image,
                       output_folder=output_folder,
                       runscript=True,
                       software=True,
                       remove_image=remove_image)
           else:
               print("Not sure what to do?")
               parser.print_help()

       # If we are given two image, we probably want a similar tree
       elif args.images is not None:

           image1,image2 = args.images.split(',')
           bot.logger.debug("Image1: %s",image1)
           bot.logger.debug("Image2: %s",image2)
           image1,existed1 = get_image(image1,
                                       return_existed=True,
                                       size=args.size)
           image2,existed2 = get_image(image2,
                                       return_existed=True,
                                       size=args.size)

           if image1 is None or image2 is None:
               bot.logger.error("Cannot find image. Exiting.")
               sys.exit(1)

           # the user wants to make a similarity tree
           if args.simtree is True:
               from singularity.app import make_sim_tree
               make_sim_tree(image1,image2)

           # the user wants to make a difference tree
           if args.subtract is True:
               from singularity.app import make_diff_tree
               make_diff_tree(image1,image2)

           if args.simcalc is True:
               from singularity.analysis.compare import calculate_similarity
               score = calculate_similarity(image1,image2,by="files.txt")
               print(score["files.txt"])

           clean_up(image1,existed1)
           clean_up(image2,existed2)
    
       else:
          print("Please specify one or more containers with --image(s)")