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

feat(image_spec): validate container registry names #2748

Merged
merged 4 commits into from
Sep 17, 2024

Conversation

pingsutw
Copy link
Member

Tracking issue

closes flyteorg/flyte#5689

Why are the changes needed?

It's better to check if the registry name is valid or not before building and pushing it.

What changes were proposed in this pull request?

validate the name in __post__init__

How was this patch tested?

unit test

Setup process

from flytekit import task, workflow, ImageSpec

image_spec = ImageSpec(
    registry="localhost:30000/UNIONAI",
    packages=["pandas"],
    builder="default"
)


@task(enable_deck=True, container_image=image_spec)
def t1(a: int) -> int:
    return a + 1


@workflow()
def wf() -> int:
    return t1(a=3)

Screenshots

Before:
Screenshot 2024-09-11 at 3 16 29 PM

After:
Screenshot 2024-09-11 at 2 40 29 PM

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

NA

Docs link

NA

def validate_container_registry_name(name: str) -> bool:
"""Validate Docker container registry name."""
# Define the regular expression for the registry name
registry_pattern = r"^(localhost:\d{1,5}|([a-z0-9._-]+)(:[0-9]{1,5})?)(/[a-zA-Z0-9._-]+)*$"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the dot be escaped, i.e. . -> \.? Also minor nits:

Suggested change
registry_pattern = r"^(localhost:\d{1,5}|([a-z0-9._-]+)(:[0-9]{1,5})?)(/[a-zA-Z0-9._-]+)*$"
registry_pattern = r"^(localhost:\d{1,5}|([a-z\d\._-]+)(:\d{1,5})?)(/[\w\.-]+)*$"

Signed-off-by: Kevin Su <[email protected]>
Copy link

codecov bot commented Sep 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.90%. Comparing base (ae9c6f8) to head (47e9145).
Report is 8 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (ae9c6f8) and HEAD (47e9145). Click for more details.

HEAD has 11 uploads less than BASE
Flag BASE (ae9c6f8) HEAD (47e9145)
15 4
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2748       +/-   ##
===========================================
- Coverage   90.87%   74.90%   -15.98%     
===========================================
  Files          74      194      +120     
  Lines        3331    19765    +16434     
  Branches        0     4121     +4121     
===========================================
+ Hits         3027    14804    +11777     
- Misses        304     4221     +3917     
- Partials        0      740      +740     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

registry_pattern = r"^(localhost:\d{1,5}|([a-z\d\._-]+)(:\d{1,5})?)(/[\w\.-]+)*$"

# Use regex to validate the given name
return bool(re.match(registry_pattern, name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange that this is not covered according to codecov. (At some point, I want to be able to trust codecov.)

@eapolinario eapolinario merged commit fb55841 into master Sep 17, 2024
102 of 103 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Housekeeping] Improve ImageSpec error message on wrong registry format
3 participants