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

Add support to get docker image tag list #446

Closed
wants to merge 1 commit into from

Conversation

zhan9san
Copy link
Contributor

@zhan9san zhan9san commented Mar 6, 2024

Get docker image list

from artifactory import ArtifactoryPath

url = 'https://artifactory.example.com/artifactory'
apikey = 'xxx'

p = ArtifactoryPath(url, apikey=apikey)

docker_repo = 'foo'

for docker_image in p.get_docker_images(docker_repo):
    for docker_image_tag in p.get_docker_image_tags(docker_repo, docker_image):
        src = f'{docker_image}:{docker_image_tag}'

Reference:

Copy link
Member

@allburov allburov left a comment

Choose a reason for hiding this comment

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

We should create dedicated classes for that, something like ArtifactoryDockerRepo and ArtifactoryDockerImage, so it'd be possible to use it this way

arti = ArtifactoryPath("....", username, password)
repo: ArtifactoryDockerRepo = arti.docker_repo("reponame")
repo.images: Iterable[ArtifactoryDockerImage]
for image in repo.images:
     image: ArtifactoryDockerImage
     for tag in image.tags:
        tag: ArtifactoryDockerImageTag
        print(f"Removing {image.name} - {image.tag}")
        tag.delete()

Right now it looks just like a simple API client

We could place it somewhere in new dohq_artifactory.docker, because it has nothing to do with ArtifactoryPath, but it can use it under the hood, like a client
https://github.com/devopshq/artifactory/tree/master/dohq_artifactory

@zhan9san
Copy link
Contributor Author

zhan9san commented Mar 8, 2024

Thanks for your review.

This change is similar to get_properties method.

artifactory/artifactory.py

Lines 1290 to 1293 in b116902

def get_properties(self, pathobj):
"""
Get artifact properties and return them as a dictionary.
"""

a simple API client can works fine. Maybe it is the PR title makes you confused. I'd like to change it to Add support to get docker image tag list.

The original thought is that I want to migrate the Docker image from Artifactory to Nexus, but currently, there is no out-of-box way to get a full list of docker image tag.

With this PR, I can do it as below.

from artifactory import ArtifactoryPath

url = 'https://artifactory.example.com/artifactory'
apikey = 'foo'

p = ArtifactoryPath(url, apikey=apikey)

docker_repo = 'foo'

registry_arti = 'artifactory.example.com'
registry_nexus = 'nexus.example.com'
registry_nexus_repo = 'example-docker-preprod-local'


for docker_image in p.get_docker_images(docker_repo):
    for docker_image_tag in p.get_docker_image_tags(docker_repo, docker_image):
        src = f'{registry_arti}/{docker_repo}/{docker_image}:{docker_image_tag}'
        dst = f'{registry_nexus}/{registry_nexus_repo}/{docker_repo}/{docker_image}:{docker_image_tag}'
        cmd = f'skopeo copy docker://{src} docker://{dst}'
        print(cmd)

Let me know if you have any concern.

@zhan9san zhan9san changed the title add support for docker image operation Add support to get docker image tag list Mar 8, 2024
@allburov
Copy link
Member

a simple API client can works fine.

That is not the approach we should go in the library, sorry.

The script looks simple, anyone can implement it with pure python, it doesn't give any pros to using it in object related way.

It's fine to have such method in some sort of Accessor or ArtifactoryAPI , but no in the top level ArtifactoryPath, this one should be as much as possible class based and give some additional types to help developers understand the underlying relationships.

@zhan9san
Copy link
Contributor Author

Thank you all the same

@zhan9san zhan9san closed this Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants