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

Add support for dockerfiles #81

Merged
merged 13 commits into from
Apr 16, 2018

Conversation

lachmanfrantisek
Copy link
Member

@lachmanfrantisek lachmanfrantisek commented Apr 12, 2018

Resolves #66
Resolves #82

  • Support for dockerfiles (using DockerfileParser as a target instance) -- Input is filepath or file-like object.
  • Refactoring of check loading.
  • Check loading extended:
    • Allows new format (subdirs in the check list can specify target type(s))
    • Allows tag/severity filtering. (Not present yet in the API.)
  • Using same definition for one label check for images, containers and dockerfiles.
  • Abstract checks for dockerfile:
    • instruction counter (compare wit min/max)
    • instruction regex (Check regex for given instruction type)

for inst in dfp.structure:
if inst["instruction"] == instruction:
result.append(inst)
return result
Copy link
Member

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:

return [inst for inst in dfp.structure if inst["instruction"] == instruction]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither am I...;-) Thanks!

Signed-off-by: lachmanfrantisek <[email protected]>
Signed-off-by: lachmanfrantisek <[email protected]>
Signed-off-by: lachmanfrantisek <[email protected]>
@lachmanfrantisek
Copy link
Member Author

I've also moved some code between files to avoid recursive dependencies. The structure started to be a little complicated:

sfood-stranka001

@lachmanfrantisek
Copy link
Member Author

It needs some polishing but I'm prepared for some review.

@lachmanfrantisek lachmanfrantisek changed the title WIP: Add support for dockerfiles Add support for dockerfiles Apr 15, 2018
Copy link
Member

@TomasTomecek TomasTomecek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too long for me doing a code review.

Tested locally on a bunch of Dockerfiles and worked like a charm, very nice work!

message="",
description="",
reference_url="https://docs.docker.com/engine/reference/builder/#from",
tags=["from", "dockerfile", "latest"],
instruction="FROM",
regex=".*/latest$",
value_regex=".*/latest$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FROM fedora is also bad, we should catch that one as well

Copy link
Member Author

@lachmanfrantisek lachmanfrantisek Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is a TODO for this on the next line:

TODO: Does not check if there is no tag => use ImageName parsing.

It will not be hard to do it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@TomasTomecek TomasTomecek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Doing PoC with Zdravo? @dhodovsk

@dhodovsk
Copy link
Member

@TomasTomecek on it

Copy link
Member

@jpopelka jpopelka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI doesn't mention 'dockerfile', so I think you want to add 'dockerfile' also here

if tags:
for t in tags:
if t not in check_instance.tags:
logger.debug("Check not passed the tag control: {}".format(r))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r -> t ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, would be better.

return target
if os.path.exists(target):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe more specifically if os.path.isfile(target):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, why I always choose the wrong one..;-) Thanks

@lachmanfrantisek
Copy link
Member Author

@jpopelka I've corrected the docs and add also support for the dockerfile as a file-like object -- We can use it for easier testing.

Copy link
Member

@jpopelka jpopelka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👍

@jpopelka jpopelka merged commit 5a33b88 into user-cont:master Apr 16, 2018
@lachmanfrantisek
Copy link
Member Author

@TomasTomecek Thanks for the testing.
@jpopelka Thanks for the review.

@lachmanfrantisek lachmanfrantisek deleted the dockerfile-support branch April 16, 2018 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants