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: implement force push functionality in ImageSpec #2234

Merged
merged 15 commits into from
Mar 13, 2024

Conversation

jasonlai1218
Copy link
Contributor

@jasonlai1218 jasonlai1218 commented Mar 3, 2024

Tracking issue

https://github.com/flyteorg/flyte/issues/

Why are the changes needed?

So that we can easily override an image with the same name.

What changes were proposed in this pull request?

  • Add a new attribute _is_force_push to the __post_init__
  • Add a new method force_push to the ImageSpec class
  • Update the logic in the ImageBuildEngine class to handle _is_force_push attribute in ImageSpec instances

How was this patch tested?

Setup process

py_image_spec = ImageSpec(
    name="test_version_1",
    registry="jasonlai1218",
)
py_image_spec = py_image_spec.force_push()

Screenshots

Screenshot 2024-03-03 at 6 02 32 PM

Check all the applicable boxes

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

Related PRs

Docs link

flyteorg/flyte#5030

…ngine classes

- Add a new attribute `is_force_push` to the `ImageSpec` class
- Add a new method `force_push` to the `ImageSpec` class
- Update the logic in the `ImageBuildEngine` class to handle `is_force_push` attribute in `ImageSpec` instances

Signed-off-by: jason.lai <[email protected]>
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 3, 2024
Copy link

codecov bot commented Mar 3, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 83.36%. Comparing base (a2888cf) to head (9b6f58f).
Report is 3 commits behind head on master.

Files Patch % Lines
flytekit/image_spec/image_spec.py 75.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2234      +/-   ##
==========================================
- Coverage   83.81%   83.36%   -0.45%     
==========================================
  Files         332      309      -23     
  Lines       25093    24021    -1072     
  Branches     3690     3480     -210     
==========================================
- Hits        21032    20026    -1006     
+ Misses       3441     3375      -66     
  Partials      620      620              

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

flytekit/image_spec/image_spec.py Outdated Show resolved Hide resolved
flytekit/image_spec/image_spec.py Outdated Show resolved Hide resolved
- Add a `force_push` method to the `image_spec` class
- Assert that `is_force_push` is True in the test function

Signed-off-by: jason.lai <[email protected]>
- Add a default value for `is_force_push` in the `ImageSpec` class
- Change the message when force pushing an image in the `ImageBuildEngine` class

Signed-off-by: jason.lai <[email protected]>
- Update the default image tag in `ic_result_4` variable

Signed-off-by: jason.lai <[email protected]>
flytekit/image_spec/image_spec.py Outdated Show resolved Hide resolved
flytekit/image_spec/image_spec.py Outdated Show resolved Hide resolved
…ildEngine classes

- Change `is_force_push` attribute to `_is_force_push` in the `ImageSpec` class
- Remove the `is_force_push` parameter from the `force_push` method in the `ImageSpec` class
- Update references to `is_force_push` to `_is_force_push` in the `ImageBuildEngine` class

Signed-off-by: jason.lai <[email protected]>
- Add a method to enable force push in `ImageSpec` class
- Update image tags in test cases in `test_run.py`
- Assert that `_is_force_push` is False in `test_image_spec.py`

Signed-off-by: jason.lai <[email protected]>
Copy link
Member

@Future-Outlier Future-Outlier left a comment

Choose a reason for hiding this comment

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

@jasonlai1218
Can you help me test the case with force push?
For example

image = ImageSpec(
    name="test-flyte",
    packages=["flytekit"],
    registry="futureoutlier",
)

and add the flag in the ImageSpec

@jasonlai1218
Copy link
Contributor Author

@Future-Outlier
What does flag in the ImageSpec mean?

@jasonlai1218
Copy link
Contributor Author

@Future-Outlier like this?

image = ImageSpec(
    name="test-flyte",
    packages=["flytekit"],
    registry="futureoutlier",
    force_push=True,
)

@Future-Outlier
Copy link
Member

@Future-Outlier like this?

image = ImageSpec(
    name="test-flyte",
    packages=["flytekit"],
    registry="futureoutlier",
    force_push=True,
)

Yes, and please provide screenshot with overwrite message on terminal, thank you

@Future-Outlier
Copy link
Member

@Future-Outlier What does flag in the ImageSpec mean?

I mean the example of using force_push

@Future-Outlier
Copy link
Member

