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

Remove trailing '=' character from generated image tag hash value #2240

Merged
merged 7 commits into from
Mar 6, 2024
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 @@
# 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("=")

Check warning on line 260 in flytekit/image_spec/image_spec.py

View check run for this annotation

Codecov / codecov/patch

flytekit/image_spec/image_spec.py#L260

Added line #L260 was not covered by tests
# replace "-" with "_" to make it a valid tag
return tag.replace("-", "_")

Check warning on line 262 in flytekit/image_spec/image_spec.py

View check run for this annotation

Codecov / codecov/patch

flytekit/image_spec/image_spec.py#L262

Added line #L262 was not covered by tests


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
Loading