Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DockerParser from updated spython 0.0.73 #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions ContainerRecipe/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions ImageDefinition/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,23 @@

# 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()

# When you add, they are found at:
# 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
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions SoftwareSourceCode/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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