diff --git a/ContainerRecipe/extract.py b/ContainerRecipe/extract.py index d3242bc..9be4498 100644 --- a/ContainerRecipe/extract.py +++ b/ContainerRecipe/extract.py @@ -63,20 +63,21 @@ # Step 3: Extract Container Things! First, the recipe file -from spython.main.parse import DockerRecipe -parser = DockerRecipe(dockerfile) +from spython.main.parse.parsers.docker import DockerParser +docker_recipe = 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('labels', docker_recipe.labels) # currently lists +containerRecipe.add_property('environment', docker_recipe.environ) # currently a list +containerRecipe.add_property('entrypoint', docker_recipe.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) +containerRecipe.add_property('ContainerImage', docker_recipe.fromHeader) # Step 4: Validate Data Structure @@ -96,12 +97,10 @@ response = run_command(['docker', 'inspect', uri]) # Inspect if response['return_code'] == 0: manifest = json.loads(response['message'])[0] - - -# Add more (not required) fields - some of these belon with ContainerImage -containerRecipe.add_property('operatingSystem', manifest['Os']) -containerRecipe.add_property('softwareVersion', manifest['Id']) # shasum -containerRecipe.add_property('identifier', manifest['RepoTags']) # tag + # Add more (not required) fields - some of these belon with ContainerImage + containerRecipe.add_property('operatingSystem', manifest['Os']) + containerRecipe.add_property('softwareVersion', manifest['Id']) # shasum + containerRecipe.add_property('identifier', manifest['RepoTags']) # tag # Note to readers - we can parse a ContainerRecipe from a manifest! # manifest['ContainerConfig'] And it has a name! Hmm. diff --git a/ImageDefinition/extract.py b/ImageDefinition/extract.py index bdbb83a..94affbf 100644 --- a/ImageDefinition/extract.py +++ b/ImageDefinition/extract.py @@ -63,8 +63,9 @@ # Step 3: Extract Container Things! First, the recipe file -from spython.main.parse import DockerRecipe -parser = DockerRecipe(dockerfile) +from spython.main.parse.parsers.docker import DockerParser +docker_recipe = DockerParser(dockerfile).parse() + # See definitions at containerRecipe._properties.keys() @@ -72,13 +73,13 @@ # containerRecipe.properties containerRecipe.add_property('version', containerRecipe.version) -containerRecipe.add_property('environment', parser.environ) # currently a list -containerRecipe.add_property('entrypoint', parser.entrypoint) +containerRecipe.add_property('environment', docker_recipe.environ) # currently a list +containerRecipe.add_property('entrypoint', docker_recipe.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', "vanessa/sregistry") -containerRecipe.add_property('ContainerImage', parser.fromHeader) +containerRecipe.add_property('ContainerImage', docker_recipe.fromHeader) # Step 4: Validate Data Structure diff --git a/README.md b/README.md index 278bc56..a877a62 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,12 @@ and is for the container [toasterlint/storjshare-cli](https://hub.docker.com/r/t # Usage -Before running these examples, make sure you have installed the module (and note -this module is under development, contributions are welcome!) +Before running these examples, make sure you have installed the required Python +modules (note that [schemaorg](https://www.github.com/openschemas/schemaorg) module is under +development, contributions are welcome!) ```bash -pip install schemaorg +pip install -r requirements.txt ``` To extract a recipe for a particular datatype, just run the `extract.py` file diff --git a/SoftwareSourceCode/extract.py b/SoftwareSourceCode/extract.py index 8676e36..c65e625 100644 --- a/SoftwareSourceCode/extract.py +++ b/SoftwareSourceCode/extract.py @@ -60,8 +60,8 @@ # Step 3: Create SoftwareSourceCode -from spython.main.parse import DockerRecipe -parser = DockerRecipe(dockerfile) +from spython.main.parse.parsers.docker import DockerParser +docker_recipe = DockerParser(dockerfile).parse() sourceCode = Schema("SoftwareSourceCode") @@ -70,7 +70,7 @@ sourceCode.add_property('creator', person) sourceCode.add_property('version', sourceCode.version) sourceCode.add_property('description', 'A Dockerfile build recipe') -sourceCode.add_property('name', parser.fromHeader) +sourceCode.add_property('name', docker_recipe.fromHeader) # Step 4: Validate Data Structure diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..15a35d1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +# Both dependencies are in 0.0.x and may change at any +# time, therefore we lock down the version for now. +# See https://semver.org/spec/v2.0.0.html#spec-item-4 +schemaorg==0.0.21 +spython==0.0.73 +