generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add docker build detection (#409)
This PR adds support for the detection of Dockerfiles, so as to cover scenarios where Docker gets used as a build tool. * Docker presence is detected by finding files either named Dockerfile or in the formats *.Dockerfile or Dockerfile.* to cover different naming conventions of dockerfiles, e.g. dev.Dockerfile or like Macaron's own Dockerfile.base and Dockerfile.final. This is defined in defaults.ini under [builder.docker] * The supported build command keyword is build, and supported deploy command keyword is push, defined in defaults.ini under [builder.docker] *For CI deploy commands the GitHub action docker/build-push-action is supported, defined in defaults.ini under [builder.docker.ci.deploy] Signed-off-by: Tim Yarkov <[email protected]>
- Loading branch information
Showing
13 changed files
with
473 additions
and
1 deletion.
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
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,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 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.