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

Move ImageName class from osbs client to utils of dockerfile parser. #139

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tim-vk
Copy link
Contributor

@tim-vk tim-vk commented Nov 30, 2022

Summary of what is discussed in PR #129 :

  • There are use cases where only specific parts of an image (returned by baseimage) needs to be edited (for example: update all the tags).
  • Currently dockerfile-parse does not provide any tools to perform this. A seperate "Image string parser" still needed to be added by any user of dockerfile-parse.
  • osbs client utils already has a perfect solution: ImageName class with possibility to edit seperate components of the imagename string.
  • ImageName() is a better fit for dockerfile-parse than for osbs-client.

This PR moves the ImageName class to utils of dockerfile-parse.

I did need to refactor the ImageName class slightly to get the following behavior in-line with dockerfile-parse behavior:

  • Return None instead of empty strings.
  • Do not automatically add "latest" if no tag is present.
  • Improve str behavior. (equality check)

I've refactored & expanded the existing tests to reflect this behavior.

Do keep in mind that these changes are breaking compared to the ImageName class contained in osbs-client.

Maintainers will complete the following section

  • Commit messages are descriptive enough
  • Code coverage from testing does not decrease and new code is covered

@tim-vk tim-vk force-pushed the feature/imageName_class branch from f6502b9 to 6efc24a Compare November 30, 2022 18:53
@tim-vk tim-vk marked this pull request as draft November 30, 2022 18:58
@tim-vk tim-vk mentioned this pull request Nov 30, 2022
2 tasks
tests/test_parser.py Fixed Show fixed Hide fixed
tests/test_parser.py Fixed Show fixed Hide fixed
@tim-vk tim-vk force-pushed the feature/imageName_class branch from eb46d2a to cc33931 Compare November 30, 2022 20:42
@tim-vk
Copy link
Contributor Author

tim-vk commented Dec 1, 2022

@rcerven : Is it the intention to keep this repo suitable for python 2? Just to be sure, before I'm going to put too much effort in trying to get that work. I'm having quite a bit of trouble wrapping my head around what's going wrong currently.

It seems something with stringIO not accepting the result from the to_string() output. But not sure how i would be able to get it to work.

@tim-vk tim-vk force-pushed the feature/imageName_class branch from c49d40d to 9736cd9 Compare December 1, 2022 19:23
@rcerven
Copy link
Member

rcerven commented Dec 1, 2022

@rcerven : Is it the intention to keep this repo suitable for python 2? Just to be sure, before I'm going to put too much effort in trying to get that work. I'm having quite a bit of trouble wrapping my head around what's going wrong currently.

It seems something with stringIO not accepting the result from the to_string() output. But not sure how i would be able to get it to work.

mmm for now afaik, @MartinBasti ?

@MartinBasti
Copy link
Contributor

@rcerven : Is it the intention to keep this repo suitable for python 2? Just to be sure, before I'm going to put too much effort in trying to get that work. I'm having quite a bit of trouble wrapping my head around what's going wrong currently.
It seems something with stringIO not accepting the result from the to_string() output. But not sure how i would be able to get it to work.

mmm for now afaik, @MartinBasti ?

We don't need it for py2 anymore, not sure about other community users :|

@tim-vk tim-vk force-pushed the feature/imageName_class branch from 591af13 to 8ccd28d Compare December 4, 2022 21:27
@tim-vk
Copy link
Contributor Author

tim-vk commented Dec 4, 2022

@MartinBasti Whelp, i'm stumped: I've got everything up to snuff: Except for the python 2 bit...
I have 0 clue how I would be able to fix these failing unit tests. Do you maybe have an idea?

Disabling the python2 tests is also a possibility. but that kind of feels like the cowards' way out...

@MartinBasti
Copy link
Contributor

@MartinBasti Whelp, i'm stumped: I've got everything up to snuff: Except for the python 2 bit... I have 0 clue how I would be able to fix these failing unit tests. Do you maybe have an idea?

Disabling the python2 tests is also a possibility. but that kind of feels like the cowards' way out...

I'm really thinking about bumping major version and drop py2 support, py2 is dead and enterprise distros can use old versions of Dockerfile-parse, I'll check with other maintainers

@MartinBasti
Copy link
Contributor

@MartinBasti Whelp, i'm stumped: I've got everything up to snuff: Except for the python 2 bit... I have 0 clue how I would be able to fix these failing unit tests. Do you maybe have an idea?
Disabling the python2 tests is also a possibility. but that kind of feels like the cowards' way out...

I'm really thinking about bumping major version and drop py2 support, py2 is dead and enterprise distros can use old versions of Dockerfile-parse, I'll check with other maintainers

@tim-vk we agreed that we will do a major release of dockerfile-parse without py2 support. I'll drop py2 support in separate PR, so for now ignore py2 failures

