-
Notifications
You must be signed in to change notification settings - Fork 7
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
Load and display image tags for neuro images
#873
Conversation
neuromation/cli/image.py
Outdated
@@ -114,7 +114,8 @@ def image() -> None: | |||
|
|||
images = await root.client.images.ls() | |||
for image in images: | |||
click.echo(image) | |||
for tag in images[image]: | |||
click.echo(f"{image} - {tag}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about we output images with tags in the format that we can re-use for other commands? I believe, it's image://user/ubuntu:tag
neuromation/api/images.py
Outdated
result: Dict[URL, List[str]] = {} | ||
for repo in ret["repositories"]: | ||
if repo.startswith("image://"): | ||
name = str(repo)[8:] # len("image://") = 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's create a constant for it, prefix = "image://"; name = str(repo)[len(prefix):]
neuromation/api/images.py
Outdated
url = URL(f"image://{repo}") | ||
result[url] = [] | ||
async with self._registry.request( | ||
"GET", URL(f"{name}/tags/list") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is not yet implemented in platform-registry
, let's comment this out for now or wrap with try-catch-ignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been merged already
Your implementation has O(N*M) complexity which is not desirable. Please add a new |
@anayden, you can use "Closes #xxx" or "Fixes #xxx" to close automatically the corresponded issue. |
Codecov Report
@@ Coverage Diff @@
## master #873 +/- ##
==========================================
- Coverage 91.37% 91.24% -0.13%
==========================================
Files 37 37
Lines 3617 3610 -7
Branches 527 520 -7
==========================================
- Hits 3305 3294 -11
- Misses 213 218 +5
+ Partials 99 98 -1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #873 +/- ##
==========================================
- Coverage 91.37% 89.99% -1.38%
==========================================
Files 37 38 +1
Lines 3617 3608 -9
Branches 527 516 -11
==========================================
- Hits 3305 3247 -58
- Misses 213 263 +50
+ Partials 99 98 -1
Continue to review full report at Codecov.
|
neuromation/api/images.py
Outdated
name = str(image)[len(prefix) :] | ||
async with self._registry.request("GET", URL(f"{name}/tags/list")) as resp: | ||
ret = await resp.json() | ||
return [tag for tag in ret.get("tags", [])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just return ret.get("tags", [])
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, of course! that's an artefact from refactoring
neuromation/cli/image.py
Outdated
|
||
Examples: | ||
|
||
neuro image tags image://myfriend/alpine:shared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the argument can contain a tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it can't. Fixed the example
neuromation/cli/image.py
Outdated
@@ -117,6 +118,27 @@ def image() -> None: | |||
click.echo(image) | |||
|
|||
|
|||
@command() | |||
@click.argument("image_name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not an image name. May be rename the argument to simply image
?
neuromation/api/images.py
Outdated
|
||
async def tags(self, image: URL) -> List[str]: | ||
prefix = "image://" | ||
name = str(image)[len(prefix) :] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if image
does not start with "image://"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Added a check and a test for that behavior
neuromation/cli/image.py
Outdated
@command() | ||
@click.argument("image_name") | ||
@async_cmd() | ||
async def tags(root: Root, image_name: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR's title says about neuro images
. Should we add an alias neuro images
or correct the title and the original issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we work with a single image here, I believe the command should be neuro image
, not neuro images
. I think the issue should be rephrased
cc @dalazx
""" | ||
List tags for image in platform registry. | ||
|
||
Image name must be URL with image:// scheme. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed to add support for relative URIs like image:myimage
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use ImageNameParser
to parse image: str
to image: DockerImage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, CLI methods for all image operations must use the same image URI parser -- this is the only way not to confuse the users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a difference. Other operations accept image URI with tag, but this operation should only accept image URI without tag.
neuromation/api/images.py
Outdated
result.append(url) | ||
return result | ||
|
||
async def tags(self, image: URL) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, we should accept image: str
similarly to API's method async def run(...)
, which accepts Container
with image: str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't care right now.
It may be changed in the following PR.
I'm working on images API stabilization and have no final decision yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added DockerImage
support. This will work even with images with tags, but I'd keep this as undocumented and not officially supported feature :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge when green
Addresses #852