generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 28
feat: add docker build detection #409
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09e9737
feat: add docker build detection
timyarkov d3e27eb
test: docker build tool tests
timyarkov 4869f0e
fix: updated e2e docker test
timyarkov de67959
fix: test docstring fix
timyarkov 82ca3df
fix: fix docker in defaults.ini
timyarkov 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,92 @@ | ||
# Copyright (c) 2023 - 2023, Oracle and/or its affiliates. All rights reserved. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. | ||
|
||
"""This module contains the Docker class which inherits BaseBuildTool. | ||
|
||
This module is used to work with repositories that use Docker as a build tool. | ||
""" | ||
|
||
from macaron.config.defaults import defaults | ||
from macaron.dependency_analyzer.dependency_resolver import NoneDependencyAnalyzer | ||
from macaron.slsa_analyzer.build_tool.base_build_tool import BaseBuildTool, file_exists | ||
|
||
|
||
class Docker(BaseBuildTool): | ||
"""This class contains the information of Docker when used as a build tool.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize instance.""" | ||
super().__init__(name="docker") | ||
|
||
def load_defaults(self) -> None: | ||
"""Load the default values from defaults.ini.""" | ||
if "builder.docker" in defaults: | ||
for item in defaults["builder.docker"]: | ||
if hasattr(self, item): | ||
setattr(self, item, defaults.get_list("builder.docker", item)) | ||
|
||
if "builder.docker.ci.deploy" in defaults: | ||
for item in defaults["builder.docker.ci.deploy"]: | ||
if item in self.ci_deploy_kws: | ||
self.ci_deploy_kws[item] = defaults.get_list("builder.docker.ci.deploy", item) | ||
|
||
def is_detected(self, repo_path: str) -> bool: | ||
"""Return True if this build tool is used in the target repo. | ||
|
||
Parameters | ||
---------- | ||
repo_path : str | ||
The path to the target repo. | ||
|
||
Returns | ||
------- | ||
bool | ||
True if this build tool is detected, else False. | ||
""" | ||
for file in self.build_configs: | ||
if file_exists(repo_path, file): | ||
return True | ||
|
||
return False | ||
|
||
def prepare_config_files(self, wrapper_path: str, build_dir: str) -> bool: | ||
"""Make necessary preparations for using this build tool. | ||
|
||
Parameters | ||
---------- | ||
wrapper_path : str | ||
The path where all necessary wrapper files are located. | ||
build_dir : str | ||
The path of the build dir. This is where all files are copied to. | ||
|
||
Returns | ||
------- | ||
bool | ||
True if succeed else False. | ||
""" | ||
# TODO: Future dependency analysis may require some preprocessing, e.g. | ||
# saving images to tar files. Need to investigate when implementing | ||
# and work with this method accordingly. | ||
|
||
return False | ||
|
||
def get_dep_analyzer(self, repo_path: str) -> NoneDependencyAnalyzer: | ||
"""Create a DependencyAnalyzer for the Docker build tool. Currently unimplemented. | ||
|
||
Parameters | ||
---------- | ||
repo_path: str | ||
The path to the target repo. | ||
|
||
Returns | ||
------- | ||
NoneDependencyAnalyser | ||
The NoneDependencyAnalyser object. | ||
|
||
Raises | ||
------ | ||
DependencyAnalyzerError | ||
""" | ||
# TODO: Find a suitable tool to analyse dependencies; as of now Syft | ||
# seems to be a good option, but need to experiment. | ||
return NoneDependencyAnalyzer() |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.