def build_from_spec(spec_file=None, build_dir=None, size=None, sudopw=None, build_folder=False, debug=False): '''build_from_spec will build a "spec" file in a "build_dir" and return the directory :param spec_file: the spec file, called "Singuarity" :param sudopw: the sudopw for Singularity, root should provide '' :param build_dir: the directory to build in. If not defined, will use tmpdir. :param size: the size of the image :param build_folder: "build" the image into a folder instead. Default False :param debug: ask for verbose output from builder ''' if spec_file == None: spec_file = "Singularity" if build_dir == None: build_dir = tempfile.mkdtemp() bot.logger.debug("Building in directory %s", build_dir) # Copy the spec to a temporary directory bot.logger.debug("Spec file set to %s", spec_file) spec_path = "%s/%s" % (build_dir, os.path.basename(spec_file)) bot.logger.debug("Spec file for build should be in %s", spec_path) # If it's not already there if not os.path.exists(spec_path): shutil.copyfile(spec_file, spec_path) image_path = "%s/image" % (build_dir) # Run create image and bootstrap with Singularity command line tool. if sudopw is not None: cli = Singularity(sudopw=sudopw, debug=debug) else: cli = Singularity(debug=debug) print("\nCreating and bootstrapping image...") # Does the user want to "build" into a folder or image? if build_folder == True: bot.logger.debug("build_folder is true, creating %s", image_path) os.mkdir(image_path) else: cli.create(image_path, size=size, sudo=True) result = cli.bootstrap(image_path=image_path, spec_path=spec_path) print(result) # If image, rename based on hash if build_folder == False: version = get_image_file_hash(image_path) final_path = "%s/%s" % (build_dir, version) os.rename(image_path, final_path) image_path = final_path bot.logger.debug("Built image: %s", image_path) return image_path
%runscript exec "Hello World!" ''' os.chdir(replicates) with open('Singularity','w') as filey: filey.writelines(runscript) from singularity.cli import Singularity cli = Singularity() for num in range(0,100): container_name = 'ubuntu-hello-world-%s.img' %(num) cli.create(container_name) cli.bootstrap(container_name,'Singularity') # ALL SINGULARITY HUB containers = shub.get_containers() os.chdir(hub) for container_name,container in containers.items(): for branch, manifest in container.items(): name = manifest['name'].replace('/','-') uncompressed = "%s-%s.img" %(name,branch) if not os.path.exists(uncompressed): try: image = shub.pull_container(manifest, download_folder=hub, name="%s-%s.img.gz" %(name,branch))