I think the interface should be simple, we add 1 more flag in ImageSpec, and it will force push the image to the specified registry.

@jasonlai1218
Copy link
Contributor Author

jasonlai1218 commented Mar 4, 2024

@pingsutw Do you have any thoughts on this? Do I need to add flag to ImageSpec interface?

- Change the variable `is_force_push` to `_is_force_push`

Signed-off-by: jason.lai <[email protected]>
@pingsutw
Copy link
Member

pingsutw commented Mar 4, 2024

we don't need a flag. just use ImageSpec(..).force_push()

flytekit/image_spec/image_spec.py Outdated Show resolved Hide resolved
flytekit/image_spec/image_spec.py Outdated Show resolved Hide resolved
- Remove the `_is_force_push` attribute from `ImageSpec` class

Signed-off-by: jason.lai <[email protected]>
Future-Outlier
Future-Outlier previously approved these changes Mar 6, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by maintainer label Mar 6, 2024
pingsutw
pingsutw previously approved these changes Mar 6, 2024
flytekit/image_spec/image_spec.py Outdated Show resolved Hide resolved
flytekit/image_spec/image_spec.py Outdated Show resolved Hide resolved
- Refactor the `ImageBuildEngine` class to improve readability and maintainability
- Update the logic for handling image building and registration
- Fix formatting and messaging inconsistencies in the code

Signed-off-by: jason.lai <[email protected]>
@jasonlai1218 jasonlai1218 dismissed stale reviews from pingsutw and Future-Outlier via 7471785 March 6, 2024 09:38
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Mar 6, 2024
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

I agree with #2234 (comment) around adding flag to ImageSpec instead of a method. The two use cases I see for force pushing is:

  1. Debugging
  2. User did not pin their dependencies and want to rebuild the image with newer versions.

In both cases, I'll want to enable and then disable force pushing. In either cases, I think a common pattern is to configure it through the environment. Here is what the API looks like for both designs

# Option 1: __init__
spec = ImageSpec(...,
    force_push=os.environ.get("FORCE_PUSH_IMAGE", "1") == "1" 
)

# Option 2: `force_push ` method
spec = ImageSpec(...)

if os.environ.get("FORCE_PUSH_IMAGE", "1") == "1":
    spec = spec.force_push()

I prefer option 1.

@@ -67,6 +67,7 @@ class ImageSpec:

def __post_init__(self):
self.name = self.name.lower()
self._is_force_push = False # False by default
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to update:

def calculate_hash_from_image_spec(image_spec: ImageSpec):

such that the force_push field is not a part of the hash?

jasonlai1218 and others added 3 commits March 7, 2024 01:43
- Add a new test for building an existing image with force push

Signed-off-by: jason.lai <[email protected]>
pingsutw
pingsutw previously approved these changes Mar 10, 2024
Signed-off-by: Kevin Su <[email protected]>
@jasonlai1218
Copy link
Contributor Author

Thank you very much @thomasjpfan for your advice.
Thanks to @pingsutw for helping with adjustments.
After adjustment, you can use the following two methods to overwrite existing image:

  1. FLYTE_FORCE_PUSH_IMAGE_SPEC=True pyflyte run --remote image_spec.py wf
  2. image = ImageSpec(registry="ghcr.io/flyteorg", packages=["pandas"]).force_push()

cc @Future-Outlier

@Future-Outlier
Copy link
Member

Thank you very much @thomasjpfan for your advice. Thanks to @pingsutw for helping with adjustments. After adjustment, you can use the following two methods to overwrite existing image:

  1. FLYTE_FORCE_PUSH_IMAGE_SPEC=True pyflyte run --remote image_spec.py wf
  2. image = ImageSpec(registry="ghcr.io/flyteorg", packages=["pandas"]).force_push()

cc @Future-Outlier

LGTM, I'm comfortable with the result.

@pingsutw pingsutw merged commit d61e79e into flyteorg:master Mar 13, 2024
45 of 47 checks passed
austin362667 pushed a commit to austin362667/flytekit that referenced this pull request Mar 16, 2024
fiedlerNr9 pushed a commit that referenced this pull request Jul 25, 2024
Signed-off-by: jason.lai <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Co-authored-by: Kevin Su <[email protected]>
Signed-off-by: Jan Fiedler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants