Skip to content

Commit

Permalink
Remove trailing '=' character from generated image tag hash value (fl…
Browse files Browse the repository at this point in the history
…yteorg#2240)

Signed-off-by: jason.lai <[email protected]>
  • Loading branch information
jasonlai1218 authored Mar 6, 2024
1 parent 1c0b228 commit cacb9f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions flytekit/image_spec/image_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ def calculate_hash_from_image_spec(image_spec: ImageSpec):
# won't rebuild the image if we change the registry_config path
spec.registry_config = None
image_spec_bytes = asdict(spec).__str__().encode("utf-8")
tag = base64.urlsafe_b64encode(hashlib.md5(image_spec_bytes).digest()).decode("ascii")
# replace "=" with "." and replace "-" with "_" to make it a valid tag
return tag.replace("=", ".").replace("-", "_")
tag = base64.urlsafe_b64encode(hashlib.md5(image_spec_bytes).digest()).decode("ascii").rstrip("=")
# replace "-" with "_" to make it a valid tag
return tag.replace("-", "_")


def hash_directory(path):
Expand Down
4 changes: 2 additions & 2 deletions tests/flytekit/unit/cli/pyflyte/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ def test_list_default_arguments(wf_path):
)

ic_result_4 = ImageConfig(
default_image=Image(name="default", fqn="flytekit", tag="DgQMqIi61py4I4P5iOeS0Q.."),
default_image=Image(name="default", fqn="flytekit", tag="DgQMqIi61py4I4P5iOeS0Q"),
images=[
Image(name="default", fqn="flytekit", tag="DgQMqIi61py4I4P5iOeS0Q.."),
Image(name="default", fqn="flytekit", tag="DgQMqIi61py4I4P5iOeS0Q"),
Image(name="xyz", fqn="docker.io/xyz", tag="latest"),
Image(name="abc", fqn="docker.io/abc", tag=None),
],
Expand Down
1 change: 1 addition & 0 deletions tests/flytekit/unit/core/image_spec/test_image_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_image_spec(mock_image_spec_builder):
assert image_spec.commands == ["echo hello"]

tag = calculate_hash_from_image_spec(image_spec)
assert "=" != tag[-1]
assert image_spec.image_name() == f"flytekit:{tag}"
ctx = context_manager.FlyteContext.current_context()
with context_manager.FlyteContextManager.with_context(
Expand Down

0 comments on commit cacb9f0

Please sign in to comment.