-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add support for dockerfiles #81
Merged
jpopelka
merged 13 commits into
user-cont:master
from
lachmanfrantisek:dockerfile-support
Apr 16, 2018
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ee4b275
Add support for dockerfiles
lachmanfrantisek 4401373
Implement dockerfile abstract check for instruction count and label
lachmanfrantisek 9239d5b
Correct dockerfile checks in rulesets
lachmanfrantisek 25cb7bf
Add check for maintainer label in dockerfile
lachmanfrantisek ecc1034
Refactor check loading
lachmanfrantisek 3581176
Merge code for dockerfile/image checks
lachmanfrantisek b390612
Use new format for ruleset
lachmanfrantisek 0d06abf
Use list comprehension
lachmanfrantisek d25a336
Reformat ruleset and target
lachmanfrantisek 4424896
Correct, reformat, sort imports
lachmanfrantisek b77caa4
Make better check for the latest tag in the dockerfile
lachmanfrantisek dd18945
Add support for the dockerfile as file-like object
lachmanfrantisek 2e1a08d
Correct docs
lachmanfrantisek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import re | ||
|
||
from ..core.target import TargetType | ||
|
||
|
||
def check_label(label, required, value_regex, labels): | ||
""" | ||
Check if the label is required and match the regex | ||
|
||
:param label: str | ||
:param required: bool (if the presence means pass or not) | ||
:param value_regex: str | ||
:param labels: [str] | ||
:return: bool (required==True: True if the label is present and match the regex if specified) | ||
(required==False: True if the label is not present) | ||
""" | ||
present = labels is not None and label in labels | ||
|
||
if present: | ||
if required and not value_regex: | ||
return True | ||
elif value_regex: | ||
pattern = re.compile(value_regex) | ||
return bool(pattern.match(labels[label])) | ||
else: | ||
return False | ||
|
||
else: | ||
return not required | ||
|
||
|
||
def get_labels_from_target(target): | ||
""" | ||
Get list of labels from the target instance. | ||
|
||
:param target: instance of the Target | ||
:return: [str] | ||
""" | ||
if target.target_type == TargetType.DOCKERFILE: | ||
return target.instance.labels | ||
return target.instance.get_metadata()["Config"]["Labels"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from colin.checks.abstract.dockerfile import DockerfileLabelCheck | ||
|
||
|
||
class DockerfileLabelMaintainerCheck(DockerfileLabelCheck): | ||
|
||
def __init__(self): | ||
super().__init__(name="maintainer_label_required", | ||
message="Label 'maintainer' has to be specified.", | ||
description="The name and email of the maintainer (usually the submitter).", | ||
reference_url="https://fedoraproject.org/wiki/Container:Guidelines#LABELS", | ||
tags=["maintainer", "label", "required"], | ||
label="maintainer", | ||
required=True, | ||
value_regex=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you know list comprehensions, I'm just wondering why you don't use it here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither am I...;-) Thanks!