Skip to content

Commit

Permalink
feat: Add --cache option to reuse docker image cache
Browse files Browse the repository at this point in the history
  • Loading branch information
wilderlopes committed May 7, 2024
1 parent b567dbc commit cd86f8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions miniogre/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def save_readme(readme, ogre_dir_path):
return readme_fullpath


def build_docker_image(dockerfile, image_name, verbose=False):
def build_docker_image(dockerfile, image_name, verbose=False, cache=False):
# build docker image

platform_name = "linux/{}".format(platform.machine())
Expand All @@ -541,8 +541,13 @@ def build_docker_image(dockerfile, image_name, verbose=False):
stderr = subprocess.PIPE
progress = "auto"

build_cmd = "DOCKER_BUILDKIT=1 docker buildx build --no-cache --load --progress={} --platform {} -t {} -f {} .".format(
progress, platform_name, image_name, dockerfile
if cache:
cache_option = ""
else:
cache_option = "--no-cache"

build_cmd = "DOCKER_BUILDKIT=1 docker buildx build {} --load --progress={} --platform {} -t {} -f {} .".format(
cache_option, progress, platform_name, image_name, dockerfile
)
print(" build command = {}".format(build_cmd))

Expand Down
3 changes: 2 additions & 1 deletion miniogre/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def run(
sbom_format: str = "pip-licenses",
no_container: bool = False,
verbose: bool = False,
cache: bool = False,
with_readme: bool = False,
):
"""
Expand Down Expand Up @@ -93,7 +94,7 @@ def run(
create_sbom(project_name, project_path, sbom_format, verbose)
if no_container == False:
build_docker_image(
os.path.join(ogre_dir_path, "Dockerfile"), project_name, verbose
os.path.join(ogre_dir_path, "Dockerfile"), project_name, verbose, cache
)
spin_up_container(project_name, project_path, port_map)
end_emoji()
Expand Down

0 comments on commit cd86f8a

Please sign in to comment.