def test_docker2singularity(test_data, tmp_path): from spython.main.parse.parsers import DockerParser from spython.main.parse.writers import SingularityWriter for dockerfile, recipe in test_data["d2s"]: parser = DockerParser(dockerfile) writer = SingularityWriter(parser.recipe) assert writer.convert().strip("\n") == read_file(recipe)
def test_docker_writer(test_data): from spython.main.parse.parsers import DockerParser dockerfile = os.path.join(test_data["root"], "Dockerfile") parser = DockerParser(dockerfile) writer = DockerWriter(parser.recipe) assert str(writer) == "[spython-writer][docker]" print(writer.convert())
def _convert(dockerfile, singularityfile): parser = DockerParser(dockerfile) for p in parser.recipe.files: p[0] = p[0].strip('\"') p[1] = p[1].strip('\"') if os.path.isdir(p[0]): p[0] += '/.' writer = SingularityWriter(parser.recipe) recipe = writer.convert() with open(singularityfile, 'w') as sf: sf.write(recipe) return singularityfile
def test_docker_parser(test_data): dockerfile = os.path.join(test_data["root"], "Dockerfile") parser = DockerParser(dockerfile) assert str(parser) == "[spython-parser][docker]" # Test all fields from recipe assert parser.recipe.fromHeader == "python:3.5.1" assert parser.recipe.cmd == "/code/run_uwsgi.sh" assert parser.recipe.entrypoint is None assert parser.recipe.workdir == "/code" assert parser.recipe.volumes == [] assert parser.recipe.ports == ["3031"] assert parser.recipe.files[0] == ["requirements.txt", "/tmp/requirements.txt"] assert parser.recipe.environ == ["PYTHONUNBUFFERED=1"] assert parser.recipe.source == dockerfile
def test_docker_parser(test_data): dockerfile = os.path.join(test_data['root'], 'Dockerfile') parser = DockerParser(dockerfile) assert str(parser) == '[spython-parser][docker]' # Test all fields from recipe assert parser.recipe.fromHeader == 'python:3.5.1' assert parser.recipe.cmd == '/code/run_uwsgi.sh' assert parser.recipe.entrypoint is None assert parser.recipe.workdir == '/code' assert parser.recipe.volumes == [] assert parser.recipe.ports == ['3031'] assert parser.recipe.files[0] == [ 'requirements.txt', '/tmp/requirements.txt' ] assert parser.recipe.environ == ['PYTHONUNBUFFERED=1'] assert parser.recipe.source == dockerfile
def convert(dockerfile, singularityfile): """Convert a Dockerfile to a Singularity recipe file. Args: dockerfile (str): The path to the Dockerfile. singularityfile (str): The path to the Singularity recipe. Returns: str: The Singularity recipefile path. """ parser = DockerParser(dockerfile) for p in parser.recipe.files: p[0] = p[0].strip('\"') p[1] = p[1].strip('\"') if os.path.isdir(p[0]): p[0] += '/.' writer = SingularityWriter(parser.recipe) recipe = writer.convert() with open(singularityfile, 'w') as sf: sf.write(recipe) return singularityfile
dockerfile = os.path.join(os.path.dirname(here), "Dockerfile") # Step 1: Read in the (custom) yaml file as a custom (under development) Schema containerRecipe = Schema(spec_yml) # Step 2: Show required and recommended fields from recipe recipe = RecipeParser(recipe_yml) print(recipe.loaded) # Step 3: Extract Container Things! First, the recipe file from spython.main.parse.parsers import DockerParser parser = DockerParser(dockerfile).parse() # containerRecipe.properties containerRecipe.add_property('version', containerRecipe.version) containerRecipe.add_property('labels', parser.labels) # currently lists containerRecipe.add_property('environment', parser.environ) # currently a list containerRecipe.add_property('entrypoint', parser.entrypoint) containerRecipe.add_property('description', 'A Dockerfile build recipe') # This would be extracted at build --> push time, so we know the uri. containerRecipe.add_property('name', "vsoch/salad") containerRecipe.add_property('ContainerImage', parser.fromHeader) # Step 4: Validate Data Structure
## Thing > CreativeWork > SoftwareSourceCode > ContainerRecipe ################################################################################ # Step 1: Read in the (custom) yaml file as a custom (under development) Schema containerRecipe = Schema("ContainerRecipe.yml") # Step 2: Show required and recommended fields from recipe recipe = RecipeParser("recipe_ContainerRecipe.yml") print(recipe.loaded) # Step 3: Extract Container Things! First, the recipe file from spython.main.parse.parsers import DockerParser parser = DockerParser('Dockerfile').parse() # containerRecipe.properties containerRecipe.add_property('version', containerRecipe.version) containerRecipe.add_property('labels', parser.labels) # currently lists containerRecipe.add_property('environment', parser.environ) # currently a list containerRecipe.add_property('entrypoint', parser.entrypoint) containerRecipe.add_property('description', 'A Dockerfile build recipe') # This would be extracted at build --> push time, so we know the uri. containerRecipe.add_property('name', "toasterlint/storjshare-cli") containerRecipe.add_property('ContainerImage', parser.fromHeader) # Step 4: Validate Data Structure