return match.group('image', 'name') if match else (None, None)
image = ImageName.parse(match.group('image')) if match else None
name = match.group('name') if match else None
return image, name
Copy link
Contributor

Choose a reason for hiding this comment

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

we are breaking BW compatibility here, I'm not sure if we can do this

Copy link
Contributor Author

@tim-vk tim-vk Dec 26, 2022

Choose a reason for hiding this comment

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

As far as i'm aware it shouldn't break backwards compatibility:

Old version: Image was a string
New version: Image is the new ImageName class which has a str representation (which is idential to the original string of the previous version).

This should be backwards compatible (the unit tests reflect this: there are only tests added, not changed).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addition:

Just realized what I typed above is not 100% true: See the explicit str(s) in util.py (line 51).
impact should still be minimal.

Alternative solution would be keeping the old function.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, explicit casting to str() is required, that's breaking change

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO would be safer to add new function and add deprecation warning to this one

Copy link
Contributor Author

@tim-vk tim-vk Jan 6, 2023

Choose a reason for hiding this comment

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

Done!
I could not find any examples within the containerbuildsystem project with deprecations so i opted to just add a simple DeprecationWarning. Let me know if an external package or other method is preferred.

@tim-vk tim-vk force-pushed the feature/imageName_class branch from 24185cf to db63b5f Compare December 26, 2022 20:13
Signed-off-by: Tim van Katwijk <[email protected]>
@tim-vk tim-vk force-pushed the feature/imageName_class branch from 0892b5e to eda9de3 Compare December 26, 2022 20:31
Copy link
Contributor Author

@tim-vk tim-vk left a comment

Choose a reason for hiding this comment

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

move to 2 commits & finishing touches.

@@ -17,3 +17,7 @@ jobs:
targets:
- fedora-all
- epel-8-x86_64

srpm_build_deps:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was apparently still missing in the master repo: I'm not 100% certain if this is correct. Please verify.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not sure what this fix is fixing, we had not such issue previously

@tim-vk tim-vk marked this pull request as ready for review December 26, 2022 20:34
@tim-vk tim-vk requested review from MartinBasti and removed request for ben-alkov, rcerven and mkosiarc December 26, 2022 20:35
Signed-off-by: Tim van Katwijk <[email protected]>
@tim-vk tim-vk force-pushed the feature/imageName_class branch 2 times, most recently from b794489 to 151f6cd Compare December 26, 2022 21:09
@tim-vk tim-vk force-pushed the feature/imageName_class branch from 151f6cd to 5fe6ebb Compare December 26, 2022 21:13
:param from_value: string like "image:tag" or "image:tag AS name"
:return: tuple of the image and stage name, e.g. ("image:tag", None)
"""
DeprecationWarning("Use image_name_from instead.")

Check failure

Code scanning / CodeQL

Unused exception object

Instantiating an exception, but not raising it, has no effect.
@tim-vk tim-vk force-pushed the feature/imageName_class branch from ff6e964 to 6b579f2 Compare January 6, 2023 11:02
@tim-vk tim-vk force-pushed the feature/imageName_class branch from 6b579f2 to 4c76644 Compare January 6, 2023 11:13
@MartinBasti
Copy link
Contributor

LGMT, very nice :)

@rcerven
Copy link
Member

rcerven commented Jan 12, 2023

can't you avoid making those breaking changes? (osbs-client and atomic-reactor are using that) and I'd prefer to keep ImageName 100% backwards compatible

  • Return None instead of empty strings.
  • Do not automatically add "latest" if no tag is present.

@tim-vk
Copy link
Contributor Author

tim-vk commented Jan 18, 2023

can't you avoid making those breaking changes? (osbs-client and atomic-reactor are using that) and I'd prefer to keep ImageName 100% backwards compatible

  • Return None instead of empty strings.
  • Do not automatically add "latest" if no tag is present.

While I recognize the wish for backwards compatibility, I do think that this is a great opportunity to genuinly think about "what do we want an imagename to be". And ignore the backwards compatibility bit (especially since the repo's you mention are not forced to use this version of the ImageName class. they can still use the old one. Though I hope someone will deprecate that one so everyone can switch to the new one with time).

So first: If there is nothing. What would you rather have: an empty string? or None. I would argue that None was a great choice to be returned. This makes checks a lot easier (if(imagename.registry), is a beautiful way of checking if there is a registry).

Second: a dockerfile does not need to contain a tag. automatically filling it in with latest would be superflous (as per the docker documentation the builder does that for you).
additionally: it would mean that if you would import a perfectly fine dockerfile & save it that the parser wil have changed it by adding 'latest'. I would find that undesired behavior.

Finally, If we do want to use the argument "backwards compatibility": The imageName class as implemented in this merge request is backwards compatible with existing code. e.g.: image_from() == str(image_name_from()).

So persionally I stand by these changes compared to the imageName class in the osbs-client. They seem to me to be the right way to go.

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.

3 participants