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

Image config option added: rebuildOnContextPathChanges #98

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ charts:
# This is by default the folder of the Dockerfile. This path should be
# set relative to chartpress.yaml.
contextPath: ..
# By default, changes to the contextPath will make chartpress rebuild
# the image, but this option make that configurable.
rebuildOnContextPathChanges: false
# Path to the Dockerfile, relative to chartpress.yaml. Defaults to
# "images/<image name>/Dockerfile".
dockerfilePath: images/binderhub/Dockerfile
Expand Down
35 changes: 25 additions & 10 deletions chartpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ def render_build_args(image_options, ns):
return build_args


def get_image_context_path(name, options):
"""
Return the image's contextPath configuration value or a default value based
on the image name.
"""
if options.get("contextPath"):
return options["contextPath"]
else:
return os.path.join("images", name)

def get_image_dockerfile_path(name, options):
"""
Return the image dockerfilePath configuration value or a default value based
on the contextPath.
"""
if options.get("dockerfilePath"):
return options["dockerfilePath"]
else:
return os.path.join(get_image_context_path(name, options), "Dockerfile")

def get_image_paths(name, options):
"""
Returns the paths that when changed should trigger a rebuild of a chart's
Expand All @@ -154,14 +174,9 @@ def get_image_paths(name, options):
Dockerfile path, and the optional others for extra paths.
"""
r = []
if options.get("contextPath"):
r.append(options["contextPath"])
else:
r.append(os.path.join("images", name))
if options.get("dockerfilePath"):
r.append(options["dockerfilePath"])
else:
r.append(os.path.join(r[0], "Dockerfile"))
if options.get("rebuildOnContextPathChanges", True):
r.append(get_image_context_path(name, options))
r.append(get_image_dockerfile_path(name, options))
r.extend(options.get("paths", []))
return r

Expand Down Expand Up @@ -350,8 +365,8 @@ def build_images(prefix, images, tag=None, push=False, force_push=False, chart_v
# include chartpress.yaml itself as it can contain build args and
# similar that influence the image that would be built
image_paths = get_image_paths(name, options) + ["chartpress.yaml"]
context_path = image_paths[0]
dockerfile_path = image_paths[1]
context_path = get_image_context_path(name, options)
dockerfile_path = get_image_dockerfile_path(name, options)
image_commit = latest_tag_or_mod_commit(*image_paths, echo=False)
if image_tag is None:
n_commits = check_output(
Expand Down